/*
  🎨 This file controls how every Rungjoy page LOOKS.
  The colors come from the Rungjoy design.
  There are two sets of colors: dark (the normal one) and light (further down, under [data-theme="light"]).
  Try changing --color-accent to another color like #ff7a59 and see what happens!
*/

:root {
  --color-bg: #161826;        /* the dark background */
  --color-surface: #232532;   /* cards and buttons */
  --color-text: #e9e9ed;      /* words */
  --color-accent: #9184d9;    /* the purple glow color */
  --color-accent-hover: #a99ee6;
  --color-on-accent: #161826; /* words on top of a filled purple button */
  --color-divider: color-mix(in srgb, #e9e9ed 16%, transparent);

  --color-neutral-400: #b2b6ca;
  --color-neutral-600: #75798c;
  --color-neutral-700: #595d6c;
  --color-neutral-800: #3f424d;
  --color-neutral-900: #292b31;

  --color-accent-100: #f5f4ff;
  --color-accent-200: #e7e5fe;
  --color-accent-300: #d2cefd;
  --color-accent-400: #b5abfc;
  --color-accent-700: #5d5294;
  --color-accent-800: #423a6a;
  --color-accent-900: #2b2741;

  --good: #6fd3a0;   /* green for right answers */
  --oops: #f08a8a;   /* soft red for "try again" */
  --warn: #f2c46d;   /* soft yellow for "heads up" notes */
  --skel-a: color-mix(in srgb, #e9e9ed 6%, transparent);  /* loading placeholders */
  --skel-b: color-mix(in srgb, #e9e9ed 13%, transparent);

  --glow: #262a60;          /* the soft purple glow behind welcome and results cards */
  --glow-strong: #353b80;
  --tag-neutral-text: #f3f5fe;
  --backdrop: rgba(10, 11, 20, 0.6);
  --muted: 58%;             /* how strong gray "muted" words are */

  --font: "Inter", system-ui, sans-serif;
  --radius: 8px;
  --shadow-sm: 0 0 0 1px #3f424d;
  --shadow-md: 0 0 0 1px #595d6c, 0 6px 18px rgba(0, 0, 0, 0.55);
  --shadow-lift: 0 16px 40px rgba(0, 0, 0, 0.6);
  --sticky-shadow: rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---------- LIGHT MODE ----------
   Same names, lighter colors. The sun/moon button switches between them,
   and the choice is remembered on this device. */
:root[data-theme="light"] {
  --color-bg: #f3f3f8;
  --color-surface: #ffffff;
  --color-text: #1d1f2e;
  --color-accent: #6a5cc7;
  --color-accent-hover: #5a4cb6;
  --color-on-accent: #ffffff;
  --color-divider: color-mix(in srgb, #1d1f2e 15%, transparent);

  --color-neutral-400: #5d6175;
  --color-neutral-600: #9a9eae;
  --color-neutral-700: #c9ccd8;
  --color-neutral-800: #e4e6ee;
  --color-neutral-900: #eef0f5;

  --color-accent-100: #2d2670;
  --color-accent-200: #3d3490;
  --color-accent-300: #5145a8;
  --color-accent-400: #6a5cc7;
  --color-accent-700: #c5bdf3;
  --color-accent-800: #e4e0fb;
  --color-accent-900: #f2f0fd;

  --good: #1f8c58;
  --oops: #cf4842;
  --warn: #b27a0e;
  --skel-a: color-mix(in srgb, #1d1f2e 6%, transparent);
  --skel-b: color-mix(in srgb, #1d1f2e 12%, transparent);

  --glow: #e8e5fb;
  --glow-strong: #d9d3f8;
  --tag-neutral-text: #2a2d3d;
  --backdrop: rgba(30, 30, 50, 0.35);
  --muted: 70%;

  --shadow-sm: 0 0 0 1px #e0e1ea;
  --shadow-md: 0 0 0 1px #d6d8e2, 0 6px 18px rgba(40, 40, 80, 0.10);
  --shadow-lift: 0 16px 40px rgba(40, 40, 80, 0.22);
  --sticky-shadow: rgba(40, 40, 80, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
html { background: var(--color-bg); }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--color-text);
  background: radial-gradient(ellipse 900px 600px at 30% 30%, var(--color-neutral-800), var(--color-bg) 70%) fixed;
  -webkit-tap-highlight-color: transparent;
}

h1 { font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; margin: 0; }

.text-muted { color: color-mix(in srgb, var(--color-text) var(--muted), transparent); }
a { color: var(--color-accent); text-underline-offset: 3px; }
a:hover { color: var(--color-accent-300); }

/* little line icons (see icons.js) */
.ic { width: 1.15em; height: 1.15em; fill: currentColor; vertical-align: -0.2em; flex: none; }
.small { font-size: 12px; }
.hidden { display: none !important; }
/* Words only screen readers hear */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- shared pieces ---------- */

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  border-radius: 14px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.card-kicker {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: 500 15px var(--font);
  color: var(--color-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
}
/* The main button: filled and bright. Use only ONE per screen, for the thing you most want people to do. */
.btn-primary {
  color: var(--color-on-accent);
  background: var(--color-accent);
  border-color: var(--color-accent);
  font-weight: 600;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--color-accent) 30%, transparent);
}
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); color: var(--color-on-accent); }
.btn-primary:active { transform: translateY(1px); box-shadow: none; }
.btn-primary:disabled { opacity: 0.45; box-shadow: none; }
/* Everything else is quieter */
.btn-secondary { border-color: var(--color-divider); }
.btn-secondary:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.btn-ghost:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }

/* A clear ring around whatever the keyboard is on */
:focus-visible { outline: 2px solid var(--color-accent-400); outline-offset: 2px; }
.btn-primary:focus-visible { outline-offset: 3px; }
.btn-icon { width: 40px; height: 40px; padding: 0; font-size: 18px; }
.btn-big { height: 50px; font-size: 16px; width: 100%; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 6px;
  white-space: nowrap;
}
.tag-accent { background: var(--color-accent-800); color: var(--color-accent-100); }
.tag-neutral { background: var(--color-neutral-800); color: var(--tag-neutral-text); }
.tag-hot {
  background: var(--color-accent-700);
  color: var(--color-accent-100);
  box-shadow: 0 0 18px color-mix(in srgb, var(--color-accent) 50%, transparent);
}

/* ---------- screens ---------- */

.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px;
  gap: 20px;
}

/* ---------- start screen ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 500;
  align-self: center;
}
.brand-bars { display: flex; align-items: flex-end; gap: 3px; height: 22px; }
.brand-bars span { width: 6px; border-radius: 2px; }
.brand-bars span:nth-child(1) { height: 8px;  background: var(--color-accent-400); }
.brand-bars span:nth-child(2) { height: 14px; background: var(--color-accent-300); }
.brand-bars span:nth-child(3) { height: 22px; background: var(--color-accent); }

/* the buttons to switch between games */
.games-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}
.games-nav a {
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 14px;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
}
.games-nav a:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.games-nav a.on {
  color: var(--color-accent-100);
  background: var(--color-accent-800);
  box-shadow: inset 0 0 0 1px var(--color-accent);
}

.start-card, .how { width: 100%; max-width: 520px; }
.start-card { box-shadow: var(--shadow-md); padding: 32px; gap: 12px; }
.start-card h1 { font-size: 44px; }

.game-icon {
  width: 56px; height: 56px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 28px;
  background: var(--color-accent-900);
  color: var(--color-accent-300);
  box-shadow: inset 0 0 0 1px var(--color-accent-800);
}

.label { font-size: 13px; margin-top: 8px; color: color-mix(in srgb, var(--color-text) 70%, transparent); }

.level-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.level-btn {
  height: 44px;
  border-radius: var(--radius);
  border: none;
  font: 500 17px var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  box-shadow: inset 0 0 0 1px var(--color-divider);
  cursor: pointer;
}
.level-btn:hover { box-shadow: inset 0 0 0 1px var(--color-neutral-400); }
.level-btn.picked {
  color: var(--color-accent-100);
  background: var(--color-accent-800);
  box-shadow: inset 0 0 0 1px var(--color-accent), 0 0 16px color-mix(in srgb, var(--color-accent) 40%, transparent);
}
.level-topic { font-size: 14px; min-height: 22px; margin-bottom: 6px; }

.best { text-align: center; font-size: 13px; }

.how ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- play screen ---------- */

#play-screen { padding: 0; gap: 0; }

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 28px;
}
.title-block { display: flex; flex-direction: column; line-height: 1.3; }
.game-name { font-size: 18px; font-weight: 500; }
.spacer { flex: 1; }

