/* understanding.games — shared design system (palette from STYLE_GUIDE.md) */
:root {
  --cream: #fcf5eb;
  --paper: #fffaf2;
  --navy: #1d2849;
  --hoodie: #303353;
  --ink: #232a4d;
  --ink-soft: #4b5274;
  --gold: #daa145;
  --gold-hi: #f4c652;
  --cyan: #82f0f2;
  --grass: #687737;
  --leaf: #8ba446;
  --sky: #bfe0f2;
  --light: #f5ddb3;
  --sticky: #fbe08a;
  --red: #bc3824;
  --cosmic: #1d264d;
  --cosmic-deep: #121838;
  --font-title: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-hand: 'Patrick Hand', 'Comic Sans MS', cursive;
  --font-read: 'Andika', 'Segoe UI', system-ui, sans-serif;
  --radius: 22px;
  --shadow: 0 12px 30px rgba(29, 40, 73, 0.18);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-read);
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-title); line-height: 1.12; margin: 0 0 0.4em; color: var(--navy); }
p { margin: 0 0 0.8em; }
.hand { font-family: var(--font-hand); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 4px solid var(--gold-hi); outline-offset: 3px; border-radius: 8px; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px clamp(16px, 4vw, 40px);
  transition: background 0.3s, box-shadow 0.3s;
}
.topbar.solid { background: rgba(252, 245, 235, 0.92); backdrop-filter: blur(10px); box-shadow: 0 2px 18px rgba(29, 40, 73, 0.12); }
.topbar.dark.solid { background: rgba(18, 24, 56, 0.85); }
.logo {
  font-family: var(--font-title); font-weight: 700; font-size: 1.25rem; color: var(--navy);
  text-decoration: none; display: flex; align-items: center; gap: 8px;
}
.topbar.dark .logo { color: var(--cream); }
.logo .star { color: var(--gold); display: inline-block; animation: spin-slow 9s linear infinite; }
.account { display: flex; align-items: center; gap: 10px; }
.chip {
  font-family: var(--font-title); font-weight: 600; font-size: 0.95rem;
  background: var(--paper); color: var(--navy); border-radius: 999px; padding: 6px 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12); border: 0; cursor: pointer; white-space: nowrap;
}
@media (max-width: 480px) {
  .logo { font-size: 1rem; gap: 6px; }
  .account { gap: 6px; }
  .account .chip { font-size: 0.8rem; padding: 5px 10px; }
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-title); font-weight: 600; font-size: 1.15rem; letter-spacing: 0.01em;
  border: 0; border-radius: 999px; padding: 0.85em 1.5em; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 0.5em; justify-content: center;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.18s var(--ease-pop), box-shadow 0.18s, filter 0.18s;
}
.btn:hover { transform: translateY(-3px) rotate(-1.2deg); filter: brightness(1.04); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-gold { background: var(--gold-hi); color: var(--navy); }
.btn-navy { background: var(--navy); color: var(--cream); }
.btn-paper { background: var(--paper); color: var(--navy); }
.btn-small { font-size: 0.95rem; padding: 0.55em 1.05em; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18); }

/* ---------- sticky note + notebook ---------- */
.sticky {
  position: relative; background: var(--sticky); color: var(--ink);
  font-family: var(--font-hand); font-size: 1.3rem; line-height: 1.3;
  padding: 1.2rem 1.3rem 1rem; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.13);
  transform: rotate(-1.6deg);
}
.sticky:nth-child(even) { transform: rotate(1.4deg); }
.sticky::before {
  content: ''; position: absolute; top: -11px; left: 50%; width: 76px; height: 24px;
  background: rgba(255, 255, 255, 0.6); transform: translateX(-50%) rotate(2deg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.notebook {
  position: relative; background: var(--paper); border-radius: 14px; padding: 1.2rem 1.4rem 1.2rem 2.6rem;
  box-shadow: var(--shadow);
  background-image: repeating-linear-gradient(transparent 0 30px, rgba(130, 170, 210, 0.35) 30px 31px);
  font-family: var(--font-hand); font-size: 1.3rem;
}
.notebook::before {
  content: ''; position: absolute; left: 12px; top: 14px; bottom: 14px; width: 12px;
  background: radial-gradient(circle, var(--navy) 4px, transparent 5px) 0 0 / 12px 24px repeat-y;
}

/* ---------- robot helper ---------- */
.robot-helper { display: flex; align-items: flex-end; gap: 10px; }
.robot-helper img { width: 76px; flex: none; animation: bob 3.2s ease-in-out infinite; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.18)); }
.robot-helper.happy img { animation: hop 0.7s var(--ease-pop) 2, bob 3.2s ease-in-out 1.4s infinite; }
.robot-helper.thinking img { animation: think 1s ease-in-out infinite; }
.bubble {
  position: relative; background: var(--paper); color: var(--ink); border-radius: 18px; padding: 0.7rem 1rem;
  font-family: var(--font-hand); font-size: 1.25rem; line-height: 1.3; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  max-width: 34ch; animation: pop-in 0.35s var(--ease-pop);
}
.bubble::after {
  content: ''; position: absolute; left: -9px; bottom: 16px; border: 10px solid transparent;
  border-right-color: var(--paper); border-left: 0;
}

