:root {
  --paper: #FDF8EE;
  --paper-warm: #F5ECD9;
  --ink: #2A2320;
  --ink-soft: #5D524B;
  --terracotta: #D95D39;
  --terracotta-dark: #B54424;
  --board: #1F5A42;
  --board-light: #2B7A5A;
  --gold: #F4B942;
  --sky: #56A8D8;
  --cream: #FFFDF7;
  --danger: #D64545;
  --ok: #2D8A56;
  --shadow: 3px 3px 0px #2A2320;
  --shadow-lg: 5px 5px 0px #2A2320;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
input, textarea { user-select: text; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #89CFF0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
}

#game-canvas {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none;
}

/* Subtle paper grain overlay */
.paper-grain {
  pointer-events: none; position: fixed; inset: 0; z-index: 2; opacity: 0.06;
  background-image: repeating-linear-gradient(
    -45deg, rgba(42,35,32,0.18) 0px, rgba(42,35,32,0.18) 1px, transparent 1px, transparent 6px
  );
}

.font-display { font-family: 'Bungee', cursive; letter-spacing: 0.4px; }
.font-hand { font-family: 'Patrick Hand', cursive; }

/* TOP HUD */
#hud-top {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px;
  z-index: 20; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }

.hud-badge {
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 14px;
  box-shadow: var(--shadow); padding: 7px 11px; display: flex; align-items: center; gap: 8px;
}
.hud-avatar-dot {
  width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--ink);
  background: var(--gold); display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.hud-title { font-family: 'Bungee', cursive; font-size: 12px; line-height: 1.15; color: var(--ink); }
.hud-sub { font-size: 11px; color: var(--ink-soft); font-weight: 700; margin-top: 2px; }

.hud-stats {
  display: flex; flex-direction: column; align-items: flex-end; gap: 5px;
}
.stat-row { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  background: var(--cream); border: 2px solid var(--ink); border-radius: 999px;
  box-shadow: 2px 2px 0 var(--ink); padding: 4px 9px; font-size: 11px; font-weight: 800;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.pill-money { background: #FFF2C2; }
.pill-star { background: #FFE4B5; }
.pill-energy { background: #D9F7E5; }
.pill-zone {
  background: var(--board); color: #FFFDF7; border-color: var(--ink);
  font-family: 'Bungee', cursive; font-size: 10px; padding: 4px 10px;
}

/* ZONE QUICK-WARP STRIP */
#zone-strip {
  position: fixed; top: calc(max(10px, env(safe-area-inset-top)) + 124px); left: 10px; right: 10px;
  z-index: 18; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none; pointer-events: auto;
}
#zone-strip::-webkit-scrollbar { display: none; }

.zone-chip {
  flex-shrink: 0; background: var(--cream); border: 2px solid var(--ink); border-radius: 999px;
  box-shadow: 2px 2px 0 var(--ink); padding: 5px 11px; font-size: 11px; font-weight: 800;
  color: var(--ink); cursor: pointer; transition: transform 0.1s; display: inline-flex; align-items: center; gap: 4px;
}
.zone-chip.active { background: var(--terracotta); color: #FFFDF7; }
.zone-chip.locked { background: #E9E1D2; color: var(--ink-soft); }
.zone-chip:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }

/* CONTEXT INTERACT PROMPT */
#interact-banner {
  position: fixed; bottom: 106px; left: 50%; transform: translateX(-50%);
  z-index: 22; display: none; align-items: center; gap: 8px;
  background: var(--gold); border: 2.5px solid var(--ink); border-radius: 999px;
  box-shadow: var(--shadow); padding: 9px 18px; font-weight: 900; font-size: 13px;
  cursor: pointer; animation: floatPop 1.4s ease-in-out infinite;
}
@keyframes floatPop {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

/* VIRTUAL JOYSTICK */
#joystick-zone {
  position: fixed; bottom: 96px; left: 16px; width: 108px; height: 108px;
  z-index: 19; touch-action: none; display: flex; align-items: center; justify-content: center;
}
.joy-base {
  width: 94px; height: 94px; border-radius: 50%;
  background: rgba(253,248,238,0.55); border: 2.5px solid rgba(42,35,32,0.55);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.joy-knob {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--cream); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
  transform: translate(0, 0); transition: transform 0.04s linear;
}

/* QUICK RIGHT BUTTONS */
#quick-right {
  position: fixed; bottom: 104px; right: 14px; z-index: 19;
  display: flex; flex-direction: column; gap: 8px;
}
.fab-btn {
  width: 46px; height: 46px; border-radius: 14px; background: var(--cream);
  border: 2.5px solid var(--ink); box-shadow: var(--shadow);
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative;
}
.fab-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.fab-dot {
  position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--ink); display: none;
}

/* BOTTOM NAVIGATION BAR */
#hud-bottom {
  position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); left: 10px; right: 10px;
  z-index: 25; display: flex; justify-content: center; pointer-events: none;
}
.dock {
  pointer-events: auto; background: var(--cream); border: 2.5px solid var(--ink);
  border-radius: 18px; box-shadow: var(--shadow-lg); padding: 6px;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; width: 100%; max-width: 520px;
}
.dock-btn {
  border: 2px solid transparent; background: transparent; border-radius: 12px;
  padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer; color: var(--ink); font-weight: 800; font-size: 10px; position: relative;
}
.dock-btn span.ico { font-size: 18px; line-height: 1; }
.dock-btn.active { background: var(--paper-warm); border-color: var(--ink); }
.dock-btn:active { transform: scale(0.95); }

