:root {
  --panel: rgba(20, 28, 48, 0.86);
  --accent: #ffd24a;
  --accent-2: #6fd36f;
  --btn: rgba(255, 255, 255, 0.16);
  --btn-active: rgba(255, 255, 255, 0.34);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8ec9ff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; }

/* ---- Start menu ---------------------------------------------------------- */
#start-menu {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #9fd2ff 0%, #6aa9e6 55%, #4b7fc0 100%);
  padding: 24px;
}
.menu-card {
  background: var(--panel);
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 380px; width: 100%;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
.menu-card h1 { font-size: 2.2rem; margin: 0 0 6px; }
.tagline { margin: 0 0 22px; opacity: 0.85; font-size: 1rem; }
.big-btn {
  display: block; width: 100%;
  margin: 10px 0; padding: 16px;
  font-size: 1.2rem; font-weight: 700;
  border: none; border-radius: 16px;
  background: var(--accent); color: #2a2000;
  cursor: pointer;
}
.big-btn.continue { background: var(--accent-2); color: #06300a; }
.big-btn:active { transform: scale(0.98); }
#btn-continue { display: none; }
.safe-note { margin: 18px 0 0; font-size: 0.78rem; opacity: 0.7; line-height: 1.5; }

/* ---- Account gate (sign-in + profile picker) ------------------------------ */
#gate {
  position: fixed; inset: 0; z-index: 35;
  display: none; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #9fd2ff 0%, #6aa9e6 55%, #4b7fc0 100%);
  padding: 24px;
}
.gate-card {
  background: var(--panel); color: #fff;
  border-radius: 24px; padding: 30px 26px;
  max-width: 400px; width: 100%; text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  max-height: 90vh; overflow-y: auto;
}
.gate-card h1 { font-size: 2rem; margin: 0 0 6px; }
.gate-sub { opacity: 0.85; margin: 0 0 18px; }
.gate-input { display: block; width: 100%; margin: 8px 0; padding: 13px 14px;
  border: none; border-radius: 12px; background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 1rem; }
.gate-input::placeholder { color: rgba(255, 255, 255, 0.55); }
.gate-btn { display: block; width: 100%; margin: 12px 0 6px; padding: 15px;
  border: none; border-radius: 14px; background: var(--accent); color: #2a2000; font-weight: 700; font-size: 1.1rem; }
.gate-btn.small { width: auto; padding: 11px 16px; margin: 0; font-size: 0.95rem; }
.gate-btn:active { transform: scale(0.98); }
.gate-link { background: none; border: none; color: #cfe0ff; text-decoration: underline; cursor: pointer; font-size: 0.9rem; padding: 8px; }
.gate-err { color: #ffcf9a; min-height: 18px; font-size: 0.85rem; }
.gate-note { background: rgba(255,255,255,0.12); border-radius: 10px; padding: 8px 12px; font-size: 0.8rem; margin: 6px 0 12px; }
.gate-consent { display: flex; align-items: flex-start; gap: 8px; text-align: left; font-size: 0.8rem; margin: 8px 0; line-height: 1.4; }
.gate-consent input { margin-top: 3px; }

.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; margin: 8px 0 16px; }
.profile-card { display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px; border: none; border-radius: 16px; background: rgba(255, 255, 255, 0.1); color: #fff; cursor: pointer; }
.profile-card:active { transform: scale(0.96); }
.profile-avatar { width: 56px; height: 56px; border-radius: 50%; color: #fff;
  font-size: 1.6rem; font-weight: 800; display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.2); }
.profile-name { font-weight: 700; font-size: 0.92rem; }
.gate-addrow { display: flex; gap: 8px; align-items: center; }
.gate-addrow .gate-input { margin: 0; }
.gate-footer { display: flex; justify-content: space-between; margin-top: 12px; border-top: 1px solid rgba(255,255,255,0.12); padding-top: 10px; }

/* ---- "Add to Home Screen" banner ------------------------------------------ */
.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); color: #fff;
  border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  transform: translateY(140%); opacity: 0; transition: transform 0.35s, opacity 0.35s;
  max-width: 460px; margin: 0 auto;
}
.install-banner.show { transform: translateY(0); opacity: 1; }
.install-icon { font-size: 1.6rem; flex: 0 0 auto; }
.install-msg { flex: 1; font-size: 0.85rem; line-height: 1.35; }
.install-msg b { color: var(--accent); }
.install-go { flex: 0 0 auto; border: none; border-radius: 10px; padding: 9px 16px;
  background: var(--accent); color: #2a2000; font-weight: 800; font-size: 0.9rem; }
.install-x { flex: 0 0 auto; border: none; background: rgba(255,255,255,0.14);
  color: #fff; width: 30px; height: 30px; border-radius: 8px; font-size: 14px; }

/* ---- HUD ------------------------------------------------------------------ */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button { pointer-events: auto; }

#crosshair {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 26px; color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}

#toast {
  position: absolute; top: 16%; left: 50%;
  transform: translateX(-50%);
  background: var(--panel); padding: 10px 18px;
  border-radius: 999px; font-weight: 600;
  opacity: 0; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

/* Right-hand action buttons */
#controls-right {
  position: absolute; right: 18px; bottom: 96px;
  display: flex; flex-direction: column-reverse; gap: 16px;
  align-items: center;
}
.act-btn {
  width: 76px; height: 76px; border-radius: 50%;
  border: none; font-size: 30px;
  background: var(--btn); color: #fff;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.act-btn:active { background: var(--btn-active); transform: scale(0.94); }
.act-btn.build { background: rgba(120, 200, 120, 0.28); }
.act-btn.mine { background: rgba(210, 160, 120, 0.28); }
.act-btn.build:first-child { }

/* Top-right small buttons */
#controls-top {
  position: absolute; top: 14px; right: 14px;
  display: flex; gap: 10px;
}
.top-btn {
  width: 52px; height: 52px; border-radius: 14px;
  border: none; font-size: 24px;
  background: var(--btn); color: #fff;
  backdrop-filter: blur(4px);
}
.top-btn:active { background: var(--btn-active); }

/* Hotbar */
#hotbar {
  position: absolute; left: 50%; bottom: 14px;
  transform: translateX(-50%);
  display: flex; gap: 6px;
  padding: 6px; border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  max-width: 96vw; overflow-x: auto;
  pointer-events: auto;
}
.slot {
  position: relative;
  width: 48px; height: 48px; flex: 0 0 auto;
  border-radius: 10px; border: 3px solid transparent;
  background: rgba(255, 255, 255, 0.12);
  display: flex; align-items: center; justify-content: center;
}
.slot img { width: 40px; height: 40px; image-rendering: pixelated; border-radius: 6px; }
.slot .item-emoji { width: 40px; height: 40px; font-size: 28px; display: flex; align-items: center; justify-content: center; }
.slot.selected { border-color: var(--accent); background: rgba(255, 210, 74, 0.22); }
.slot .count {
  position: absolute; right: 2px; bottom: 0;
  font-size: 12px; font-weight: 700;
  text-shadow: 0 1px 2px #000;
}

/* Virtual joystick (created by input.js) */
.joystick-base {
  position: fixed; z-index: 9; display: none;
  width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
}

/* ---- Inventory / crafting modal ------------------------------------------ */
#modal {
  position: fixed; inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.5); padding: 18px;
}
#modal.open { display: flex; }
.modal-panel {
  position: relative;
  background: var(--panel);
  border-radius: 20px; padding: 22px;
  width: 100%; max-width: 440px;
  max-height: 84vh; overflow-y: auto;
}
#modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px; border-radius: 10px;
  border: none; background: var(--btn); color: #fff; font-size: 18px;
}
#modal-body h3 { margin: 18px 0 10px; font-size: 1rem; opacity: 0.9; }
.mode-row { margin-bottom: 6px; }
.mode-btn {
  width: 100%; padding: 12px; border: none; border-radius: 12px;
  background: var(--accent); color: #2a2000; font-weight: 700; font-size: 1rem;
}

