/* ==================== ROOT THEME ==================== */
:root {
  --sage: #8aad8f;
  --sage-light: #b5ccb8;
  --sage-dark: #5d8264;
  --cream: #f7f4ee;
  --cream-deep: #ede8df;
  --white: #ffffff;
  --stone: #c4b9a8;
  --stone-dark: #9e9080;
  --mist: #e8ede9;
  --bark: #5c4f3d;
  --bark-light: #7a6a56;
  --text-primary: #2e2a24;
  --text-secondary: #6b6257;
  --text-muted: #9e9080;
  --danger: #c0614a;
  --danger-soft: #f5e8e5;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  --shadow-1: 0 1px 2px rgba(60, 50, 35, .06);
  --shadow-2: 0 4px 10px rgba(60, 50, 35, .08);
  --shadow-3: 0 10px 24px rgba(60, 50, 35, .12);
  --shadow-4: 0 20px 44px rgba(60, 50, 35, .16);

  --ease: cubic-bezier(.4, 0, .2, 1);
  --t: 200ms var(--ease);

  --badge-movie-bg: #edf0f7;
  --badge-movie-fg: #5060a0;
  --badge-show-bg: #f0ede8;
  --badge-show-fg: #8a6a30;
  --badge-book-bg: #eaf0e6;
  --badge-book-fg: #5d8264;
}

[data-theme="dark"] {
  --cream: #1a1a1e;
  --cream-deep: #222226;
  --white: #242428;
  --bark: #d4cdc0;
  --bark-light: #b0a996;
  --mist: #2a2d2a;
  --text-primary: #e8e4de;
  --text-secondary: #b3ab9d;
  --text-muted: #8a8276;
  --stone: #4a4640;
  --stone-dark: #6b6459;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 4px 10px rgba(0, 0, 0, .35);
  --shadow-3: 0 10px 24px rgba(0, 0, 0, .45);
  --shadow-4: 0 20px 44px rgba(0, 0, 0, .55);

  --badge-movie-bg: #2a2d3a;
  --badge-movie-fg: #8090c0;
  --badge-show-bg: #352e22;
  --badge-show-fg: #c0a060;
  --badge-book-bg: #223526;
  --badge-book-fg: #8fbf8f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--cream);
  transition: background var(--t), color var(--t);
  min-height: 100vh;
}

h1, h2, h3, .serif {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  letter-spacing: -.015em;
}

.micro-label,
.stat-label {
  text-transform: uppercase;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--text-muted);
}

/* ==================== AMBIENT BACKGROUND ==================== */
.ambient {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .55;
  transition: opacity var(--t);
}

[data-theme="dark"] .orb {
  opacity: .15;
}

.orb-sage-1 {
  width: 600px;
  height: 600px;
  top: -150px;
  left: -150px;
  background: radial-gradient(circle, var(--sage) 0%, transparent 70%);
  animation: drift1 24s ease-in-out infinite -4s;
}

.orb-sand {
  width: 500px;
  height: 500px;
  top: 20%;
  right: -120px;
  background: radial-gradient(circle, var(--stone) 0%, transparent 70%);
  animation: drift2 28s ease-in-out infinite -12s;
}

.orb-sage-2 {
  width: 400px;
  height: 400px;
  bottom: -120px;
  left: 30%;
  background: radial-gradient(circle, var(--sage-light) 0%, transparent 70%);
  animation: drift3 20s ease-in-out infinite -8s;
}

[data-theme="dark"] .orb-sage-1,
[data-theme="dark"] .orb-sage-2 {
  background: radial-gradient(circle, #2f5d3a 0%, transparent 70%);
}

[data-theme="dark"] .orb-sand {
  background: radial-gradient(circle, #4a3a28 0%, transparent 70%);
}

@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(60px, 40px) scale(1.15); }
}

@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-50px, 30px) scale(1.1); }
}

@keyframes drift3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -40px) scale(1.2); }
}

/* ==================== LAYOUT ==================== */
.app {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ==================== HEADER ==================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 16px;
}

.app-title {
  font-size: 2.2rem;
  margin: 0 0 2px;
  color: var(--text-primary);
}