/* TOAST */
#toast {
  position: fixed; top: 112px; left: 50%; transform: translateX(-50%) translateY(-12px);
  z-index: 90; background: var(--ink); color: #FFFDF7; border-radius: 999px;
  padding: 9px 16px; font-size: 12px; font-weight: 700; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.22);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* MODALS & OVERLAYS */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(42,35,32,0.58);
  display: none; align-items: center; justify-content: center; padding: 14px;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }

.modal-card {
  width: 100%; max-width: 440px; max-height: 86vh; overflow-y: auto;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px;
  box-shadow: var(--shadow-lg); padding: 18px; position: relative;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 2px dashed rgba(42,35,32,0.25);
}
.modal-title { font-family: 'Bungee', cursive; font-size: 16px; margin: 0; color: var(--ink); }
.btn-close {
  width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--ink);
  background: var(--cream); font-weight: 900; font-size: 16px; cursor: pointer;
}

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 13px; border: 2.5px solid var(--ink);
  font-weight: 800; font-size: 13px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform 0.1s; width: 100%;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn-primary { background: var(--terracotta); color: #FFFDF7; }
.btn-green { background: var(--board); color: #FFFDF7; }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-cream { background: var(--cream); color: var(--ink); }
.btn-sm { padding: 7px 11px; font-size: 11px; width: auto; }

/* FORMS */
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 11px; font-weight: 800; margin-bottom: 4px; color: var(--ink-soft); }
.field input, .field select {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--ink);
  background: var(--cream); font-size: 14px; font-weight: 600; color: var(--ink);
  outline: none;
}
.field input:focus { border-color: var(--terracotta); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab-btn {
  flex: 1; padding: 8px; border-radius: 11px; border: 2px solid var(--ink);
  background: var(--cream); font-weight: 800; font-size: 12px; cursor: pointer;
}
.tab-btn.active { background: var(--gold); }

/* INTRO SLIDES */
#intro-overlay {
  position: fixed; inset: 0; z-index: 80; background: linear-gradient(180deg, #56A8D8 0%, #FDF8EE 65%);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.intro-box {
  width: 100%; max-width: 410px; background: var(--paper); border: 3px solid var(--ink);
  border-radius: 24px; box-shadow: var(--shadow-lg); padding: 22px 20px; text-align: center;
}
.intro-art {
  width: 112px; height: 112px; margin: 0 auto 14px; border-radius: 24px;
  border: 3px solid var(--ink); background: var(--gold); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; font-size: 56px;
}
.intro-dots { display: flex; justify-content: center; gap: 7px; margin: 14px 0; }
.intro-dot { width: 9px; height: 9px; border-radius: 50%; background: #D8CEBC; border: 1.5px solid var(--ink); }
.intro-dot.active { width: 24px; border-radius: 99px; background: var(--terracotta); }

/* CATALOG & DECOR GRID */
.cat-strip { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; scrollbar-width: none; }
.cat-strip::-webkit-scrollbar { display: none; }
.cat-pill {
  flex-shrink: 0; padding: 5px 10px; border-radius: 999px; border: 2px solid var(--ink);
  background: var(--cream); font-size: 11px; font-weight: 800; cursor: pointer;
}
.cat-pill.active { background: var(--board); color: #FFFDF7; }

.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.shop-card {
  background: var(--cream); border: 2px solid var(--ink); border-radius: 14px;
  padding: 10px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  box-shadow: 2px 2px 0 var(--ink);
}
.shop-ico { font-size: 28px; text-align: center; }
.shop-name { font-weight: 800; font-size: 12px; line-height: 1.2; }
.shop-meta { font-size: 10px; color: var(--ink-soft); }

/* CLASSROOM SEAT GRID (ABSEN 1-30) */
.seat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seat-cell {
  border: 2px solid var(--ink); border-radius: 11px; padding: 6px 3px; text-align: center;
  background: var(--cream); cursor: pointer; font-size: 10px; font-weight: 800;
}
.seat-cell.mine { background: var(--gold); }
.seat-cell.occupied { background: #DFF2E6; }
.seat-cell.empty { background: #F1EAE0; color: var(--ink-soft); }

/* MINI-GAMES */
.minigame-box {
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 16px;
  padding: 14px; text-align: center; margin-bottom: 10px;
}
.order-bubble {
  font-size: 38px; padding: 10px; background: #FFF2C2; border: 2px solid var(--ink);
  border-radius: 14px; display: inline-block; margin: 8px 0;
}
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 10px; }
.menu-btn {
  padding: 10px 6px; border-radius: 12px; border: 2px solid var(--ink); background: var(--paper);
  font-weight: 800; font-size: 12px; cursor: pointer; box-shadow: 2px 2px 0 var(--ink);
}
.menu-btn:active { transform: translate(1px, 1px); }

/* PIKET ARENA */
.piket-arena {
  position: relative; width: 100%; height: 220px; border-radius: 16px;
  border: 2.5px solid var(--ink); background: linear-gradient(180deg, #E8F5E9 0%, #D7CCC8 100%);
  overflow: hidden; margin-bottom: 10px;
}
.trash-item {
  position: absolute; font-size: 30px; cursor: pointer; padding: 4px;
  transition: transform 0.1s;
}
.trash-item:active { transform: scale(1.3); }

/* CHECKIN STREAK */
.streak-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.streak-day {
  border: 2px solid var(--ink); border-radius: 12px; padding: 8px 4px; text-align: center;
  background: var(--cream); font-size: 10px; font-weight: 800;
}
.streak-day.done { background: #D9F7E5; }
.streak-day.today { background: var(--gold); }

/* LEADERBOARD */
.lb-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: 12px; border: 2px solid var(--ink);
  background: var(--cream); margin-bottom: 6px; font-size: 12px; font-weight: 700;
}
.lb-rank {
  width: 26px; height: 26px; border-radius: 8px; background: var(--gold);
  border: 2px solid var(--ink); display: flex; align-items: center; justify-content: center;
  font-family: 'Bungee', cursive; font-size: 11px; flex-shrink: 0;
}

/* STORY CARD PREVIEW */
#story-canvas {
  width: 100%; max-width: 260px; aspect-ratio: 9/16; display: block; margin: 0 auto 12px;
  border-radius: 14px; border: 2.5px solid var(--ink); box-shadow: var(--shadow);
}

/* AVATAR SWATCHES */
.swatch-row { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch {
  padding: 6px 10px; border-radius: 10px; border: 2px solid var(--ink);
  background: var(--cream); font-size: 11px; font-weight: 800; cursor: pointer;
}
.swatch.active { background: var(--gold); }

/* MISSION LIST */
.mission-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border: 2px solid var(--ink); border-radius: 12px;
  background: var(--cream); margin-bottom: 7px; font-size: 12px; font-weight: 700;
}
.mission-item.done { background: #D9F7E5; }

.info-box {
  background: #FFF2C2; border: 2px solid var(--ink); border-radius: 13px;
  padding: 10px 12px; font-size: 12px; line-height: 1.45; margin-bottom: 10px;
}

@media (max-width: 360px) {
  .dock-btn { font-size: 9px; }
  .dock-btn span.ico { font-size: 16px; }
}
