:root {
  --bg: #0f0f12;
  --surface: #1a1a22;
  --surface-hover: #22222e;
  --border: #2e2e3a;
  --text: #e8e6f0;
  --text-muted: #8b8798;
  --accent: #e85d4c;
  --accent-hover: #f07062;
  --accent-soft: rgba(232, 93, 76, 0.15);
  --success: #4ade80;
  --warning: #fbbf24;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(232, 93, 76, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(100, 80, 200, 0.08), transparent);
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

/* Header */
.header {
  margin-bottom: 2rem;
}

.header-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

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

.subtitle {
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.lang-btn {
  min-width: 3rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.sync-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.sync-dot.syncing {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.sync-dot.synced {
  background: var(--success);
}

.sync-dot.error {
  background: #ef4444;
}

.sync-dot.offline {
  background: var(--text-muted);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sync-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  min-height: 1.2em;
}

.sync-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sync-hint strong {
  color: var(--text);
}

.sync-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1.5;
}

.sync-info.configured {
  border-color: rgba(74, 222, 128, 0.3);
  color: var(--success);
}

.sync-info.not-configured {
  border-color: rgba(251, 191, 36, 0.3);
  color: var(--warning);
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

.stats {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1.25rem;
  min-width: 120px;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-bottom: 1.5rem;
}

.search-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.search-box input::placeholder {
  color: var(--text-muted);
}

.filter-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sort-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sort-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-right: 0.125rem;
}

.tab {
  padding: 0.4rem 0.875rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.tab:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

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

.btn-ghost {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-icon:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.btn-icon.danger:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* Drama cards */
.drama-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.drama-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  transition: border-color 0.2s, transform 0.15s;
}

.drama-card:hover {
  border-color: #3e3e4e;
}

.drama-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.drama-title {
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
}

.drama-status-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.status-watching {
  background: var(--accent-soft);
  color: var(--accent);
}

.drama-card.archived {
  opacity: 0.85;
}

.restore-btn {
  margin-right: auto;
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
}

.status-completed {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
}

.status-on_hold {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}

.episode-section {
  margin-bottom: 0.75rem;
}

.episode-count {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.drama-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.drama-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.episode-controls {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-right: auto;
}

.episode-controls .btn-icon {
  font-size: 1.25rem;
  font-weight: 600;
}

.episode-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 3rem;
  text-align: center;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* Modal */
.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 440px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-form h2 {
  font-size: 1.2rem;
  margin-bottom: 0.25rem;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.required {
  color: var(--accent);
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  padding: 0.625rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.modal-form input:focus,
.modal-form select:focus,
.modal-form textarea:focus {
  border-color: var(--accent);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 600px) {
  .app {
    padding: 1.25rem 1rem 3rem;
  }

  .header-title-row {
    flex-direction: column;
    gap: 0.75rem;
  }

  .header-actions {
    align-self: flex-start;
  }

  .sync-btn {
    align-self: flex-start;
  }

  .header-top h1 {
    font-size: 1.5rem;
  }

  .drama-card-header {
    flex-direction: column;
    gap: 0.375rem;
  }

  .drama-actions {
    flex-wrap: wrap;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .btn-primary {
    flex: 1;
  }
}
