/* Self-hosted fonts (Latin subset, variable weight). Same files Google Fonts
   serves, minus the extra round trips to two other origins. */
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('assets/fonts/fredoka-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url('assets/fonts/nunito-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #23303a;
  --ink-soft: #5d6b74;
  --paper: #fffaf0;
  --paper-edge: #e3d3b4;
  --sea: #1d6a8a;
  --sea-dark: #124a62;
  --sand: #efdcb2;
  --perfect: #2e8b57;
  --close: #b8930a;
  --meh: #d9731a;
  --wild: #c0392b;
  --caught: #1d6a8a;
  /* Paper grain, generated; a ui_paper PNG replaces it when present */
  --paper-img: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45 0 0 0 0 .35 0 0 0 0 .2 0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --lift: 0 1px 0 rgba(60, 40, 10, 0.05), 2px 3px 0 rgba(60, 40, 10, 0.07), 3px 7px 14px rgba(60, 40, 10, 0.2);
  --lift-sm: 1px 2px 0 rgba(60, 40, 10, 0.08), 2px 4px 8px rgba(60, 40, 10, 0.16);
  --display: 'Fredoka', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* Shown only until the canvas paints */
  background: linear-gradient(#7cbfdf, #e6f4ef 55%, var(--sand) 55%);
  color: var(--ink);
  font: 16px/1.4 'Nunito', ui-rounded, 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* The scene is the whole screen; the UI floats on top of it */
.scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.paper {
  background: var(--paper) var(--paper-img);
  box-shadow: var(--lift);
  border-radius: 4px;
}

.muted {
  color: var(--ink-soft);
  margin: 0;
  text-align: center;
}

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 4px;
}
.tag {
  background: var(--paper) var(--paper-img);
  box-shadow: var(--lift-sm);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--display);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
  transform: rotate(-1.5deg);
}
.pips {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 5px;
}
.pip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 250, 240, 0.75);
  box-shadow: inset 0 0 0 2px rgba(35, 48, 58, 0.18);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  transition: transform 0.2s;
}
.pip.current {
  box-shadow: inset 0 0 0 2px var(--ink);
  transform: scale(1.2);
}
.pip[class*='tier-'] {
  background: var(--c);
  box-shadow: var(--lift-sm);
}
.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--paper) var(--paper-img);
  box-shadow: var(--lift-sm);
  font-size: 18px;
  display: grid;
  place-items: center;
}

/* ---------- Stage: transparent window onto the scene ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 170px;
}
.stage-title {
  position: absolute;
  inset: 4% 0 auto;
  text-align: center;
  pointer-events: none;
  display: none;
}
#app[data-screen='start'] .stage-title,
#app[data-screen='loading'] .stage-title {
  display: block;
}
.logo {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(30px, 11.5vw, 76px); /* "GUESSUNAMI" is ~7em wide: fits a 320px phone */
  letter-spacing: 0.08em;
  line-height: 1;
  color: #fff;
  text-shadow:
    3px 3px 0 var(--sea),
    6px 6px 0 var(--sea-dark),
    8px 12px 14px rgba(20, 40, 60, 0.3);
  transform: rotate(-3deg);
  animation: bob 3.2s ease-in-out infinite;
}
.logo img {
  max-width: 90%;
  height: clamp(70px, 20vw, 110px);
}
.tagline {
  margin: 10px 0 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  color: var(--sea-dark);
}
@keyframes bob {
  50% {
    transform: rotate(-2deg) translateY(-5px);
  }
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.countdown span {
  font-family: var(--display);
  font-weight: 700;
  font-size: 128px;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 4px 6px 0 rgba(35, 48, 58, 0.35);
  animation: pop 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes pop {
  from {
    transform: scale(2) rotate(-12deg);
    opacity: 0;
  }
  25% {
    opacity: 1;
  }
  to {
    transform: scale(1) rotate(-4deg);
  }
}

.reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 5%;
  gap: 8px;
  pointer-events: none;
}
.stamp {
  --c: var(--ink);
  font-family: var(--display);
  font-size: clamp(26px, 8vw, 38px);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--c);
  border: 4px solid var(--c);
  outline: 2px solid var(--c);
  outline-offset: 3px;
  border-radius: 10px;
  padding: 0 16px;
  background: rgba(255, 250, 240, 0.9) var(--paper-img);
  transform: rotate(-8deg);
  animation: stamp-in 0.24s cubic-bezier(0.2, 1.6, 0.4, 1) both;
  box-shadow: var(--lift);
}
.stamp img {
  display: block;
  height: 64px;
}
.stamp:has(img) {
  border: 0;
  outline: 0;
  padding: 0;
  background: none;
  box-shadow: none;
}
.reveal-text {
  background: var(--paper) var(--paper-img);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 15px;
  font-weight: 700;
  box-shadow: var(--lift-sm);
  max-width: 94%;
  text-align: center;
  animation: fade-up 0.25s 0.1s both;
}
@keyframes stamp-in {
  from {
    transform: rotate(-20deg) scale(2.4);
    opacity: 0;
  }
  to {
    transform: rotate(-8deg) scale(1);
    opacity: 1;
  }
}
@keyframes fade-up {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
}

