@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Nunito:wght@400;600;700;800&display=swap');

/* ── TOKENS ─────────────────────────────────────────── */

:root {
  --bg:         #f5f0ff;
  --surface:    #ffffff;
  --surface2:   #ede8f8;
  --border:     #ddd0f5;
  --text:       #1a0a3c;
  --text-dim:   #7c6a9e;
  --purple:     #7c3aed;
  --purple-lt:  #a855f7;
  --purple-dk:  #5b21b6;
  --purple-bg:  #ede9fe;
  --yellow:     #f59e0b;
  --yellow-bg:  #fef3c7;
  --green:      #10b981;
  --red:        #ef4444;
  --shadow:     rgba(124,58,237,0.12);
  --font-body:  'Nunito', system-ui, sans-serif;
  --font-pixel: 'Press Start 2P', monospace;
}

[data-theme="dark"] {
  --bg:        #0d0019;
  --surface:   #1a0d2e;
  --surface2:  #2e1065;
  --border:    #3d1a6e;
  --text:      #f0e6ff;
  --text-dim:  #9d6ec7;
  --purple-bg: #2e1065;
  --yellow-bg: #2d1f00;
  --shadow:    rgba(0,0,0,0.4);
}

/* ── RESET ───────────────────────────────────────────── */

*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

.hidden { display: none !important; }

/* ── PIN SCREEN ─────────────────────────────────────── */

#pin-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--purple-dk) 0%, var(--bg) 60%);
}

.pin-container { width: 100%; text-align: center; }

.title-line1,
.title-line2 {
  font-family: var(--font-pixel);
  font-size: 26px;
  color: #ffffff;
  text-shadow: 0 0 20px rgba(168,85,247,0.8);
  letter-spacing: 2px;
  line-height: 1.6;
}

.title-ver {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: rgba(255,255,255,0.5);
  margin-bottom: 40px;
}

.pin-box {
  background: var(--surface);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.pin-label { font-weight: 700; font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }

#pin-input {
  display: block;
  width: 150px;
  margin: 0 auto 20px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 14px;
  color: var(--purple);
  font-family: var(--font-pixel);
  font-size: 24px;
  padding: 12px;
  text-align: center;
  letter-spacing: 8px;
  outline: none;
}
#pin-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}

.error-msg { color: var(--red); font-size: 13px; font-weight: 700; margin-top: 12px; }

/* ── BUTTONS ─────────────────────────────────────────── */

.btn {
  background: var(--purple);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 14px;
  padding: 14px 18px;
  cursor: pointer;
  min-height: 50px;
  transition: filter 0.15s, transform 0.1s;
  box-shadow: 0 4px 0 var(--purple-dk);
}
.btn:active {
  filter: brightness(0.9);
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--purple-dk);
}

.btn-full { width: 100%; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text-dim);
  box-shadow: 0 4px 0 var(--border);
}
.btn-secondary:active { box-shadow: 0 2px 0 var(--border); }

/* ── GAME SCREEN ─────────────────────────────────────── */

#game-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 50px;
}

.header-title {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--purple);
}

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

.header-level { font-weight: 800; font-size: 13px; color: var(--purple-lt); }
.header-xp    { font-weight: 800; font-size: 13px; color: var(--yellow); }

.theme-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── PANELS ─────────────────────────────────────────── */

#main-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.panel { padding: 16px; }

.panel-title {
  font-weight: 800;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── STATS ───────────────────────────────────────────── */

.player-card {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-lt) 100%);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 24px rgba(124,58,237,0.3);
  color: #fff;
}

.sprite {
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.8;
  color: rgba(255,255,255,0.9);
  flex-shrink: 0;
}

.p-name  { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.p-level {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--yellow);
  margin-bottom: 4px;
}
.p-title { font-size: 12px; font-weight: 600; opacity: 0.85; }

