/* =========================================================================
   Aqua Crush — "precision arcade"
   Hard edges, ivory and navy, one accent. Every surface is notched at the
   corners like a sprite; nothing on this page is rounded. Motion is stepped
   and mechanical rather than soft, so the interface reads as a machine.
   ========================================================================= */

:root {
  /* Brand */
  --ink: #0a1a2f;
  --ink-soft: #1b2c45;
  --ink-faint: #55637a;
  --paper: #f0f5fb;
  --paper-pure: #ffffff;
  --blue: #1e5bff;
  --blue-deep: #0b3bb0;
  --blue-tint: #d6e2ff;
  --cyan: #38c6e8;
  --bronze: #c89257;
  /* WhatsApp's own brand green, used only on the WhatsApp button where
     people expect to recognise it. Not part of the Aqua palette. */
  --whatsapp: #25d366;
  --whatsapp-deep: #128c3e;

  --edge: 3px;
  --notch: 7px;
  --lift: 5px;

  --font: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo,
    Consolas, "Liberation Mono", monospace;

  --step: cubic-bezier(0.2, 0.9, 0.3, 1);
}

/* Notched corners — the signature. Applied to every raised surface. */
.notch {
  clip-path: polygon(
    0 var(--notch), var(--notch) 0,
    calc(100% - var(--notch)) 0, 100% var(--notch),
    100% calc(100% - var(--notch)), calc(100% - var(--notch)) 100%,
    var(--notch) 100%, 0 calc(100% - var(--notch))
  );
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  /* Dither field: a faint dot grid, so the background has texture without
     resorting to a gradient. */
  background-image: radial-gradient(var(--blue-tint) 1px, transparent 1px);
  background-size: 8px 8px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  /* The board handles its own gestures; stop the page rubber-banding under it. */
  touch-action: manipulation;
}

button, input, textarea { font: inherit; color: inherit; }

/* Keyboard focus.
   One colour cannot serve both grounds: cyan on the ivory page measures
   1.84:1, well under the 3:1 WCAG asks of a focus indicator. So the ring is
   deep blue on the light ground and cyan on the navy surfaces, each chosen
   for contrast against what is actually behind it. */
:focus-visible {
  outline: 3px solid var(--blue-deep);
  outline-offset: 3px;
}
.code-plate :focus-visible,
.gauge :focus-visible {
  outline-color: var(--cyan);
}
button { cursor: pointer; border: none; background: none; }

/* ---------------------------------------------------------------- layout */

.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 14px
           max(14px, env(safe-area-inset-bottom));
}

.screen { display: none; flex: 1; flex-direction: column; }

/* The game screen is a fixed-size cluster rather than a document, so it is
   centred vertically instead of stranded at the top of a tall phone. */
#screen-game[data-active] { justify-content: center; }
.screen[data-active] { display: flex; animation: wipe-in 0.32s var(--step) both; }

/* Screens arrive with a hard wipe, not a fade — arcade, not app. */
@keyframes wipe-in {
  from { opacity: 0; clip-path: inset(0 0 100% 0); }
  to   { opacity: 1; clip-path: inset(0 0 0 0); }
}