.craft-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.craft-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px; border: none;
  background: rgba(255, 255, 255, 0.1); color: #fff; text-align: left;
}
.craft-card img { width: 36px; height: 36px; image-rendering: pixelated; border-radius: 6px; }
.craft-card .item-emoji { width: 36px; height: 36px; font-size: 28px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.inv-cell .item-emoji { font-size: 26px; }
.eat-btn { position: absolute; left: 2px; bottom: 1px; border: none; border-radius: 6px;
  background: var(--accent-2); color: #06300a; font-size: 10px; font-weight: 800; padding: 1px 5px; }

/* Survival HUD (hearts + hunger), just above the hotbar in Adventure mode */
#survival-hud { position: absolute; left: 50%; bottom: 70px; transform: translateX(-50%);
  z-index: 8; text-align: center; pointer-events: none; }
#survival-hud .stat-row { font-size: 15px; letter-spacing: 1px; line-height: 1.35;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }
.craft-card.disabled { opacity: 0.45; }
.craft-label strong { display: block; font-size: 0.92rem; }
.craft-label span { font-size: 0.72rem; opacity: 0.8; }

.inv-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.inv-cell {
  position: relative; aspect-ratio: 1;
  border-radius: 10px; background: rgba(255, 255, 255, 0.1);
  display: flex; align-items: center; justify-content: center;
}
.inv-cell.empty { opacity: 0.35; }
.inv-cell img { width: 30px; height: 30px; image-rendering: pixelated; }
.inv-cell span {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000;
}

/* ---- Friendly confirm dialog --------------------------------------------- */
#confirm {
  position: fixed; inset: 0; z-index: 40;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55); padding: 24px;
}
#confirm.open { display: flex; }
.confirm-card {
  background: var(--panel); border-radius: 20px;
  padding: 26px; max-width: 360px; width: 100%; text-align: center;
}
.confirm-card p { margin: 0 0 20px; font-size: 1.05rem; line-height: 1.5; }
.confirm-btns { display: flex; gap: 12px; }
.confirm-btns .big-btn { margin: 0; flex: 1; background: var(--accent-2); color: #06300a; }
.confirm-btns .big-btn.danger { background: #ff8a6a; color: #3a0f00; }

/* On a wide screen (desktop testing) shrink the touch buttons a touch. */
@media (min-width: 900px) and (pointer: fine) {
  #controls-right, #controls-top .top-btn { opacity: 0.85; }
}

/* ==========================================================================
   CHAT + PARENT ZONE
   ========================================================================== */

/* Start-menu Parent Zone link */
.menu-link {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  margin: 4px auto 0; padding: 8px 14px;
  background: none; border: none; cursor: pointer;
  color: #cfe0ff; font-size: 0.95rem; text-decoration: underline;
}

/* Red alert badge (on Parent Zone buttons) */
.alert-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #ff4d4d; color: #fff; font-size: 11px; font-weight: 800;
  border-radius: 999px; line-height: 1;
}
#controls-top .top-btn { position: relative; }
#controls-top .alert-badge { position: absolute; top: -4px; right: -4px; }
.alert-badge[hidden] { display: none; }

/* Shared little controls */
.wide-btn { display: block; width: 100%; margin: 12px 0 6px; padding: 14px;
  border: none; border-radius: 14px; background: var(--accent); color: #2a2000;
  font-weight: 700; font-size: 1.05rem; cursor: pointer; }
.wide-btn:active { transform: scale(0.98); }
.link-btn { background: none; border: none; color: #bcd; text-decoration: underline;
  cursor: pointer; font-size: 0.9rem; padding: 8px; }
.link-btn.danger { color: #ff9b8a; }
.mini-btn { border: none; border-radius: 9px; padding: 7px 11px; margin-left: 6px;
  background: var(--btn); color: #fff; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.mini-btn.ok { background: var(--accent-2); color: #06300a; }
.mini-btn.danger { background: rgba(255,120,100,0.3); }
.icon-btn { width: 38px; height: 38px; border: none; border-radius: 10px;
  background: var(--btn); color: #fff; font-size: 17px; cursor: pointer; }
.muted { opacity: 0.72; }
.tiny { font-size: 0.75rem; line-height: 1.5; }
.badge { background: #ff4d4d; color: #fff; border-radius: 999px; padding: 0 6px;
  font-size: 0.72rem; margin-left: 4px; }

/* Overlays shared shape */
#chat-overlay, #parent-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,0.5);
}
#chat-overlay.open, #parent-overlay.open { display: flex; }
.chat-panel, .parent-panel {
  width: 100%; max-width: 460px;
  background: var(--panel); color: #fff;
  border-radius: 22px 22px 0 0;
  max-height: 88vh; display: flex; flex-direction: column;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 620px) {
  #chat-overlay, #parent-overlay { align-items: center; }
  .chat-panel, .parent-panel { border-radius: 22px; }
}

/* ---- Kid chat ---- */
.chat-header, .parent-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chat-title { font-size: 1.25rem; font-weight: 700; }
.chat-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 8px; }
.chat-tab { border: none; border-radius: 999px; padding: 7px 14px; background: var(--btn); color: #fff; font-weight: 600; white-space: nowrap; }
.chat-tab.active { background: var(--accent); color: #2a2000; }
.chat-whoami { display: flex; align-items: center; justify-content: space-between; font-size: 0.82rem; opacity: 0.85; margin-bottom: 6px; }
.chat-messages { flex: 1; overflow-y: auto; min-height: 200px; max-height: 46vh;
  display: flex; flex-direction: column; gap: 8px; padding: 6px 2px; }
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.msg-bubble { max-width: 78%; background: rgba(255,255,255,0.12); padding: 8px 12px; border-radius: 14px; }
.msg-row.mine .msg-bubble { background: var(--accent-2); color: #06300a; }
.msg-from { font-size: 0.72rem; font-weight: 700; opacity: 0.85; margin-bottom: 2px; }
.msg-text { font-size: 0.98rem; word-break: break-word; }
.msg-time { font-size: 0.62rem; opacity: 0.6; margin-top: 3px; text-align: right; }
.chat-inputrow { display: flex; gap: 8px; margin-top: 10px; }
.chat-input { flex: 1; padding: 13px 14px; border-radius: 12px; border: none; font-size: 1rem;
  background: rgba(255,255,255,0.14); color: #fff; }
.chat-input::placeholder { color: rgba(255,255,255,0.55); }
.chat-send { border: none; border-radius: 12px; padding: 0 18px; background: var(--accent); color: #2a2000; font-weight: 700; }
.chat-hint { min-height: 18px; font-size: 0.82rem; margin-top: 6px; }
.chat-hint.blocked { color: #ffd0a0; }
.chat-notice, .chat-picker { text-align: center; padding: 20px 10px; }
.chat-notice h3, .chat-picker h3 { margin: 0 0 8px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; margin: 14px 0; }
.picker-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px;
  border: none; border-radius: 14px; background: rgba(255,255,255,0.1); color: #fff; font-weight: 600; }
.picker-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--accent);
  color: #2a2000; font-size: 1.3rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }

/* ---- Parent zone ---- */
.parent-gate { text-align: center; padding: 12px 6px; }
.parent-gate h2 { margin: 4px 0 8px; }
.pin-input { display: block; width: 100%; margin: 8px 0; padding: 13px; border: none; border-radius: 12px;
  background: rgba(255,255,255,0.14); color: #fff; font-size: 1.1rem; text-align: center; letter-spacing: 4px; }
.pin-input.small { letter-spacing: normal; font-size: 0.95rem; text-align: left; }
.pin-err { color: #ff9b8a; min-height: 18px; font-size: 0.82rem; }
.parent-tabs { display: flex; gap: 4px; margin-bottom: 10px; overflow-x: auto; }
.parent-tab { flex: 1; border: none; border-radius: 10px; padding: 9px 6px; background: var(--btn);
  color: #fff; font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.parent-tab.active { background: var(--accent); color: #2a2000; }
.parent-body { overflow-y: auto; max-height: 64vh; padding: 2px; }
.group-card { background: rgba(255,255,255,0.08); border-radius: 14px; padding: 12px; margin-bottom: 12px; }
.group-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.member-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.member-row { display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,0.07); border-radius: 10px; padding: 8px 10px; font-size: 0.9rem; }
.member-row.pending { background: rgba(255,210,74,0.16); }
.member-name { word-break: break-word; }
.inline-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.inline-row.create { margin-top: 8px; }
.inline-input { flex: 1; padding: 10px 12px; border: none; border-radius: 10px;
  background: rgba(255,255,255,0.14); color: #fff; font-size: 0.92rem; }
.log-select { width: 100%; padding: 10px; border-radius: 10px; border: none; margin-bottom: 10px;
  background: rgba(255,255,255,0.14); color: #fff; font-size: 0.95rem; }
.log-view { display: flex; flex-direction: column; gap: 6px; }
.log-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: baseline;
  background: rgba(255,255,255,0.06); border-radius: 8px; padding: 7px 10px; font-size: 0.86rem; }
.log-from { font-weight: 700; color: var(--accent); }
.log-text { word-break: break-word; }
.log-time { font-size: 0.66rem; opacity: 0.6; }
.alert-card { border-radius: 12px; padding: 12px; margin-bottom: 10px; background: rgba(255,255,255,0.08);
  border-left: 4px solid #ffd24a; }
.alert-card.sev-high { border-left-color: #ff4d4d; background: rgba(255,77,77,0.12); }
.alert-card.sev-medium { border-left-color: #ffa54a; }
.alert-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.alert-cat { font-size: 0.72rem; background: rgba(0,0,0,0.3); padding: 2px 8px; border-radius: 999px; }
.alert-original { font-style: italic; background: rgba(0,0,0,0.25); padding: 8px 10px; border-radius: 8px; word-break: break-word; }
.alert-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.setting-block { border-top: 1px solid rgba(255,255,255,0.12); margin-top: 12px; padding-top: 12px; }
.setting-block.info { background: rgba(255,255,255,0.05); border-radius: 12px; padding: 12px; border-top: none; }
.setting-block h4 { margin: 0 0 8px; }
.consent-row { display: flex; align-items: flex-start; gap: 8px; margin: 8px 0; line-height: 1.4; }
.consent-row input { margin-top: 3px; }
.or-divider { text-align: center; opacity: 0.5; font-size: 0.8rem; margin: 12px 0 8px; text-transform: uppercase; letter-spacing: 1px; }
.gbtn-host { display: flex; justify-content: center; min-height: 44px; }
.setup-steps { margin: 10px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.setup-steps li { font-size: 0.85rem; line-height: 1.4; }
.setup-steps code { background: rgba(0,0,0,0.4); padding: 3px 7px; border-radius: 6px;
  font-family: ui-monospace, monospace; font-size: 0.8rem; display: inline-block; margin: 3px 0; word-break: break-all; }
.invite-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.invite-name { font-weight: 700; flex: 0 0 auto; margin-right: 4px; }
.invite-code { flex: 1 1 auto; min-width: 120px; font-family: ui-monospace, monospace; font-size: 0.82rem;
  background: rgba(0,0,0,0.35); padding: 6px 9px; border-radius: 8px; word-break: break-all; letter-spacing: 1px; }
.toggle { border: none; border-radius: 999px; padding: 9px 16px; font-weight: 700; }
.toggle.on { background: var(--accent-2); color: #06300a; }
.toggle.off { background: rgba(255,255,255,0.2); color: #fff; }
.segmented { display: flex; gap: 4px; background: rgba(0,0,0,0.25); border-radius: 10px; padding: 3px; }
.seg { border: none; background: none; color: #fff; padding: 7px 14px; border-radius: 8px; font-weight: 600; }
.seg.active { background: var(--accent); color: #2a2000; }

/* ==========================================================================
   GAME LAYER — quest tracker, journal, popups
   ========================================================================== */

/* Always-on objective tracker (top-left) */
#quest-tracker {
  position: absolute; top: 12px; left: 12px; z-index: 8;
  display: flex; align-items: stretch; gap: 8px;
  max-width: 62vw; pointer-events: none;
}
.tracker-goal {
  background: rgba(0,0,0,0.42); backdrop-filter: blur(4px);
  border-radius: 14px; padding: 8px 12px; min-width: 150px;
}
.tracker-title { font-size: 0.9rem; font-weight: 800; }
.tracker-desc { font-size: 0.72rem; opacity: 0.85; margin: 2px 0 6px; line-height: 1.3; }
.tracker-bar { height: 7px; border-radius: 4px; background: rgba(255,255,255,0.2); overflow: hidden; }
.tracker-bar span { display: block; height: 100%; background: var(--accent-2); border-radius: 4px; transition: width 0.3s; }
.tracker-count { font-size: 0.7rem; opacity: 0.9; margin-top: 3px; font-weight: 700; }
.tracker-start { pointer-events: auto; margin-top: 4px; border: none; border-radius: 9px;
  padding: 7px 12px; background: var(--accent); color: #2a2000; font-weight: 700; font-size: 0.82rem; }
.tracker-stars {
  background: rgba(0,0,0,0.42); backdrop-filter: blur(4px); border-radius: 14px;
  padding: 8px 12px; font-size: 0.95rem; align-self: flex-start; white-space: nowrap;
}
.tracker-stars b { color: var(--accent); }

/* Journal popup */
#journal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,0.5);
}
#journal-overlay.open { display: flex; }
.journal-panel {
  width: 100%; max-width: 460px; background: var(--panel); color: #fff;
  border-radius: 22px 22px 0 0; max-height: 88vh; display: flex; flex-direction: column;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 620px) {
  #journal-overlay { align-items: center; }
  .journal-panel { border-radius: 22px; }
}
.journal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.journal-header h2 { margin: 0; font-size: 1.25rem; }
.journal-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.jtab { flex: 1; border: none; border-radius: 10px; padding: 9px; background: var(--btn); color: #fff; font-weight: 700; }
.jtab.active { background: var(--accent); color: #2a2000; }
.journal-list { overflow-y: auto; max-height: 66vh; display: flex; flex-direction: column; gap: 8px; padding: 2px; }

.level-card { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.08);
  border-radius: 14px; padding: 10px 12px; }
.level-card.done { background: rgba(111,211,111,0.16); }
.level-card.active { background: rgba(255,210,74,0.16); outline: 2px solid rgba(255,210,74,0.5); }
.level-card.locked { opacity: 0.55; }
.level-icon { font-size: 1.5rem; width: 32px; text-align: center; }
.level-mid { flex: 1; }
.level-name { font-weight: 800; font-size: 0.98rem; }
.level-desc { font-size: 0.76rem; opacity: 0.82; line-height: 1.35; margin-top: 2px; }
.level-bar { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.2); overflow: hidden; margin-top: 6px; }
.level-bar span { display: block; height: 100%; background: var(--accent-2); }
.level-reward { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 800; font-size: 0.9rem; }
.reward-block { width: 26px; height: 26px; image-rendering: pixelated; border-radius: 5px; }

.award-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.award-card { background: rgba(255,255,255,0.07); border-radius: 14px; padding: 14px 10px; text-align: center; opacity: 0.6; }
.award-card.earned { opacity: 1; background: rgba(255,210,74,0.14); }
.award-icon { font-size: 1.8rem; }
.award-name { font-weight: 800; font-size: 0.85rem; margin-top: 4px; }
.award-desc { font-size: 0.72rem; opacity: 0.8; margin-top: 2px; line-height: 1.3; }

/* Celebration popups (level complete / achievement) */
#popup-stack { position: fixed; top: 12%; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.game-popup {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 2px solid var(--accent);
  border-radius: 16px; padding: 12px 18px; min-width: 240px; max-width: 92vw;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  opacity: 0; transform: translateY(-14px); transition: opacity 0.35s, transform 0.35s;
}
.game-popup.show { opacity: 1; transform: translateY(0); }
.popup-icon { font-size: 2rem; }
.popup-title { font-weight: 800; font-size: 0.98rem; }
.popup-sub { font-size: 0.8rem; opacity: 0.85; margin-top: 2px; }
