/* =========================================================================
   COZY STUDY GARDEN — Warm Storybook Pixel Design System (Anti-AI-Slop)
   100% Native Vietnamese Typography (Be Vietnam Pro) • Day / Sunset / Night
   ========================================================================= */
:root {
  --bg: #f8f1df;
  --bg-dot: rgba(92, 67, 44, 0.075);
  --surface: #fffdf7;
  --surface-2: #f4ead2;
  --border: #d5c199;
  --border-strong: #8c6a43;
  --text: #362517;
  --muted: #76614a;
  --accent: #d97718;
  --accent-hover: #c4660f;
  --accent-soft: #fdecd2;
  --green: #3f8f54;
  --green-soft: #e1f3e5;
  --red: #cf4945;
  --red-soft: #fce6e5;
  --blue: #3b78d8;
  --glow: transparent;
  --shadow-card: 0 4px 0 rgba(92, 67, 44, 0.12), 0 10px 24px rgba(92, 67, 44, 0.06);
  --shadow-ctl: 0 2px 0 rgba(92, 67, 44, 0.18);
  --radius: 16px;
  --radius-sm: 11px;
}

body.theme-sunset {
  --bg: #f6e4c6;
  --bg-dot: rgba(128, 72, 34, 0.08);
  --surface: #fff7ea;
  --surface-2: #f0d8b4;
  --border: #d5a676;
  --border-strong: #94582a;
  --text: #382012;
  --muted: #7d563c;
  --accent: #d45d22;
  --accent-hover: #bc4d17;
  --accent-soft: #fce2cf;
  --glow: rgba(247, 178, 103, 0.25);
}

body.theme-night {
  --bg: #1f1b18;
  --bg-dot: rgba(245, 234, 216, 0.045);
  --surface: #2c2621;
  --surface-2: #38302a;
  --border: #55483d;
  --border-strong: #8a735e;
  --text: #f5ead8;
  --muted: #bcae9b;
  --accent: #f0b243;
  --accent-hover: #f7c360;
  --accent-soft: rgba(240, 178, 67, 0.18);
  --green: #64be76;
  --green-soft: rgba(100, 190, 118, 0.16);
  --red: #f06c68;
  --red-soft: rgba(240, 108, 104, 0.16);
  --glow: rgba(255, 204, 102, 0.34);
  --shadow-card: 0 4px 0 rgba(0, 0, 0, 0.35), 0 12px 24px rgba(0, 0, 0, 0.22);
  --shadow-ctl: 0 2px 0 rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.2px, transparent 1.2px);
  background-size: 18px 18px;
  color: var(--text);
  line-height: 1.55;
  padding-bottom: 92px;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.35s ease, color 0.3s ease;
}

/* ===== STICKY HEADER ===== */
.header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 14px; padding: 11px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 3px 12px rgba(92, 67, 44, 0.06);
  position: sticky; top: 0; z-index: 30;
}
.brand {
  font-weight: 900; font-size: 16.5px; letter-spacing: -0.2px;
  display: inline-flex; align-items: center; gap: 7px; color: var(--text);
}
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill {
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800;
  background: var(--surface-2); border: 1.5px solid var(--border);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pill:first-child { background: var(--accent-soft); border-color: var(--accent); }

.container { max-width: 780px; margin: 0 auto; padding: 16px 14px; }

/* ===== CARDS & TYPOGRAPHY ===== */
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.card h2, .card h3 {
  margin: 0 0 10px 0;
  font-size: 15.5px; font-weight: 800; letter-spacing: -0.15px;
  display: flex; align-items: center; gap: 7px; color: var(--text);
}
.muted { color: var(--muted); font-size: 12.5px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.between { justify-content: space-between; }

/* ===== CONTROLS ===== */
button {
  font: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
  padding: 8px 13px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface-2); color: var(--text);
  box-shadow: var(--shadow-ctl); min-height: 38px;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
}
button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: 0.48; cursor: not-allowed; box-shadow: none; }
button.primary { background: var(--accent); color: #fffdf7; border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.success { background: var(--green); color: #fffdf7; border-color: var(--green); }
button.success:hover:not(:disabled) { filter: brightness(1.06); }
button.soft { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
button.sm { padding: 5px 10px; font-size: 12px; min-height: 32px; }

input, select, textarea {
  font: inherit; font-size: 13.5px; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  width: 100%; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="range"] { padding: 0; border: none; background: transparent; accent-color: var(--accent); }

/* ===== TABS & FLOATING BOTTOM DOCK ===== */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeSlide 0.18s ease-out; }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.bottom-nav {
  position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100vw - 20px)); z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 6px; background: var(--surface);
  border: 2px solid var(--border-strong); border-radius: 16px;
  box-shadow: 0 6px 24px rgba(54, 37, 23, 0.18);
}
.bottom-nav button {
  border: none; box-shadow: none; background: transparent;
  padding: 10px 6px; font-size: 13px; font-weight: 800; border-radius: 11px;
  color: var(--muted); min-height: 42px;
}
.bottom-nav button:hover { background: var(--surface-2); color: var(--text); transform: none; }
.bottom-nav button.active {
  background: var(--accent); color: #fffdf7;
  box-shadow: 0 2px 0 rgba(92, 48, 12, 0.25);
}