.xp-section   { margin-bottom: 14px; }
.xp-label {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.xp-label span:last-child { color: var(--yellow); font-weight: 800; }

.xp-bar {
  height: 20px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple) 0%, var(--purple-lt) 100%);
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 2px 8px rgba(124,58,237,0.4);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: 0 2px 8px var(--shadow);
}
.s-label {
  font-weight: 700;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}
.s-value {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--purple);
}

.week-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px var(--shadow);
}
.week-title { font-weight: 700; font-size: 11px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 10px; }
.week-days  { display: flex; gap: 6px; }
.week-day   { flex: 1; text-align: center; }
.day-name   { font-weight: 700; font-size: 11px; color: var(--text-dim); margin-bottom: 5px; }
.day-box    { height: 24px; border-radius: 8px; background: var(--surface2); border: 1px solid var(--border); }
.week-day.done  .day-box  { background: var(--purple); border-color: var(--purple-dk); box-shadow: 0 2px 6px rgba(124,58,237,0.3); }
.week-day.today .day-name { color: var(--purple); font-weight: 800; }

.phrase-box {
  background: var(--purple-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  border-left: 4px solid var(--purple);
}
.phrase-label { font-weight: 700; font-size: 11px; color: var(--purple); text-transform: uppercase; margin-bottom: 8px; }
.phrase-text  { font-size: 13px; color: var(--text-dim); line-height: 1.8; font-style: italic; font-weight: 600; }

/* ── MISSIONS ────────────────────────────────────────── */

.quests-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  margin-bottom: 18px;
  overflow: hidden;
  box-shadow: 0 4px 16px var(--shadow);
}

.quests-header {
  background: var(--purple);
  padding: 12px 16px;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.quest-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.quest-item:last-child { border-bottom: none; }

.quest-name { font-weight: 700; font-size: 13px; margin-bottom: 9px; color: var(--text); }

.quest-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quest-bar {
  flex: 1;
  height: 14px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.quest-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple) 0%, var(--purple-lt) 100%);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.quest-count    { font-weight: 700; font-size: 12px; color: var(--text-dim); white-space: nowrap; min-width: 36px; text-align: right; }
.quest-xp       { font-weight: 800; font-size: 12px; color: var(--yellow); white-space: nowrap; }
.quest-done-tag { font-weight: 800; font-size: 12px; color: var(--green); white-space: nowrap; }

.section-header {
  font-weight: 800;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  margin-top: 4px;
}

.mission-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: 0 2px 6px var(--shadow);
}
.mission-item:active { background: var(--purple-bg); border-color: var(--purple); }

.m-name { font-weight: 700; font-size: 13px; margin-bottom: 4px; color: var(--text); }
.m-xp   { font-weight: 800; font-size: 13px; color: var(--yellow); }

.mission-add {
  width: 40px;
  height: 40px;
  background: var(--purple);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 3px 0 var(--purple-dk);
  font-family: var(--font-body);
  font-weight: 400;
}

/* ── LOG ─────────────────────────────────────────────── */

.log-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 8px;
  box-shadow: 0 2px 6px var(--shadow);
}
.log-name { font-weight: 700; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.log-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); gap: 8px; font-weight: 600; }
.log-meta-left  { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-meta-right { white-space: nowrap; flex-shrink: 0; }
.log-xp   { color: var(--yellow); font-weight: 800; }
.log-mood { color: var(--purple-lt); }

.empty-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  padding: 50px 20px;
  line-height: 2.5;
}

/* ── REWARDS ─────────────────────────────────────────── */

.reward-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px var(--shadow);
}
.reward-item.available {
  border-color: var(--yellow);
  background: var(--yellow-bg);
  box-shadow: 0 4px 16px rgba(245,158,11,0.15);
}
.reward-item.claimed { opacity: 0.45; }

.reward-lvl  { font-weight: 700; font-size: 11px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 6px; }
.reward-name { font-weight: 800; font-size: 15px; margin-bottom: 6px; color: var(--text); }
.reward-desc { font-size: 13px; font-weight: 600; color: var(--text-dim); line-height: 1.7; margin-bottom: 12px; }