/* Children stagger in behind the wipe. */
.stagger > * { animation: rise 0.4s var(--step) both; }
.stagger > *:nth-child(1) { animation-delay: 0.06s; }
.stagger > *:nth-child(2) { animation-delay: 0.12s; }
.stagger > *:nth-child(3) { animation-delay: 0.18s; }
.stagger > *:nth-child(4) { animation-delay: 0.24s; }
.stagger > *:nth-child(5) { animation-delay: 0.30s; }
.stagger > *:nth-child(6) { animation-delay: 0.36s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------ typography */

.eyebrow {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

h1, h2 { font-weight: 700; letter-spacing: -0.02em; line-height: 1.12; }
h1 { font-size: clamp(23px, 6.6vw, 30px); }
h2 { font-size: clamp(19px, 5.4vw, 24px); }

p { line-height: 1.55; font-size: 14px; color: var(--ink-soft); }

.wordmark { display: block; width: 100%; height: auto; image-rendering: pixelated; }

/* --------------------------------------------------------------- surfaces */

.panel {
  background: var(--paper-pure);
  border: var(--edge) solid var(--ink);
  box-shadow: var(--lift) var(--lift) 0 var(--ink);
  padding: 18px;
}

/* The notch and the border cannot coexist on one element — the clip eats the
   border. So notched panels wrap: outer clips, inner draws. */
.plate { padding: var(--edge); background: var(--ink); }
.plate > .plate-face { background: var(--paper-pure); padding: 16px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 15px 18px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  border: var(--edge) solid var(--ink);
  box-shadow: var(--lift) var(--lift) 0 var(--ink);
  text-decoration: none;
  transition: transform 0.08s var(--step), box-shadow 0.08s var(--step),
              background 0.15s;
}

/* Press = the button physically travels into its own shadow. */
.btn:active {
  transform: translate(var(--lift), var(--lift));
  box-shadow: 0 0 0 var(--ink);
}

.btn:disabled { background: var(--ink-faint); cursor: not-allowed; }
.btn--ghost { background: var(--paper-pure); color: var(--ink); }
/* Navy on WhatsApp green, not white — white on this green is about 2.3:1 and
   fails contrast on the single most important button on the page. */
.btn--wa { background: var(--whatsapp); color: var(--ink); }
.btn--sm { min-height: 44px; font-size: 13px; padding: 10px 14px; width: auto; }

/* ------------------------------------------------------- language picker */

.lang-grid { display: grid; gap: 10px; margin-top: 20px; }

.lang {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  background: var(--paper-pure);
  border: var(--edge) solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 700;
  font-size: 16px;
  text-align: left;
  transition: transform 0.1s var(--step), box-shadow 0.1s var(--step),
              background 0.15s;
}
.lang:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.lang__flag { font-size: 24px; line-height: 1; }
.lang__code {
  margin-left: auto;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}
/* The browser's language is pre-highlighted, but never auto-selected. */
.lang[data-suggested] { background: var(--blue-tint); }
.lang[data-suggested] .lang__code { color: var(--blue-deep); }

/* ------------------------------------------------------------- level map */

.levels { display: grid; gap: 12px; margin: 18px 0; }

.level-card {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--paper-pure);
  border: var(--edge) solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  text-align: left;
  width: 100%;
}
.level-card[data-locked] { opacity: 0.42; box-shadow: none; }
.level-card[data-done] { background: var(--blue-tint); }

.level-card__no {
  display: grid;
  place-items: center;
  height: 40px;
  background: var(--ink);
  color: var(--paper-pure);
  font-weight: 700;
  font-size: 17px;
}
.level-card[data-done] .level-card__no { background: var(--blue); }
.level-card__name { font-weight: 700; font-size: 16px; }
.level-card__meta { font-size: 11px; color: var(--ink-faint); letter-spacing: 0.06em; }
.level-card__state { font-size: 18px; }

/* ------------------------------------------------------------------- HUD */

.hud {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 10px;
}

.gauge {
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  min-width: 78px;
}
.gauge__label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.66;
}
.gauge__value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
/* Last five moves: the counter starts pulsing. */
.gauge[data-low] .gauge__value { color: var(--cyan); animation: tick 1s steps(2) infinite; }
@keyframes tick { 50% { opacity: 0.45; } }

.goals { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; align-content: center; }

.goal {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px 5px 5px;
  background: var(--paper-pure);
  border: 2px solid var(--ink);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.goal canvas { image-rendering: pixelated; display: block; }
.goal[data-met] { background: var(--blue); color: #fff; border-color: var(--blue-deep); }
.goal[data-met] .goal__count { text-decoration: line-through; opacity: 0.8; }

/* ----------------------------------------------------------------- board */

.board-frame { background: var(--ink); padding: var(--edge); position: relative; }

#board {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  background: var(--paper-pure);
  touch-action: none; /* the board owns its gestures */
}

/* A very faint scanline wash over the playfield only. */
.board-frame::after {
  content: "";
  position: absolute;
  inset: var(--edge);
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom, rgba(10, 26, 47, 0.05) 0 1px, transparent 1px 3px
  );
  mix-blend-mode: multiply;
}

/* --------------------------------------------------------------- host bar */

.host {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 8px 12px 8px 8px;
  background: var(--paper-pure);
  border: var(--edge) solid var(--ink);
}
.host canvas { image-rendering: pixelated; display: block; flex: none; }
.host__say { font-size: 12px; line-height: 1.4; color: var(--ink-soft); }

/* When Dr Erkan speaks, the line replaces the level goal in the same slot.
   It reads as speech rather than status: darker, heavier, faintly italic. */
.host__say[data-speaking] {
  color: var(--ink);
  font-weight: 700;
  font-style: italic;
  animation: said 0.22s var(--step);
}
@keyframes said {
  from { opacity: 0; transform: translateX(-4px); }
}
.host__name {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}
/* A small hop whenever Dr Erkan reacts. */
.host canvas[data-react] { animation: hop 0.4s steps(4); }
@keyframes hop { 40% { transform: translateY(-7px); } }