.app-subtitle {
  margin: 0;
  text-transform: uppercase;
  font-size: .74rem;
  letter-spacing: .08em;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--stone);
  background: var(--white);
  color: var(--bark);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform var(--t), box-shadow var(--t), background var(--t);
}

.theme-toggle:hover {
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

.btn-add {
  background: var(--sage-dark);
  color: #fff;
  border: none;
  border-radius: var(--r-pill);
  padding: 10px 20px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(93, 130, 100, .35);
  transition: transform var(--t), box-shadow var(--t);
}

.btn-add:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(93, 130, 100, .45);
}

/* ==================== STATS ==================== */
.stats-card {
  background: var(--white);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  padding: 24px 8px;
  margin-bottom: 24px;
  transition: background var(--t);
}

.stat-col {
  position: relative;
  text-align: center;
  padding: 0 12px;
}

.stat-col:not(:first-child)::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 36px;
  background: var(--stone);
  opacity: .4;
}

.stat-number {
  font-family: 'DM Serif Display', serif;
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.stat-progress-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.progress-track {
  width: 100%;
  max-width: 140px;
  height: 6px;
  background: var(--mist);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--sage-light), var(--sage-dark));
  border-radius: var(--r-pill);
  transition: width .6s var(--ease);
}

/* ==================== CONTROLS ROW ==================== */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.pill-group {
  display: inline-flex;
  background: var(--white);
  border-radius: var(--r-pill);
  padding: 4px;
  box-shadow: var(--shadow-1);
  gap: 2px;
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: .82rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background var(--t), color var(--t), box-shadow var(--t);
  white-space: nowrap;
}

.pill:hover { color: var(--text-primary); }