.reward-status         { font-weight: 700; font-size: 13px; }
.reward-status.locked  { color: var(--border); }
.reward-status.available { color: var(--yellow); }
.reward-status.claimed { color: var(--text-dim); }

.claim-btn { width: 100%; margin-top: 10px; font-size: 13px; }

/* ── JOURNAL ─────────────────────────────────────────── */

.journal-add-btn { width: 100%; margin-bottom: 14px; font-size: 14px; padding: 15px; }

.journal-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: 0 2px 6px var(--shadow);
}
.journal-date { font-weight: 700; font-size: 11px; color: var(--purple); text-transform: uppercase; margin-bottom: 8px; }
.journal-body { font-size: 13px; font-weight: 600; line-height: 1.8; color: var(--text); word-break: break-word; }

/* ── BOTTOM NAV ──────────────────────────────────────── */

.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding: 4px 8px 8px;
  gap: 4px;
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 14px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 10px;
  padding: 7px 2px;
  cursor: pointer;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, color 0.15s;
}

.nav-btn .nav-icon { font-size: 20px; line-height: 1; }

.nav-btn.active {
  background: var(--purple-bg);
  color: var(--purple);
}

/* ── MODALS ──────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 5000;
  padding: 0;
}

.modal-box {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
}

.modal-title { font-weight: 800; font-size: 16px; margin-bottom: 6px; color: var(--text); }
.modal-xp    { font-weight: 800; font-size: 20px; color: var(--yellow); margin-bottom: 16px; }
.modal-label { font-weight: 700; font-size: 12px; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; }

#modal-note, #journal-text {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 14px;
  margin-bottom: 14px;
  outline: none;
  resize: none;
}
#modal-note:focus, #journal-text:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.12);
}
#journal-text { height: 130px; line-height: 1.7; }

/* Mood selector */
.mood-label { font-weight: 700; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; text-transform: uppercase; }

.mood-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.mood-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  min-height: 40px;
  min-width: 36px;
  padding: 8px 6px;
  text-align: center;
}
.mood-btn.selected {
  background: var(--purple);
  border-color: var(--purple-dk);
  color: #fff;
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}

.mood-desc {
  font-weight: 700;
  font-size: 12px;
  color: var(--purple);
  margin-bottom: 16px;
  min-height: 16px;
}

.modal-actions { display: flex; gap: 8px; margin-top: 4px; }
.modal-actions .btn { flex: 1; font-size: 14px; }

/* ── ANIMATIONS ──────────────────────────────────────── */

.xp-popup {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(245,158,11,0.6);
  pointer-events: none;
  z-index: 8000;
  animation: float-up 1.4s ease forwards;
  white-space: nowrap;
}

@keyframes float-up {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  20%  { transform: translateX(-50%) translateY(-10px) scale(1.15); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-70px) scale(0.9); }
}

.levelup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,0,25,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9500;
  gap: 14px;
}

.lu-text {
  font-family: var(--font-pixel);
  font-size: 26px;
  color: var(--yellow);
  text-shadow: 0 0 30px var(--yellow);
  animation: pulse 0.5s ease infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.08); }
}

.lu-level  { font-size: 13px; color: rgba(255,255,255,0.5); font-weight: 600; }
.lu-name   { font-family: var(--font-pixel); font-size: 14px; color: #c084fc; }
.lu-reward { font-size: 14px; color: var(--yellow); text-align: center; line-height: 2; font-weight: 700; max-width: 260px; }

.quest-flash {
  position: fixed;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  z-index: 7000;
  white-space: nowrap;
  animation: flash-anim 2.2s ease forwards;
  box-shadow: 0 4px 16px rgba(16,185,129,0.4);
}

@keyframes flash-anim {
  0%  { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; }
  100%{ opacity: 0; }
}