.play-area {
  flex: 1;
  width: 100%;
  max-width: 1024px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 40px;
  align-items: center;
  padding: 20px 48px 36px;
}

.left { display: flex; flex-direction: column; gap: 28px; align-items: flex-start; }

.timer-row { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.timer-ring {
  --pct: 100%;
  width: 84px; height: 84px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--color-accent) 0 var(--pct), var(--color-neutral-700) var(--pct) 100%);
}
.timer-ring.low { background: conic-gradient(var(--oops) 0 var(--pct), var(--color-neutral-700) var(--pct) 100%); }
.timer-inner {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--color-bg);
  display: grid; place-items: center;
  font-size: 22px; font-weight: 500;
}

.question {
  font-size: clamp(56px, 10vw, 110px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.answer-row { display: flex; align-items: center; gap: 14px; }
.ask { font-size: 22px; }
.answer-box {
  min-width: 140px; height: 72px;
  border-radius: 12px;
  display: flex; align-items: center;
  padding: 0 22px;
  font-size: 40px; font-weight: 500;
  box-shadow: inset 0 0 0 2px var(--color-accent), 0 0 24px color-mix(in srgb, var(--color-accent) 30%, transparent);
}
.caret {
  width: 2px; height: 40px;
  margin-left: 4px;
  background: var(--color-accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.answer-box.right { box-shadow: inset 0 0 0 2px var(--good), 0 0 28px color-mix(in srgb, var(--good) 40%, transparent); }
.answer-box.wrong { box-shadow: inset 0 0 0 2px var(--oops); animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.feedback { min-height: 26px; font-size: 16px; }
.feedback.right { color: var(--good); }
.feedback.wrong { color: var(--oops); }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pad-key {
  height: 72px;
  border: none;
  border-radius: var(--radius);
  font: 500 26px var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: inset 0 0 0 1px var(--color-divider);
  cursor: pointer;
  display: grid; place-items: center;
  touch-action: manipulation;
}
.pad-key:hover { background: color-mix(in srgb, var(--color-text) 6%, var(--color-surface)); }
.pad-key:active { transform: scale(0.96); }
.pad-key.go { color: var(--color-accent); background: transparent; box-shadow: inset 0 0 0 1px var(--color-accent); }

/* ---------- results screen ---------- */

.results {
  width: 100%;
  max-width: 400px;
  align-items: stretch;
  text-align: center;
  gap: 16px;
  padding: 32px 24px;
  background: radial-gradient(ellipse 420px 360px at 50% 0%, var(--glow), var(--color-surface) 75%);
  box-shadow: var(--shadow-md);
}
.big-points { font-size: 76px; font-weight: 500; letter-spacing: -0.03em; line-height: 1; margin-top: 8px; }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.dot { width: 18px; height: 6px; border-radius: 3px; background: var(--color-neutral-700); }
.dot.on { background: var(--color-accent); }

.breakdown { background: var(--color-bg); padding: 18px; text-align: left; }
.breakdown .row { display: flex; justify-content: space-between; font-size: 14px; }
.breakdown .total { font-size: 16px; font-weight: 500; }
.divider { height: 1px; background: var(--color-divider); }
.res-message { font-size: 15px; color: var(--color-accent-300); min-height: 22px; }
.saved-note { margin-top: 6px; font-size: 14px; color: var(--good); }
.saved-note.big-win { font-size: 17px; font-weight: 500; color: var(--color-accent-200); }
.warm-up {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: var(--radius); font-size: 14px;
  background: var(--color-bg); box-shadow: inset 0 0 0 1px var(--color-divider);
}
.warm-up span { flex: 1; }
.warm-up .btn { flex: none; }

/* Play again, Change level and Base camp */
.results-actions { display: flex; flex-direction: column; gap: 10px; }
/* the "Base camp" button at the bottom of the results card (same look as the one at the top) */
.results-nav { align-self: center; margin-top: 4px; }

/* "you're not logged in" notes */
.saved-note.not-saved { color: var(--warn); }
.logged-out-note {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border-radius: var(--radius); font-size: 14px;
  background: color-mix(in srgb, var(--warn) 12%, var(--color-surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warn) 55%, transparent);
}
.logged-out-note > .ic { flex: none; width: 22px; height: 22px; color: var(--warn); }
.logged-out-note span { flex: 1; }
.logged-out-note .btn { flex: none; height: 34px; padding: 0 14px; text-decoration: none; }

/* ---------- smooth movement (quick, never slow) ---------- */

@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

body { animation: page-in 0.2s ease-out; }
.screen:not(.hidden) { animation: screen-in 0.22s ease-out; }
.results .big-points { animation: pop-in 0.3s 0.05s ease-out backwards; }
.saved-note, .warm-up, .logged-out-note { animation: fade-up 0.25s ease-out; }
.pause-box[open] { animation: pop-in 0.16s ease-out; }
.pause-box[open]::backdrop { animation: page-in 0.16s ease-out; }
.btn, .tag, .games-nav a { transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s; }

/* People who turn off motion on their device get no movement at all */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, *::backdrop { animation: none !important; transition: none !important; }
}

/* ---------- loading placeholders (gray shapes while we wait for the server) ---------- */

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skel, .is-loading-text {
  border-radius: 6px;
  background: linear-gradient(90deg, var(--skel-a) 25%, var(--skel-b) 50%, var(--skel-a) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.skel { display: block; }
.is-loading-text { color: transparent !important; user-select: none; }
.is-loading-text * { visibility: hidden; }
.skel-line { height: 12px; }
.level-picker.is-loading { pointer-events: none; }
.level-picker.is-loading > * {
  color: transparent !important;
  box-shadow: none !important;
  background: linear-gradient(90deg, var(--skel-a) 25%, var(--skel-b) 50%, var(--skel-a) 75%) !important;
  background-size: 200% 100% !important;
  animation: shimmer 1.3s linear infinite;
}
.skel-circle { border-radius: 50%; }

/* ---------- the light/dark switch ---------- */

.theme-btn .ic { width: 20px; height: 20px; }
.theme-corner { position: fixed; top: 14px; right: 14px; z-index: 10; }
.theme-pill {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 11px; border: none; border-radius: 7px;
  font: inherit; color: var(--color-text); background: transparent; cursor: pointer;
}
.theme-pill:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }

/* ---------- the Paused box ---------- */

.pause-box {
  width: min(380px, calc(100vw - 32px));
  padding: 28px 24px 24px;
  border: none;
  border-radius: 16px;
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  text-align: center;
}
.pause-box::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.pause-box h2 { margin: 0 0 6px; font-size: 26px; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 10px; }
.pause-box h2 .ic { color: var(--color-accent); }
.pause-box p { margin: 0 0 20px; }
.pause-buttons { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Pip the mascot ---------- */

.pip { display: block; height: auto; flex: none; }
.pip-cheering { animation: pip-hop 0.6s ease-out 2; }
@keyframes pip-hop { 50% { transform: translateY(-14px); } }
@media (prefers-reduced-motion: reduce) { .pip-cheering { animation: none; } }
@media (max-width: 600px) { .pip { width: 110px; } }

/* Phones: keep Play again / Change level / Base camp pinned to the bottom of the screen */
@media (max-width: 600px) {
  .results-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 0 -24px -32px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-radius: 0 0 14px 14px;
    background: var(--color-surface);
    box-shadow: 0 -10px 18px -6px var(--sticky-shadow);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .results-actions #again-btn { grid-column: 1 / -1; }
  .results-actions .btn-big { height: 46px; }
  .results-actions .results-nav { grid-column: auto; align-self: stretch; margin: 0; justify-content: center; }
  .results-actions .results-nav a { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; }
}

/* Pip at the top of the results card, for big moments only */
.res-pip { display: flex; justify-content: center; margin: -8px 0 -4px; }
.res-pip:empty { display: none; }

/* ---------- small screens (phones) ---------- */

@media (max-width: 760px) {
  .games-nav a { padding: 6px 9px; font-size: 13px; }
  .title-block { flex: 1; min-width: 0; }
  .title-block .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar { padding: 14px 16px; gap: 8px; flex-wrap: wrap; }
  #streak-tag { order: 5; flex: 1 0 100%; justify-content: center; }
  .play-area { grid-template-columns: 1fr; gap: 20px; padding: 8px 20px 24px; }
  .left { align-items: center; text-align: center; gap: 18px; }
  .pad { max-width: 340px; width: 100%; margin: 0 auto; }
  .pad-key { height: 60px; }
  .level-picker { grid-template-columns: repeat(4, 1fr); }
  .start-card { padding: 24px; }
  .start-card h1 { font-size: 36px; }
}