/* ---------- auth dialog ---------- */
dialog.auth {
  border: 0; border-radius: 26px; padding: 0; width: min(460px, calc(100vw - 32px));
  background: var(--paper); color: var(--ink); box-shadow: 0 30px 80px rgba(18, 24, 56, 0.45);
}
dialog.auth[open] { animation: dialog-in 0.4s var(--ease-pop); }
dialog.auth::backdrop { background: rgba(18, 24, 56, 0.55); backdrop-filter: blur(4px); }
.auth-inner { padding: 26px 26px 22px; }
.auth-tabs { display: flex; gap: 6px; background: #f1e8d8; border-radius: 999px; padding: 5px; margin-bottom: 18px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 8px 6px; cursor: pointer;
  font-family: var(--font-title); font-weight: 600; font-size: 0.92rem; color: var(--ink-soft);
}
.auth-tabs button[aria-selected='true'] { background: var(--navy); color: var(--cream); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-family: var(--font-title); font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; color: var(--navy); }
.field .row { display: flex; gap: 8px; }
.input {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 0.7em 0.9em; border-radius: 14px;
  border: 3px solid #e6dcc8; background: #fff; color: var(--ink); transition: border-color 0.2s;
}
.input:focus { outline: none; border-color: var(--gold); }
.icon-btn {
  flex: none; width: 50px; border: 0; border-radius: 14px; background: var(--sticky); cursor: pointer; font-size: 1.3rem;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.14); transition: transform 0.2s var(--ease-pop);
}
.icon-btn:hover { transform: rotate(-12deg) scale(1.06); }
.auth-note { font-size: 0.92rem; color: var(--ink-soft); margin: 4px 0 14px; }
.auth-error { color: var(--red); font-weight: 700; min-height: 1.4em; font-size: 0.95rem; }
.auth-close { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--ink-soft); }
.code-card {
  text-align: center; background: var(--navy); color: var(--cream); border-radius: 20px; padding: 18px; margin: 10px 0 16px;
}
.code-card .code { font-family: var(--font-title); font-weight: 700; font-size: 1.7rem; letter-spacing: 0.06em; color: var(--gold-hi); }

/* ---------- mantra banner ---------- */
.mantra {
  background: var(--navy); color: var(--cream); text-align: center; font-family: var(--font-hand);
  font-size: clamp(1.3rem, 3vw, 2rem); padding: 1.1em 1em;
}
.mantra b { color: var(--gold-hi); font-weight: 400; }

/* ---------- toasts ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 90;
  background: var(--navy); color: var(--cream); border-radius: 999px; padding: 12px 22px; font-family: var(--font-title);
  box-shadow: var(--shadow); animation: toast-in 0.4s var(--ease-pop);
}

/* ---------- printing (Explorer Code, North Star card) ---------- */
#print-sheet { display: none; }
@media print {
  body > *:not(#print-sheet) { display: none !important; }
  #print-sheet { display: block; font-family: var(--font-read); color: #000; padding: 40px; }
  #print-sheet img { max-width: 100%; }
}

/* ---------- keyframes ---------- */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-26px) scale(1.06, 0.96); } }
@keyframes think { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes wave { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(3deg); } }
@keyframes twinkle { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.15); } }
@keyframes pop-in { 0% { opacity: 0; transform: scale(0.5); } 70% { opacity: 1; transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(30px) scale(0.92); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes spin-slow { to { transform: rotate(360deg); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
@keyframes float-up { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(-90px) scale(1.5); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
