*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --green: #4ade80;
  --green-bg: #064e3b;
  --amber: #fbbf24;
  --amber-bg: #78350f;
  --gray: #64748b;
  --red: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* App container */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 12px;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* Login screen */
.login-card {
  margin-top: 30vh;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 16px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card .error {
  color: var(--red);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: scale(0.98);
}

/* Search bar */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 8px 0 12px;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.search-bar input:focus {
  border-color: var(--accent);
}

/* Episode list */
.episode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.episode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.episode-card:hover {
  background: var(--bg-input);
}

.episode-card:active {
  transform: scale(0.99);
}

.watch-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.watch-dot.not_started {
  border: 2px solid var(--gray);
  background: transparent;
}

.watch-dot.in_progress {
  border: 2px solid var(--amber);
  background: var(--amber);
  position: relative;
}

.watch-dot.completed {
  border: 2px solid var(--green);
  background: var(--green);
}

.episode-info {
  flex: 1;
  min-width: 0;
}

.episode-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.episode-title {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.episode-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
}

.episode-meta .minute-marker {
  color: var(--amber);
  font-weight: 500;
}

.badge {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.badge.ai {
  background: var(--accent);
  color: #fff;
}

/* Detail page */
.detail-header {
  margin-bottom: 20px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.detail-meta a {
  color: var(--accent);
  text-decoration: none;
}

/* Watch state controls */
.watch-controls {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 20px;
}

.watch-controls h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 500;
}

.state-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.state-btn {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.state-btn:hover {
  border-color: var(--text-secondary);
}

.state-btn.active.not_started {
  border-color: var(--gray);
  color: var(--text);
}

.state-btn.active.in_progress {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-bg);
}

.state-btn.active.completed {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-bg);
}

.minute-input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.minute-input-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.minute-input-group input {
  width: 80px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  text-align: center;
}

.minute-input-group input:focus {
  border-color: var(--accent);
}

.minute-input-group .save-btn {
  padding: 6px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Content sections */
.section {
  margin-bottom: 24px;
}

.section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section .content {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

.section .content p {
  margin-bottom: 8px;
}

.section .content p:last-child {
  margin-bottom: 0;
}

/* Mermaid mindmap */
.mindmap-container {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  cursor: pointer;
}

.mindmap-container .mermaid {
  display: flex;
  justify-content: center;
}

.mindmap-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Fullscreen overlay */
.mermaid-fullscreen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

.mermaid-fullscreen .close-hint {
  position: absolute;
  top: 16px;
  right: 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.mermaid-fullscreen .mermaid {
  max-width: 100%;
}

/* Loading & empty states */
.loading {
  text-align: center;
  padding: 40px 0;
  color: var(--text-secondary);
}

.empty-state {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
}

.no-content {
  color: var(--text-muted);
  font-style: italic;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  text-align: center;
}

/* Description on detail page */
.description {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
  margin-top: 12px;
}

/* Screen visibility */
[hidden] {
  display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