.tier-perfect { --c: var(--perfect); }
.tier-close { --c: var(--close); }
.tier-meh { --c: var(--meh); }
.tier-wild { --c: var(--wild); }
.tier-caught { --c: var(--caught); }

/* ---------- Panels ---------- */
.panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 16px;
}
.loading {
  align-items: center;
  font-weight: 700;
  color: var(--ink-soft);
  padding-bottom: 40px;
}

.big-btn {
  min-height: 58px;
  border: 0;
  border-radius: 12px;
  background: var(--sea);
  color: #fff;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 5px 0 var(--sea-dark), 0 8px 16px rgba(18, 74, 98, 0.35);
  transition: transform 0.06s, box-shadow 0.06s;
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--sea-dark), 0 2px 6px rgba(18, 74, 98, 0.3);
}
.big-btn.secondary {
  background: var(--paper) var(--paper-img);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--paper-edge), 0 8px 14px rgba(60, 40, 10, 0.2);
}

/* Start */
.theme {
  align-self: center;
  margin: 0;
  background: var(--sea);
  color: #fff;
  font-family: var(--display);
  font-weight: 600;
  font-size: 17px;
  padding: 4px 18px;
  border-radius: 3px;
  box-shadow: var(--lift-sm);
  transform: rotate(-1deg);
}
.theme:empty {
  display: none;
}
.howto {
  padding: 12px 16px;
  transform: rotate(0.5deg);
}
.howto summary {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.howto summary::-webkit-details-marker {
  display: none;
}
.howto summary::after {
  content: '+';
  font-size: 22px;
  color: var(--ink-soft);
}
.howto[open] summary::after {
  content: '–';
}
.howto ul {
  margin: 8px 0 2px;
  padding-left: 20px;
}
.howto li {
  margin: 5px 0;
}
.howto li::marker {
  color: var(--sea);
}

/* Play */
.play {
  gap: 12px;
}
.card {
  position: relative;
  padding: 18px 18px 14px;
  transform: rotate(var(--tilt, 0deg));
  min-height: 124px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
/* Strip of tape holding the card down */
.card::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  width: 84px;
  height: 22px;
  margin-left: -42px;
  background: rgba(242, 226, 170, 0.75);
  box-shadow: 0 1px 2px rgba(60, 40, 10, 0.15);
  transform: rotate(-3deg);
}
.card.enter {
  animation: card-in 0.2s ease-out;
}
.card.done .prompt,
.card.done .answer-line {
  opacity: 0.45;
}
@keyframes card-in {
  from {
    transform: translateX(40px) rotate(5deg);
    opacity: 0;
  }
}
.prompt {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(20px, 5.6vw, 25px);
  font-weight: 600;
  line-height: 1.2;
}
.answer-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}
.display {
  min-width: 62%;
  text-align: center;
  font-family: var(--display);
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--sea-dark);
  border-bottom: 3px dashed rgba(35, 48, 58, 0.3);
  padding: 0 8px;
  line-height: 1.25;
}
.unit {
  color: var(--ink-soft);
  font-weight: 800;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 9px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.keypad button {
  min-height: clamp(48px, 7dvh, 60px);
  border: 0;
  border-radius: 10px;
  background: var(--paper) var(--paper-img);
  font-family: var(--display);
  font-size: 26px;
  font-weight: 600;
  box-shadow: 0 4px 0 var(--paper-edge), 0 6px 10px rgba(60, 40, 10, 0.18);
  transition: transform 0.05s, box-shadow 0.05s;
}
.keypad button.small {
  font-size: 21px;
}
.keypad button:nth-child(3n + 1) {
  rotate: -0.6deg;
}
.keypad button:nth-child(3n) {
  rotate: 0.5deg;
}
.keypad button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--paper-edge), 0 2px 4px rgba(60, 40, 10, 0.18);
}
.keypad .go {
  grid-column: 1 / -1;
  background: var(--sea);
  color: #fff;
  font-size: 24px;
  letter-spacing: 0.06em;
  box-shadow: 0 5px 0 var(--sea-dark), 0 8px 14px rgba(18, 74, 98, 0.3);
}
.keypad .go:active {
  box-shadow: 0 1px 0 var(--sea-dark), 0 2px 6px rgba(18, 74, 98, 0.3);
}
.keypad .go:disabled {
  background: #8fa9b4;
  box-shadow: 0 5px 0 #6f8a96;
  cursor: default;
  transform: none;
}
/* Stay opaque so the scene (and water) never shows through the keys */
.keypad.disabled button:not(.go) {
  color: rgba(35, 48, 58, 0.35);
}