/* ===== PET GREETING & DAILY QUESTS ===== */
.pet-banner {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--accent-soft) 100%);
  border: 2px solid var(--border); border-radius: var(--radius);
  margin-bottom: 14px; box-shadow: var(--shadow-card);
}
.quest-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quest-item {
  padding: 11px 8px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface-2);
  font-size: 12.5px; font-weight: 700; text-align: center;
}
.quest-item.done { border-color: var(--green); background: var(--green-soft); color: var(--text); }

/* ===== STUDENT DEADLINE RADAR ===== */
.todo-item {
  padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface-2);
  display: flex; flex-direction: column; gap: 6px;
}
.todo-item.urgent { border-color: var(--red); background: var(--red-soft); }
.todo-item.soon { border-color: var(--accent); background: var(--accent-soft); }
.todo-item.done { opacity: 0.62; }
.subtask-row { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding-left: 6px; cursor: pointer; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}

/* ===== FOCUS WINDOW (BODY DOUBLING) ===== */
.focus-window {
  position: relative; overflow: hidden; border-radius: var(--radius);
  border: 2px solid var(--border-strong); padding: 20px 16px; text-align: center;
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 65%);
}
.timer-digits {
  font-size: 52px; font-weight: 900; letter-spacing: 2px; margin: 10px 0 8px;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.prog-wrap {
  height: 10px; border-radius: 999px; background: var(--surface-2);
  border: 1.5px solid var(--border); overflow: hidden; max-width: 420px; margin: 0 auto;
}
.prog-fill { height: 100%; background: var(--green); transition: width 0.35s ease; border-radius: 999px; }

/* ===== BOX BREATHING ===== */
.breath-circle {
  width: 78px; height: 78px; margin: 12px auto; border-radius: 50%;
  background: var(--green-soft); border: 3px solid var(--green);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12.5px; color: var(--text);
  transition: transform 3.8s ease-in-out;
}
.breath-circle.inhale { transform: scale(1.3); }
.breath-circle.exhale { transform: scale(0.86); }

/* ===== 8x8 COZY PIXEL GARDEN ===== */
.garden-wrap { overflow-x: auto; padding-bottom: 4px; }
.garden-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px;
  min-width: 340px; padding: 10px; border-radius: var(--radius);
  background: var(--surface-2); border: 2px solid var(--border-strong);
  position: relative;
}
.garden-cell {
  aspect-ratio: 1; border-radius: 9px;
  border: 1.5px dashed var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; position: relative;
  transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.garden-cell:hover { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.04); z-index: 2; }