.pill.active {
  background: var(--sage-dark);
  color: #fff;
  box-shadow: 0 4px 12px rgba(93, 130, 100, .3);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border-radius: var(--r-pill);
  padding: 9px 16px;
  box-shadow: var(--shadow-1);
  flex: 1;
  min-width: 200px;
  transition: box-shadow var(--t);
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box:focus-within {
  box-shadow: 0 0 0 3px rgba(138, 173, 143, .18);
}

.search-box input {
  border: none;
  outline: none;
  background: transparent;
  font-family: 'DM Sans', sans-serif;
  font-size: .86rem;
  color: var(--text-primary);
  width: 100%;
}

/* ==================== SERVICE ROW ==================== */
.service-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.service-chip {
  border: 1px solid var(--stone);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}

.service-chip:hover {
  border-color: var(--sage-dark);
  color: var(--text-primary);
}

.service-chip.active {
  background: var(--sage);
  border-color: var(--sage);
  color: #fff;
}

/* ==================== STATES ==================== */
.spinner-wrap {
  display: flex;
  justify-content: center;
  padding: 80px 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--mist);
  border-top-color: var(--sage-dark);
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.empty-emoji {
  font-size: 2.6rem;
  margin-bottom: 12px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}

.empty-state p {
  color: var(--text-secondary);
  margin: 0 0 20px;
}

/* ==================== CARD GRID ==================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.title-card {
  position: relative;
  background: var(--white);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--t), box-shadow var(--t), opacity var(--t);
}

.title-card::before {
  content: '';
  display: block;
  height: 4px;
  background: linear-gradient(90deg, var(--sage-light), var(--sage-dark));
}

.title-card.is-watched::before {
  background: linear-gradient(90deg, var(--stone), var(--stone-dark));
}

.title-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-4);
}

.title-card.is-watched {
  opacity: .72;
}

.card-body {
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.badge {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 3px 9px;
  border-radius: var(--r-pill);
}

.badge-movie { background: var(--badge-movie-bg); color: var(--badge-movie-fg); }
.badge-show { background: var(--badge-show-bg); color: var(--badge-show-fg); }
.badge-book { background: var(--badge-book-bg); color: var(--badge-book-fg); }
.badge-whom { background: var(--mist); color: var(--sage-dark); }
.badge-service { background: var(--mist); color: var(--text-secondary); }

.card-title {
  font-size: 1.15rem;
  margin: 0 0 4px;
  color: var(--text-primary);
}

.is-watched .card-title {
  text-decoration: line-through;
}

.card-genre {
  font-size: .78rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.card-notes {
  font-size: .8rem;
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.card-date {
  margin-top: auto;
  font-size: .74rem;
  color: var(--stone-dark);
  padding-top: 6px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--mist);
}

.btn-watch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--sage-dark);
  background: transparent;
  color: var(--sage-dark);
  font-size: .78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background var(--t), color var(--t);
}

.btn-watch svg { width: 14px; height: 14px; }

.btn-watch:hover {
  background: var(--sage-dark);
  color: #fff;
}

.btn-watch.is-watched {
  border-color: var(--stone-dark);
  color: var(--stone-dark);
}

.btn-watch.is-watched:hover {
  background: var(--stone-dark);
  color: #fff;
}

.card-icon-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t), color var(--t);
}

.icon-btn svg { width: 15px; height: 15px; }

.icon-btn:hover {
  background: var(--mist);
  color: var(--text-primary);
}

.icon-btn.icon-delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ==================== MODALS ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 25, 18, .38);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t), visibility var(--t);
  z-index: 100;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal-sheet {
  background: var(--white);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-4);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  transform: translateY(20px);
  transition: transform 280ms cubic-bezier(.34, 1.4, .4, 1), opacity var(--t);
  opacity: 0;
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
  opacity: 1;
}

.modal-sheet-sm {
  max-width: 380px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-head h2 {
  font-size: 1.4rem;
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--mist);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t);
}

.modal-close svg { width: 14px; height: 14px; }
.modal-close:hover { background: var(--stone); color: #fff; }

.field-group {
  margin-bottom: 16px;
}

.field-group label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-group input[type="text"],
.field-group textarea {
  width: 100%;
  background: var(--cream);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: .9rem;
  color: var(--text-primary);
  outline: none;
  transition: background var(--t), box-shadow var(--t), border-color var(--t);
  resize: vertical;
}

.field-group input[type="text"]:focus,
.field-group textarea:focus {
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(138, 173, 143, .22);
  border-color: var(--sage);
}

.tile-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tile-group-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.tile {
  border: 1.5px solid var(--stone);
  background: var(--cream);
  border-radius: var(--r-md);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: .84rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--t), background var(--t), color var(--t);
}

.tile svg { width: 20px; height: 20px; }

.tile:hover { border-color: var(--sage); }

.tile.active {
  border-color: var(--sage-dark);
  background: var(--mist);
  color: var(--sage-dark);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.btn-ghost {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: .86rem;
  padding: 10px 18px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background var(--t);
}

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

.btn-submit {
  border: none;
  background: var(--sage-dark);
  color: #fff;
  font-weight: 600;
  font-size: .86rem;
  padding: 10px 20px;
  border-radius: var(--r-pill);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(93, 130, 100, .35);
  transition: transform var(--t), box-shadow var(--t), opacity var(--t);
}

.btn-submit:hover { transform: translateY(-1px); }
.btn-submit:disabled { opacity: .7; cursor: default; transform: none; }

.btn-danger {
  border: none;
  background: var(--danger);
  color: #fff;
  font-weight: 600;
  font-size: .86rem;
  padding: 10px 20px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: transform var(--t), opacity var(--t);
}

.btn-danger:hover { transform: translateY(-1px); }
.btn-danger:disabled { opacity: .7; cursor: default; transform: none; }

.delete-copy {
  color: var(--text-secondary);
  font-size: .9rem;
  margin: 0 0 20px;
}

/* ==================== TOASTS ==================== */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}

.toast {
  background: var(--bark);
  color: var(--cream);
  padding: 12px 20px;
  border-radius: var(--r-pill);
  font-size: .86rem;
  font-weight: 500;
  box-shadow: var(--shadow-3);
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 280ms var(--ease), opacity 280ms var(--ease);
  max-width: 320px;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sage-light);
  flex-shrink: 0;
}

.toast.toast-error::before {
  background: var(--danger);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 640px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  .stats-card {
    grid-template-columns: 1fr 1fr;
    row-gap: 20px;
  }

  .stat-col::before {
    display: none;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    width: 100%;
    order: 10;
  }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    max-width: none;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .tile-group,
  .tile-group-3 {
    grid-template-columns: 1fr;
  }
}