/* Result */
#app[data-screen='result'] .stage {
  flex: 0 0 clamp(150px, 30dvh, 280px);
}
.result {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-top: 4px;
  overscroll-behavior: contain;
  /* Still scrolls (touch, wheel, keyboard); just no visible scrollbar */
  scrollbar-width: none;
}
.result::-webkit-scrollbar {
  display: none;
}
.sheet {
  padding: 18px 16px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.result-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.1;
}
.result-sub {
  margin: -4px 0 0;
  color: var(--ink-soft);
  font-weight: 700;
}
.result-grid {
  font-size: 26px;
  letter-spacing: 3px;
}
.next {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.next:empty {
  display: none;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stats > div {
  background: var(--paper) var(--paper-img);
  box-shadow: var(--lift-sm);
  border-radius: 4px;
  text-align: center;
  padding: 8px 4px;
}
.stats > div:nth-child(odd) {
  rotate: -1deg;
}
.stats > div:nth-child(even) {
  rotate: 0.8deg;
}
.stats b {
  display: block;
  font-family: var(--display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}
.stats span {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}
.stats p {
  grid-column: 1 / -1;
  margin: 0;
  background: var(--paper);
  border-radius: 999px;
  padding: 4px 12px;
  justify-self: center;
  box-shadow: var(--lift-sm);
}
.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-list li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--paper) var(--paper-img);
  box-shadow: var(--lift-sm);
  border-radius: 4px;
  border-left: 6px solid var(--c);
}
.badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
}
.row-q {
  margin: 0;
  font-weight: 800;
  line-height: 1.2;
}
.row-a {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
}
.row-a b {
  color: var(--ink);
}
.chip {
  color: var(--c);
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: var(--lift);
  z-index: 2;
}

/* ---------- Screen transitions ---------- */
/* Start screen drops away; the next panel rises in as the camera reframes */
#app.leaving .stage-title,
#app.leaving .panel.start {
  animation: leave 0.22s ease-in forwards;
}
#app[data-screen='play'] .panel.play,
#app[data-screen='result'] .panel.result {
  animation: rise 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes leave {
  to {
    opacity: 0;
    transform: translateY(28px);
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(45%);
  }
}

/* Narrow phones: smaller pips leave room for the puzzle tag */
@media (max-width: 400px) {
  .top {
    gap: 8px;
  }
  .pips {
    gap: 3px;
  }
  .pip {
    width: 12px;
    height: 12px;
    font-size: 8px;
  }
}

/* Short phones: tighten the play screen so the stage keeps some room */
@media (max-height: 700px) {
  .card {
    min-height: 104px;
    padding: 14px 16px 10px;
  }
  .display {
    font-size: 28px;
  }
  .keypad {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .logo {
    animation: none;
  }
  .stamp,
  .countdown span,
  .card.enter,
  .reveal-text,
  #app[data-screen='play'] .panel.play,
  #app[data-screen='result'] .panel.result {
    animation: fade-in 0.25s both;
  }
  #app.leaving .stage-title,
  #app.leaving .panel.start {
    animation: fade-out 0.2s forwards;
  }
  @keyframes fade-in {
    from {
      opacity: 0;
    }
  }
  @keyframes fade-out {
    to {
      opacity: 0;
    }
  }
}
