@font-face {
  font-family: "Wintyr VF";
  src: url("fonts/Wintyr.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --accent: #FFD445;          /* ColorTheme.yellow */
  --bg: var(--accent);        /* backgroundColor (light) */
  --fg: #000;                 /* primaryColor (light) */
  --key-bg: #000;
  --key-fg: var(--accent);
  --special-key-bg: #fff;     /* quit / delete keys */
  --hex-fill: #fff;
  --hex-stroke: none;
  --hex-letter: #000;
  --k: 1.1;                   /* grid scale, set from JS */
  --font: "Wintyr VF", ui-sans-serif, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --fg: var(--accent);
    --special-key-bg: var(--accent);
    --hex-fill: #000;
    --hex-stroke: #fff;
    --hex-letter: var(--accent);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-feature-settings: "case" 1;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button, a.pill {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

[hidden] { display: none !important; }

/* ---------- App shell ---------- */

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  -webkit-user-select: none;
  user-select: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding-top: 12px;
  height: 52px;
  flex: none;
}

.wordmark {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--fg);
  background: transparent;
  color: var(--fg);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  padding: 0;
}

.play {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* ---------- Grid ---------- */

.grid {
  display: flex;
  flex-direction: column;
  gap: calc(11px * var(--k));
  padding: calc(8px * var(--k)) 0;
}

.grid.final { gap: calc(2px * var(--k)); margin-bottom: 20px; }

.row {
  display: flex;
  gap: calc(2px * var(--k));
}

.row.shake { animation: shake 0.5s linear; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  12.5%, 37.5%, 62.5%, 87.5% { transform: translateX(15px); }
  25%, 50%, 75% { transform: translateX(0); }
}

.cell {
  position: relative;
  width: calc(38px * var(--k));
  height: calc(58px * var(--k));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.cell.fixed, .grid.complete .cell { cursor: default; }

.cell .hex {
  position: absolute;
  left: 50%;
  top: 50%;
  height: calc(72px * var(--k));
  transform: translate(-50%, -50%);
  overflow: visible;
}

.cell .hex path {
  fill: var(--hex-fill);
  stroke: var(--hex-stroke);
  stroke-width: 1.4;
}

.cell .ch {
  position: relative;
  font-size: calc(60px * var(--k));
  font-weight: 500;
  line-height: 1;
  transform: translateY(calc(-3px * var(--k)));
  transition: transform 0.25s cubic-bezier(.3, 1.6, .5, 1);
}

.cell.empty .ch { transform: translateY(calc(-3px * var(--k))) scale(0.8); }
.cell.fixed .ch { color: var(--hex-letter); }

.cell .cursor {
  position: absolute;
  left: 50%;
  bottom: calc(5px * var(--k));
  width: calc(25px * var(--k));
  height: calc(4px * var(--k));
  transform: translateX(-50%);
  background: var(--fg);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ---------- Finish celebration ---------- */

.grid-wrap { position: relative; }

/* Letters hop in a diagonal wave (r + c), echoing the puzzle's diagonal. */
.grid.celebrate .cell .ch {
  animation: hop 0.55s cubic-bezier(.3, 1.5, .5, 1) both;
  animation-delay: calc(var(--i) * 55ms);
}

@keyframes hop {
  0%   { translate: 0 0; scale: 1; }
  40%  { translate: 0 calc(-16px * var(--k)); scale: 1.18; }
  100% { translate: 0 0; scale: 1; }
}

/* Reduced motion: a soft fade wave instead of movement. */
.grid.celebrate-calm .cell .ch {
  animation: pulse 0.9s ease both;
  animation-delay: calc(var(--i) * 70ms);
}

@keyframes pulse { 50% { opacity: 0.3; } }

.banner {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  background: var(--fg);
  color: var(--bg);
  border-radius: 60px;
  padding: 14px 28px 14px 22px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 3px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  animation: stamp 0.5s cubic-bezier(.3, 1.6, .5, 1) 0.45s both;
  z-index: 6; /* above the confetti canvas */
}

.banner #bannerEmoji { font-size: 36px; letter-spacing: 0; }

@keyframes stamp {
  from { opacity: 0; scale: 0.5; rotate: -8deg; }
  to   { opacity: 1; scale: 1; rotate: -3deg; }
}

.banner.calm { animation: fadein 0.4s ease 0.3s both; rotate: -3deg; }
@keyframes fadein { from { opacity: 0; } }

.banner.out { opacity: 0; transition: opacity 0.25s; }

/* ---------- Status bar ---------- */

.status {
  width: calc(238px * var(--k));
  max-width: 100%;
  min-width: 262px;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin: clamp(16px, 4dvh, 40px) 0 20px;
  flex: none;
}

.status b { font-weight: 600; }

/* ---------- Keyboard ---------- */

.bottom { flex: none; width: 100%; display: flex; justify-content: center; }

.keyboard {
  --gap: 4px;
  --kw: min(36px, calc((100vw - 32px - 9 * var(--gap)) / 10));
  --kh: clamp(42px, 7dvh, 56px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 12px;
}

.krow { display: flex; gap: var(--gap); }

.key {
  width: var(--kw);
  height: var(--kh);
  border-radius: 6px;
  border: 1px solid var(--fg);
  background: var(--key-bg);
  color: var(--key-fg);
  font-size: 20px;
  font-weight: 400;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, opacity 0.3s;
}

.key:active { transform: scale(0.95); }
.key:disabled { opacity: 0.33; cursor: default; }

.key.special {
  width: calc(var(--kw) * 1.55);
  background: var(--special-key-bg);
  border: none;
  color: #000;
}

.key.special svg { display: block; }

/* ---------- Post-game actions ---------- */

.done-actions {
  width: min(300px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
}

.pill {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 1px;
  padding: 14px 20px;
  border-radius: 40px;
  border: none;
  transition: transform 0.12s;
}

.pill:active { transform: scale(0.95); }
.pill-solid { background: var(--fg); color: var(--bg); }
.pill-outline { background: transparent; color: var(--fg); box-shadow: inset 0 0 0 3px var(--fg); }
.pill-white { background: #fff; color: #000; font-size: 16px; font-weight: 400; }
/* White so the black Pro card below is the boldest thing on the finished board */
.summary-btn { background: #fff; color: #000; }
.pill-black { background: #000; color: #fff; font-weight: 400; letter-spacing: 2px; max-width: 280px; }

/* App / Pro upsell under the finished board (mirrors the iOS general paywall) */
.pro-card {
  margin-top: 8px;
  background: #000;
  color: #fff;
  border-radius: 20px;
  box-shadow: inset 0 0 0 1px var(--fg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pro-badge { display: block; color: #fff; }

.pro-card p {
  margin: 0;
  font: 12px/1.4 -apple-system, system-ui, sans-serif;
}

.store-row { display: flex; gap: 8px; }

.store-btn {
  flex: 1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  background: var(--accent);
  color: #000;
  border-radius: 40px;
  padding: 11px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: transform 0.12s;
  touch-action: manipulation;
}

.store-btn:active { transform: scale(0.95); }

.next {
  margin: 0;
  text-align: center;
  font-size: 13px;
  opacity: 0.7;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  animation: pop 0.15s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* Results */

.results {
  background: var(--bg);
  overflow-y: auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.results-inner {
  max-width: 440px;
  min-height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
}

.results-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 40px 0 20px;
  border-bottom: 1px solid var(--fg);
}

.label {
  font-size: 14px;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 6px;
}

.res-time { padding-top: 22px; }

.big-time {
  font-size: min(125px, 30vw);
  font-weight: 400;
  letter-spacing: -4px;
  line-height: 1;
  margin-top: 0;
}

.res-row {
  display: flex;
  align-items: flex-start;
  padding-top: 16px;
}

.res-score, .res-breakdown { flex: 1; min-width: 0; }
.res-breakdown { padding-left: 16px; }

.big-score {
  font-size: min(104px, 25vw);
  font-weight: 500;
  letter-spacing: -4px;
  line-height: 1;
  margin-top: 4px;
}

.info-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--fg);
  background: transparent;
  color: var(--fg);
  opacity: 0.4;
  font: 600 11px ui-serif, Georgia, serif;
  padding: 0;
  margin-left: 4px;
}

.res-breakdown ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.res-breakdown li {
  display: flex;
  gap: 10px;
  font-size: 18px;
  padding: 1px 0;
}

.res-breakdown li b { font-weight: 600; }

.res-pattern { padding-top: 16px; padding-bottom: 24px; }

.res-pattern p {
  margin: 8px 0 0;
  font: 15px/1.35 -apple-system, system-ui, sans-serif;
}

.res-actions {
  margin-top: auto;
  padding-bottom: 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.res-actions .pill { font-size: 18px; letter-spacing: 2px; }
.res-actions .pill-outline { box-shadow: inset 0 0 0 2px var(--fg); }

.res-actions-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.close-circle {
  flex: none;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #000;
  font-size: 20px;
  font-weight: 700;
  padding: 0;
}

#shareBtn { flex: 1; min-width: 0; white-space: nowrap; }

/* Dark info cards (scoring, how to play) */

.dark-card {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.card {
  max-width: 420px;
  width: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  color: #fff;
}

.card-label {
  font-size: 12px;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: -12px;
}

.card p {
  margin: 0;
  font: 16px/1.6 -apple-system, system-ui, sans-serif;
}

.card p.muted { color: rgba(255, 255, 255, 0.6); }

.card-buttons { display: flex; flex-direction: column; gap: 12px; }
.card-buttons .close-circle { align-self: center; }
.card-buttons [hidden] { display: none; }
.pill-ghost { background: transparent; color: #fff; box-shadow: inset 0 0 0 2px #fff; font-size: 16px; font-weight: 400; }

/* Onboarding slides */

.onboard {
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 56px) 0 calc(env(safe-area-inset-bottom) + 40px);
  gap: 32px;
  z-index: 30;
}

.skip {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 18px);
  right: 16px;
  background: none;
  border: none;
  color: var(--fg);
  font-size: 14px;
  letter-spacing: 1px;
  opacity: 0.6;
  padding: 8px;
}

.ob-viewport {
  flex: 1;
  width: 100%;
  max-width: 440px;
  overflow: hidden;
  min-height: 0;
  touch-action: pan-y;
}

.ob-track {
  display: flex;
  height: 100%;
  transition: transform 0.3s ease-out;
}

.ob-page {
  flex: 0 0 100%;
  height: 100%;
  padding: 0 40px;
  overflow-y: auto;
}

.ob-page h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 7.2px;
  margin: 0 0 40px;
}

.ob-page p, .ob-page li {
  font: 15px/1.45 -apple-system, system-ui, sans-serif;
  margin: 0 0 28px;
}

.ob-page ul { list-style: none; padding: 0; margin: 0; }
.ob-page li { margin-bottom: 16px; }

.ob-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ob-lottie { width: 100%; height: min(280px, 38dvh); }
.ob-intro p { margin-top: min(100px, 8dvh); }

.howto-img { max-width: 100%; height: auto; display: block; }
.howto-img .ink { fill: var(--fg); }
.howto-img .paper { fill: var(--hex-fill); stroke: var(--hex-stroke); stroke-width: 1.4; }

.ob-dots { display: flex; gap: 8px; }
.ob-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--fg); opacity: 0.2; }
.ob-dots i.on { opacity: 1; }

.ob-next { max-width: 280px; font-size: 18px; letter-spacing: 2px; }

/* Practice complete */

.closing {
  background: #000;
  color: var(--accent);
  display: flex;
  z-index: 30;
}

.closing-inner {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 0 30px calc(env(safe-area-inset-bottom) + 50px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.closing h2 { font-size: 28px; font-weight: 700; letter-spacing: 4px; margin: auto 0 24px; }
.closing p { font: 16px/1.5 -apple-system, system-ui, sans-serif; margin: 0 0 auto; }
.closing-btn { background: var(--accent); color: #000; font-size: 18px; letter-spacing: 2px; padding: 16px; }

/* Home (returning players, daily not finished yet) */

.home {
  background: var(--bg);
  color: var(--fg);
  display: flex;
  justify-content: center;
}

.home-inner {
  width: 262px;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(env(safe-area-inset-bottom) + 40px);
}

.home-date {
  margin: auto 0 clamp(48px, 20dvh, 180px);
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px;
}

#homePlay { margin-bottom: clamp(48px, 20dvh, 180px); }

.home-logo {
  text-align: center;
  font-size: 64px;
  font-weight: 600;
  letter-spacing: 7px;
  margin-right: -7px; /* letter-spacing trails the last letter; keep it optically centered */
  line-height: 1;
  margin-bottom: 16px;
}

.home-info { font-size: 16px; letter-spacing: 2px; }

/* Pro teaser over the summary (mirrors the iOS general paywall) */

.tease {
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  animation: fadein 0.25s ease;
}

.tease-sheet {
  position: relative;
  width: min(420px, 100%);
  height: min(760px, 100%);
  border-radius: 28px;
  overflow: hidden;
  background: #000 url("img/upsell.jpg") center / cover no-repeat;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 28px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.45s cubic-bezier(.2, .9, .3, 1.1) both;
}

/* Keeps the buttons legible where they cross the screenshots. */
.tease-sheet::before {
  content: "";
  position: absolute;
  inset: 45% 0 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85) 70%);
  pointer-events: none;
}

@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

.tease-copy, .tease-actions { position: relative; }

.tease-copy { width: 46%; margin-bottom: 40px; }
.tease-badge { display: block; color: #fff; margin-bottom: 16px; }

.tease h2 {
  margin: 0 0 16px;
  color: var(--accent);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 1px;
}

.tease p { margin: 0; font: 13px/1.45 -apple-system, system-ui, sans-serif; }

.tease-store { display: flex; gap: 10px; }

.tease-btn {
  flex: 1;
  width: auto;
  background: var(--accent);
  color: #000;
  font-size: 15px;
  font-weight: 600;
  padding: 15px 6px;
  white-space: nowrap;
}

.tease-later {
  display: block;
  margin: 20px auto 0;
  background: none;
  border: none;
  color: #fff;
  font: 14px -apple-system, system-ui, sans-serif;
  text-decoration: underline;
  padding: 4px 8px;
}

/* Give up */

.quit {
  background: #fff;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quit-inner {
  width: 100%;
  padding: 0 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.quit-inner p { font-size: 20px; margin: 0 0 16px; }

/* Confetti + loading */

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  z-index: 50;
}

@media (prefers-reduced-motion: reduce) {
  .overlay, .row.shake, .tease-sheet { animation: none; }
  .cell .ch { transition: none; }
}