.garden-cell.filled { border-style: solid; border-color: var(--border); }
.garden-cell.selected { border-color: var(--green); border-style: solid; box-shadow: 0 0 0 2.5px var(--green); }
.garden-cell.has-light { box-shadow: 0 0 20px 5px var(--glow); }
.garden-cell.pop-in { animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
.growth-pip { position: absolute; bottom: 2px; right: 3px; font-size: 10px; line-height: 1; }

/* ===== PET ROAMING (Utility-AI on garden grid) ===== */
.pet-roamer {
  position: absolute; right: 1px; bottom: 1px; z-index: 3;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: auto; cursor: pointer;
  animation: petWaddle 1.6s ease-in-out infinite;
}
.pet-roamer-alt { right: auto; left: 1px; bottom: 4px; animation-delay: 0.5s; }
.pet-roamer .px-pet { filter: drop-shadow(1px 2px 0 rgba(28,25,23,0.25)); }
.pet-bubble {
  font-size: 10px; line-height: 1; margin-top: -2px;
  background: var(--surface); border: 1.5px solid var(--text);
  border-radius: 8px; padding: 1px 4px; box-shadow: 2px 2px 0 var(--text);
}
.pet-dim { opacity: 0.55; filter: saturate(0.6); }
.pet-care-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 6px; font-size: 12px;
}
.pet-snack-pill {
  border: 1.5px solid var(--border); border-radius: 999px;
  padding: 1px 8px; background: var(--surface-2); font-size: 12px;
}
.pet-care-mini {
  display: flex; gap: 10px; font-size: 11px; color: var(--muted);
}
.decor-card.active-companion { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft, rgba(46,160,90,0.25)); }
@keyframes petWaddle {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-3px) rotate(2deg); }
}
@media (prefers-reduced-motion: reduce) {
  .pet-roamer, .px-pet { animation: none; }
}
.dust-overlay {
  position: absolute; inset: 0; pointer-events: none; border-radius: var(--radius);
  background: radial-gradient(circle at 22% 28%, rgba(168,150,124,0.28) 2px, transparent 3px),
              radial-gradient(circle at 74% 68%, rgba(168,150,124,0.28) 2px, transparent 3px);
  background-size: 46px 46px;
}

/* ===== PIXEL SPRITES & SHOP CARDS ===== */
.px-sprite { image-rendering: pixelated; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.px-pet { animation: petBob 2.1s ease-in-out infinite; }
.px-guest { animation: guestSlide 0.35s ease-out; }
.bloom-sparkle { filter: drop-shadow(0 0 5px rgba(245, 180, 30, 0.65)); }

.decor-shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 9px; }
.decor-card {
  padding: 12px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  text-align: center; gap: 5px;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.decor-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.decor-card.active { border: 2px solid var(--accent); background: var(--accent-soft); }

.guest-card {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: var(--radius-sm); border: 1.5px solid var(--border); background: var(--surface-2);
}
.energy-card summary {
  cursor: pointer; font-weight: 700; font-size: 14px; list-style: none;
}
.energy-card summary::before { content: "▸ "; color: var(--accent); }
.energy-card[open] summary::before { content: "▾ "; }
.letter-unread { border-color: var(--accent); background: var(--accent-soft); cursor: pointer; }
.letter-unread:hover { border-color: var(--accent-hover); }

/* ===== OPTIONAL EXTERNAL AI (BYOK, feature-gated) ===== */
.external-ai-box { border-top: 1px dashed var(--border); padding-top: 8px; }
.external-ai-box summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.cozy-checkin { margin-top: 8px; }
.cozy-checkin summary { cursor: pointer; font-size: 12px; color: var(--accent); font-weight: 600; }
.cozy-chat-log { display: flex; flex-direction: column; gap: 4px; max-height: 140px; overflow-y: auto; }
.cozy-msg-user, .cozy-msg-pet {
  font-size: 12px; padding: 5px 8px; border-radius: 9px; max-width: 92%;
  border: 1.5px solid var(--border); background: var(--surface-2);
}
.cozy-msg-user { align-self: flex-end; background: var(--accent-soft); }
.cozy-msg-pet { align-self: flex-start; }
#socraticResult .todo-item { cursor: default; }

/* ===== TOAST & FLOATING FX ===== */
.toast {
  position: fixed; top: 68px; left: 50%; transform: translateX(-50%); z-index: 999;
  padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 13px;
  background: var(--text); color: var(--bg); opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease; box-shadow: 0 6px 18px rgba(0,0,0,0.22);
  max-width: calc(100vw - 24px); text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--red); color: #fff; }

.fx-float {
  position: fixed; pointer-events: none; z-index: 9999; font-weight: 900; font-size: 14px;
  padding: 4px 10px; border-radius: 999px; background: #fef08a; color: #5c3a21;
  border: 2px solid #b45309; animation: fxRise 0.95s ease-out forwards;
}

@keyframes petBob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes guestSlide { 0% { opacity: 0; transform: translateX(-14px); } 100% { opacity: 1; transform: translateX(0); } }
@keyframes popIn { 0% { transform: scale(0.75); } 65% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes fxRise { 0% { opacity: 0; transform: translate(-50%, 6px); } 20% { opacity: 1; transform: translate(-50%, -8px); } 100% { opacity: 0; transform: translate(-50%, -44px); } }

@media (max-width: 600px) {
  .quest-grid { grid-template-columns: 1fr; }
  .timer-digits { font-size: 40px; }
  .header { padding: 9px 12px; }
  button { min-height: 42px; }
}
