/* ==========================================================================
   Sunshine Arcade — shared styles (tokens, base, buttons, game shell)
   ========================================================================== */

:root {
  --paper: #F3EDE2;
  --paper-deep: #E6DCC8;
  --cream: #FFF9EE;
  --ink: #1C1917;
  --ink-2: #4A4540;
  --ink-3: #8A8178;
  --sun: #FF5A1F;
  --yellow: #FFC933;
  --pink: #FF78AE;
  --blue: #2E5CDB;
  --green: #1BA35B;
  --night: #231F3F;

  --accent: var(--sun);
  --on-accent: var(--ink);

  --font: "Anybody", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "DM Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .11 0 0 0 0 .09 0 0 0 0 .08 0 0 0 .6 -.24'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--paper);
  background-image: var(--grain);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

a { color: inherit; }

h1, h2, h3, p { margin: 0; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

::selection { background: var(--yellow); color: var(--ink); }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 6px; }

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent);
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 800;
  font-size: 18px;
  font-stretch: 112%;
  letter-spacing: -0.01em;
  line-height: 1;
  padding: 14px 22px;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .08s ease, box-shadow .08s ease, background-color .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { cursor: not-allowed; opacity: .45; transform: none; box-shadow: 0 5px 0 var(--ink); }
.btn.ghost { --btn-bg: var(--cream); --btn-fg: var(--ink); }
.btn.big { font-size: 22px; padding: 16px 30px; }
.btn kbd {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 5px;
  border: 1.5px solid currentColor;
  border-radius: 5px;
  opacity: .7;
}

/* ---------- Game shell ---------- */

body.game {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}

.bar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  color: var(--ink);
  border-bottom: 3px solid var(--ink);
}

.back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  font-weight: 800;
  font-size: 15px;
  font-stretch: 110%;
  color: var(--ink);
  text-decoration: none;
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.back:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.back:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.back svg { width: 26px; height: 26px; flex: none; transition: transform .45s cubic-bezier(.3, 1.8, .5, 1); }
.back:hover svg { transform: rotate(-14deg) scale(1.12); }
.back .back-moon { display: none; }
:root[data-theme="moon"] .back .back-sun { display: none; }
:root[data-theme="moon"] .back .back-moon { display: block; }

.bar-title {
  font-size: clamp(20px, 3.2vw, 32px);
  font-weight: 900;
  font-stretch: 130%;
  letter-spacing: -0.03em;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.bar-tools {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  white-space: nowrap;
}
.chip b { font-family: var(--font); font-size: 16px; font-weight: 900; letter-spacing: 0; text-transform: none; }

.icon-btn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--ink);
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .off { display: none; }
.icon-btn.is-muted .on { display: none; }
.icon-btn.is-muted .off { display: block; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--stage, var(--paper));
  background-image: var(--grain);
}
.stage > canvas { position: absolute; inset: 0; display: block; }

/* HUD: small readouts floating over the play area */
.hud {
  position: absolute;
  z-index: 2;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}
.hud-group { display: flex; gap: 8px; flex-wrap: wrap; }
.hud-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 64px;
  padding: 7px 12px 8px;
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
}
.hud-item small {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
}
.hud-item b {
  font-size: 22px;
  font-weight: 900;
  font-stretch: 115%;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hud-item.bump b { animation: bump .35s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.3); } 100% { transform: scale(1); } }

.hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 8px 14px;
  color: var(--cream);
  background: var(--ink);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  animation: hint-bob 1.6s ease-in-out infinite;
}
@keyframes hint-bob { 50% { transform: translate(-50%, -5px); } }

/* ---------- Panels (intro / results) ---------- */