.host--big { flex-direction: column; text-align: center; border: none; background: none; }

.host__tools { display: flex; gap: 6px; margin-left: auto; flex: none; }
.host__tools .btn { padding: 10px 12px; box-shadow: 3px 3px 0 var(--ink); }
.host__tools .btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
#btn-sound[aria-pressed="false"] { opacity: 0.45; }

/* First-play hint. Delivered by Dr Erkan in his own speech slot rather than
   floated over the board — an overlay there would cover the bottom row, which
   is exactly where a new player is most likely to try their first swipe. */
.host__say[data-coach]::before {
  content: "\261E";
  display: inline-block;
  margin-right: 7px;
  color: var(--blue);
  animation: coach-nudge 1.4s ease-in-out infinite;
}
@keyframes coach-nudge {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(5px); }
}


/* ------------------------------------------------------------------ form */

.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 6px;
}
.field__input {
  width: 100%;
  padding: 13px 14px;
  background: var(--paper);
  border: var(--edge) solid var(--ink);
  font-size: 16px; /* 16px or iOS zooms the page on focus */
  outline: none;
}
.field__input:focus { background: var(--paper-pure); box-shadow: inset 0 0 0 2px var(--blue); }
textarea.field__input { resize: vertical; min-height: 74px; line-height: 1.45; }
.field__error { display: none; margin-top: 5px; font-size: 12px; color: var(--blue-deep); font-weight: 700; }
.field[data-invalid] .field__input { box-shadow: inset 0 0 0 2px var(--blue-deep); }
.field[data-invalid] .field__error { display: block; }

.phone-row { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
select.field__input { appearance: none; background-image: none; }

.consent {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin: 16px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.consent input {
  appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  background: var(--paper);
  border: var(--edge) solid var(--ink);
  display: grid;
  place-items: center;
}
.consent input:checked { background: var(--blue); }
.consent input:checked::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: rotate(-45deg) translate(1px, -2px);
}
.consent a { color: var(--blue-deep); }

/* ------------------------------------------------------------------ code */

.code-plate {
  background: var(--ink);
  color: var(--paper-pure);
  padding: 20px 16px;
  text-align: center;
  margin: 16px 0;
  position: relative;
  overflow: hidden;
}
/* A slow sheen crossing the code, so it reads as something valuable. */
.code-plate::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 42%, rgba(56, 198, 232, 0.3) 50%, transparent 58%);
  animation: sheen 3.6s linear infinite;
}
@keyframes sheen { from { transform: translateX(-120%); } to { transform: translateX(120%); } }

.code-plate__label {
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  opacity: 0.6;
  position: relative;
}
/* Sized so the full 21-character code fits one line down to a 320px phone.
   A code broken across two lines gets mis-copied and mis-read over the phone,
   so it must never wrap. */
.code-plate__value {
  font-size: clamp(14px, 5.2vw, 22px);
  font-weight: 700;
  letter-spacing: 0.03em;
  margin: 8px 0 13px;
  position: relative;
  white-space: nowrap;
}

.terms {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px dashed var(--ink-faint);
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--ink-faint);
}
.terms strong { display: block; margin-bottom: 4px; letter-spacing: 0.16em; text-transform: uppercase; font-size: 9px; }

/* --------------------------------------------------------------- overlay */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(10, 26, 47, 0.82);
}
.overlay[data-open] { display: flex; animation: fade 0.2s both; }
@keyframes fade { from { opacity: 0; } }

.overlay__card {
  width: 100%;
  max-width: 340px;
  background: var(--paper-pure);
  border: var(--edge) solid var(--ink);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.35);
  padding: 22px;
  text-align: center;
  animation: pop 0.3s var(--step) both;
}
@keyframes pop {
  from { transform: scale(0.9) translateY(14px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* Pixel confetti on the win — squares only, no circles. */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 8px;
  animation: drop linear forwards;
}
@keyframes drop {
  to { transform: translateY(105dvh) rotate(220deg); }
}

/* ---------------------------------------------------------------- footer */

.footer {
  margin-top: auto;
  padding-top: 16px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
}

.link-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-faint);
}

.spacer { flex: 1; min-height: 12px; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }

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

/* Bigger screens get a touch more air, never a wider board. */
@media (min-width: 520px) {
  .app { padding-top: 26px; }
  .lang-grid { grid-template-columns: 1fr 1fr; }
}

/* Short phones: trim the vertical rhythm so the board never gets squeezed. */
@media (max-height: 700px) {
  .host { padding: 6px 10px 6px 6px; }
  .host__say { font-size: 11px; }
  h1 { font-size: 21px; }
}

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