.panel {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  background: color-mix(in srgb, var(--stage, var(--paper)) 72%, transparent);
  touch-action: auto;
}
.panel:not([hidden]) .sheet { animation: sheet-in .45s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes sheet-in { from { transform: translateY(24px) scale(.96); opacity: 0; } }

.sheet {
  width: min(480px, 100%);
  padding: 30px 28px 28px;
  text-align: center;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--ink);
}
.sheet .kicker {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  padding: 5px 10px;
  margin-bottom: 14px;
  color: var(--on-accent);
  background: var(--accent);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.sheet h2 {
  font-size: clamp(38px, 9vw, 54px);
  font-weight: 900;
  font-stretch: 135%;
  letter-spacing: -0.04em;
  line-height: .92;
}
.sheet .lead { margin-top: 12px; font-size: 18px; color: var(--ink-2); }
.rules {
  list-style: none;
  counter-reset: rule;
  margin: 22px 0 0;
  padding: 0;
  text-align: left;
  display: grid;
  gap: 10px;
}
.rules li {
  counter-increment: rule;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 16px;
  line-height: 1.35;
}
.rules li::before {
  content: counter(rule);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  font-size: 14px;
  font-weight: 900;
  color: var(--on-accent);
  background: var(--accent);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.sheet .actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 26px;
}
.sheet .keys {
  margin-top: 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
}

.score-big {
  margin-top: 10px;
  font-size: clamp(60px, 17vw, 100px);
  font-weight: 900;
  font-stretch: 125%;
  letter-spacing: -0.05em;
  line-height: .9;
  font-variant-numeric: tabular-nums;
}
.score-big small { font-size: .32em; letter-spacing: 0; color: var(--ink-3); }
.score-note { margin-top: 8px; font-size: 17px; font-weight: 700; }
.new-best {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 12px;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 999px;
  transform: rotate(-3deg);
  animation: wiggle 1.2s ease-in-out infinite;
}
@keyframes wiggle { 50% { transform: rotate(3deg) scale(1.05); } }

.breakdown {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  border-top: 2px dashed var(--ink-3);
  text-align: left;
}
.breakdown li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 2px dashed var(--paper-deep);
  font-size: 15px;
}
.breakdown li span:first-child { color: var(--ink-2); }
.breakdown li b { font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- Verdict card (between turns) ---------- */

.verdict {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 12px 12px 12px 20px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink);
  transform: translateX(-50%);
  touch-action: manipulation;
}
.verdict:not([hidden]) { animation: verdict-in .4s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes verdict-in { from { transform: translate(-50%, 30px); opacity: 0; } }
.verdict .pts {
  font-size: 46px;
  font-weight: 900;
  font-stretch: 125%;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.verdict .words { display: grid; gap: 3px; }
.verdict .label { font-size: 19px; font-weight: 900; font-stretch: 110%; line-height: 1.1; }
.verdict .sub { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 24px;
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--cream);
  background: var(--ink);
  border-radius: 999px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s, opacity .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

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

@media (max-width: 640px) {
  .bar { grid-template-columns: auto 1fr auto; gap: 8px; padding-left: 10px; padding-right: 10px; }
  .back span { display: none; }
  .back { padding: 4px; }
  .bar-title { font-size: 20px; font-stretch: 115%; }
  .chip { padding: 7px 9px; }
  .chip .chip-label { display: none; }
  .hud { top: 10px; left: 10px; right: 10px; }
  .hud-item { min-width: 0; padding: 5px 9px 6px; }
  .hud-item b { font-size: 18px; }
  .sheet { padding: 24px 20px 22px; }
  .verdict {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 14px;
    width: calc(100% - 24px);
    padding: 12px;
  }
  .verdict .pts { font-size: 38px; padding-left: 4px; }
  .verdict .label { font-size: 17px; }
  .verdict .btn { grid-column: 1 / -1; width: 100%; padding: 13px 14px; font-size: 17px; }
}

@media (pointer: coarse) {
  .btn kbd { display: none; }
}

/* ---------- Moonlight theme (picked by the coin on the home page) ---------- */

:root[data-theme="moon"] {
  --paper: #17152E;
  --paper-deep: #2A2650;
  color-scheme: dark;
}
:root[data-theme="moon"] .bar { color: var(--cream); }
:root[data-theme="moon"] :focus-visible { outline-color: var(--cream); }

/* The theme swap is revealed as a growing circle (see home.js). */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

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