:root {
  color-scheme: light;
  --ink: #4a3540;
  --muted: #9c7f88;
  --bg: #fff8f7;
  --panel: #fffdfb;
  --board: #fff0f1;
  --line: rgba(104, 67, 80, 0.13);
  --accent: #d86b88;
  --accent-soft: #efb5c4;
  --accent-deep: #f1d5dc;
  --coral: #d62839;
  --warning: #d62839;
  --warning-deep: #b31328;
  --amber: #d99b5f;
  --shadow: 0 12px 30px rgba(116, 67, 82, 0.16);
  --safe-top: max(14px, env(safe-area-inset-top));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

.app-shell {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 12% 42%, rgba(216, 107, 136, 0.08), transparent 28%),
    radial-gradient(circle at 88% 66%, rgba(217, 155, 95, 0.06), transparent 24%),
    var(--bg);
}

.app-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 140 140' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.13'/%3E%3C/svg%3E");
}

.topbar {
  min-height: 68px;
  padding: var(--safe-top) clamp(16px, 3vw, 42px) 12px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid rgba(104, 67, 80, 0.1);
}

.mini-brand {
  width: max-content;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  font-size: 10px;
  font-weight: 850;
  line-height: 0.94;
  letter-spacing: 0.21em;
}

.mini-brand strong {
  color: var(--accent);
  font-size: 17px;
  letter-spacing: 0.04em;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: clamp(24px, 5vw, 70px);
}

.stat {
  min-width: 62px;
  text-align: center;
}

.stat__label {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.stat__value {
  display: block;
  color: var(--ink);
  font-size: clamp(17px, 2vw, 22px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transform-origin: center;
}

.stat--combo .stat__value {
  color: var(--accent);
}

.stat__value.bump,
.stat--combo.bump {
  animation: stat-bump 350ms cubic-bezier(.2, 1.6, .45, 1);
}

.topbar__actions {
  justify-self: end;
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(104, 67, 80, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
  transition: 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: rgba(104, 67, 80, 0.25);
  outline: none;
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cute-icon {
  fill: currentColor;
  stroke: none;
}

.cute-icon--pause {
  color: var(--accent);
}

.cute-icon--pause circle {
  fill: #fff8f7;
}

.sound-off,
body.is-muted .sound-on {
  display: none;
}

body.is-muted .sound-off {
  display: block;
}

.game-layout {
  position: relative;
  min-height: 0;
  padding: clamp(12px, 2.2vh, 24px) clamp(14px, 3vw, 34px) var(--safe-bottom);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  gap: clamp(9px, 1.5vh, 16px);
}

.target-panel {
  width: min(94vw, 660px);
  text-align: center;
}

.target-panel__eyebrow {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 13px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.22em;
}

.round-meta::before {
  content: "";
  width: 3px;
  height: 3px;
  margin: 0 10px 2px 0;
  display: inline-block;
  border-radius: 99px;
  background: var(--accent);
}

.target-word {
  min-height: clamp(41px, 5.8vh, 58px);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(2px, 0.45vw, 6px);
  font-size: clamp(30px, 5.4vh, 54px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.045em;
}

.target-letter {
  min-width: 0.64em;
  display: inline-block;
  color: rgba(74, 53, 64, 0.32);
  text-align: center;
  position: relative;
  transition: 220ms ease;
}

.target-letter--done {
  color: var(--accent);
}

.target-letter--next {
  color: var(--ink);
  transform: translateY(-1px);
}

.target-letter--next::after {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: -6px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.target-panel.is-complete .target-word {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 3px;
  text-underline-offset: 8px;
}

.target-hint {
  min-height: 15px;
  margin-top: 4px;
  color: #9c7f88;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.target-hint strong {
  color: var(--accent);
  font-size: 10px;
}

.board-wrap {
  height: min(100%, 92vw, 680px);
  min-height: 0;
  aspect-ratio: 1;
  max-width: min(92vw, 680px);
  max-height: none;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(168, 80, 110, 0.3);
  border-radius: clamp(18px, 3.3vw, 30px);
  background: var(--board);
  box-shadow: var(--shadow), 0 0 0 1px rgba(104, 67, 80, 0.12) inset;
  touch-action: none;
  transform: translateZ(0);
}

.board-wrap:focus {
  outline: none;
}

.board-wrap:focus-visible {
  border-color: rgba(104, 67, 80, 0.32);
  box-shadow: var(--shadow), 0 0 0 1px rgba(104, 67, 80, 0.16);
}

.board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.16);
}

.board-wrap.shake {
  animation: board-shake 420ms ease;
}

.board-wrap.flash-correct::before,
.board-wrap.flash-wrong::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  animation: board-flash 360ms ease-out forwards;
}

.board-wrap.flash-correct::before {
  background: rgba(216, 107, 136, 0.08);
}

.board-wrap.flash-wrong::before {
  background: rgba(214, 40, 57, 0.27);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--board);
}

.board-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  color: var(--ink);
  font-size: clamp(26px, 6vw, 52px);
  font-weight: 950;
  letter-spacing: 0.07em;
  text-align: center;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%) scale(0.7);
}

.board-toast.show {
  animation: toast-pop 720ms cubic-bezier(.16, 1.1, .3, 1) forwards;
}

.board-toast.is-wrong {
  color: var(--warning-deep);
  text-shadow: 0 3px 0 rgba(255, 248, 247, 0.7), 0 4px 18px rgba(179, 19, 40, 0.22);
}

.board-toast small {
  display: block;
  margin-top: 7px;
  color: var(--accent);
  font-size: 0.3em;
  letter-spacing: 0.15em;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 32px);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  background: rgba(255, 248, 247, 0.88);
  transition: opacity 230ms ease, visibility 230ms ease;
}

.screen--visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.screen-card {
  width: min(100%, 430px);
  text-align: center;
  transform: translateY(12px) scale(0.98);
  transition: transform 300ms cubic-bezier(.2, .85, .35, 1);
}

.screen--visible .screen-card {
  transform: translateY(0) scale(1);
}

.hero-mark {
  height: 46px;
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.hero-mark__tile {
  width: 42px;
  height: 42px;
  margin-right: -5px;
  display: grid;
  place-items: center;
  border: 2px solid #c9809a;
  border-radius: 12px;
  background: #efb5c4;
  color: #563746;
  font-size: 18px;
  font-weight: 950;
  box-shadow: 0 5px 11px rgba(0, 0, 0, 0.22);
  transform: rotate(-3deg);
}

.hero-mark__tile:nth-child(2) { transform: translateY(4px) rotate(2deg); }
.hero-mark__tile:nth-child(3) { transform: translateY(-2px) rotate(-1deg); }
.hero-mark__tile--head {
  z-index: 1;
  width: 47px;
  height: 47px;
  border-color: var(--accent);
  background: var(--accent);
  transform: translateY(-4px) rotate(3deg);
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.25);
}

.start-card h1,
.screen-card h2 {
  margin: 0;
  font-size: clamp(43px, 8vw, 68px);
  font-weight: 950;
  line-height: 0.88;
  letter-spacing: -0.055em;
}

.start-card h1 span {
  display: block;
  color: var(--ink);
  font-size: 0.54em;
  letter-spacing: 0.17em;
  transform: translateX(0.08em);
}

.start-card h1 {
  color: var(--accent);
}

.primary-button {
  width: 100%;
  min-height: 54px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: #563746;
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0.12em;
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 150ms ease;
}

.button-icon {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 160ms ease;
}

.primary-button:hover .button-icon {
  transform: translateX(3px);
}

.button-icon--round {
  stroke-width: 1.8;
}

.primary-button:hover,
.primary-button:focus-visible {
  transform: translateY(-2px);
  outline: none;
}

.primary-button:active {
  transform: translateY(1px) scale(0.99);
}

.play-tutorial {
  height: 34px;
  margin-top: 9px;
  display: grid;
  place-items: center;
  color: var(--accent);
}

.tutorial-cursor,
.tutorial-hand {
  width: 28px;
  height: 30px;
  fill: #fffdfb;
  stroke: #a9506e;
  stroke-width: 1.6;
  stroke-linejoin: round;
  animation: tutorial-tap 1.8s ease-in-out infinite;
}

.tutorial-hand { display: none; }

@keyframes tutorial-tap {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(3px) scale(.94); }
  60% { transform: translateY(0) scale(1); }
}

.compact-card,
.result-card {
  max-width: 360px;
}

.screen-kicker {
  display: block;
  margin-bottom: 9px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.24em;
}

.compact-card h2,
.result-card h2 {
  margin-bottom: 28px;
  font-size: clamp(40px, 9vw, 60px);
}

.text-button {
  margin-top: 12px;
  padding: 9px 16px;
  border: 0;
  background: transparent;
  color: #839086;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.15em;
  cursor: pointer;
}

.text-button:hover,
.text-button:focus-visible {
  color: var(--ink);
  outline: none;
}

.result-grid {
  margin: -3px 0 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid rgba(104, 67, 80, 0.16);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(104, 67, 80, 0.05);
}

.result-grid div {
  padding: 13px 8px;
}

.result-grid div:nth-child(odd) { border-right: 1px solid rgba(104, 67, 80, 0.12); }
.result-grid div:nth-child(-n+2) { border-bottom: 1px solid rgba(104, 67, 80, 0.12); }

.result-grid span,
.result-grid strong {
  display: block;
}

.result-grid span {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.result-grid strong {
  margin-top: 2px;
  color: var(--ink);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.game-footer {
  position: relative;
  width: min(94vw, 680px);
  min-height: 26px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  color: #9c7f88;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.game-footer p {
  margin: 0;
  text-align: center;
}

.game-footer p strong {
  color: #74515f;
}

.lives {
  position: absolute;
  top: 10px;
  left: clamp(14px, 3vw, 34px);
  display: flex;
  gap: 10px;
  font-size: 11px;
}

.life {
  width: 28px;
  height: 28px;
  color: #d9c0c5;
  transition: 250ms ease;
}

.life svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
  stroke: #563746;
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.life svg circle,
.life svg path:last-child {
  fill: none;
  stroke: #563746;
  stroke-width: 1.2;
  stroke-linecap: round;
}

.life--active {
  color: var(--coral);
}

.mobile-controls {
  display: none;
}

.move-button {
  width: 56px;
  height: 50px;
  border: 1px solid rgba(104, 67, 80, 0.18);
  border-radius: 10px;
  background: #fff1f1;
  color: var(--ink);
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.move-button:active {
  transform: translateY(1px);
}

.move-button--up { grid-area: up; }
.move-button--left { grid-area: left; }
.move-button--down { grid-area: down; }
.move-button--right { grid-area: right; }

.life.lost {
  animation: life-lost 450ms ease;
}

.mobile-pause-button { display: none; }

@keyframes stat-bump {
  50% { transform: translateY(-2px); }
}

@keyframes next-pulse {
  50% { opacity: 0.45; transform: scaleX(0.72); }
}

@keyframes word-celebrate {
  45% { transform: scale(1.11); letter-spacing: 0.085em; }
}

@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-8px) rotate(-0.5deg); }
  36% { transform: translateX(7px) rotate(0.4deg); }
  54% { transform: translateX(-5px); }
  72% { transform: translateX(3px); }
}

@keyframes board-flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes toast-pop {
  0% { opacity: 0; transform: translate(-50%, -45%) scale(.65); }
  28% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  70% { opacity: 1; transform: translate(-50%, -52%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -63%) scale(.95); }
}

@keyframes life-lost {
  40% { color: white; transform: scale(1.55) rotate(20deg); }
  100% { color: #d9c0c5; transform: scale(0.7); }
}

@media (max-width: 640px) {
  .topbar {
    min-height: 58px;
    grid-template-columns: 70px 1fr 70px;
    gap: 7px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .mini-brand span { display: none; }
  .mini-brand strong { font-size: 13px; }
  .hud-stats { justify-content: center; gap: clamp(12px, 5vw, 24px); }
  .stat { min-width: 44px; }
  .stat__label { font-size: 7px; }
  .stat__value { font-size: 16px; }
  .stat--best { display: none; }
  .icon-button { width: 32px; height: 32px; border-radius: 10px; }
  .topbar__actions { gap: 5px; }

  .game-layout {
    padding-left: 10px;
    padding-right: 10px;
    gap: 8px;
  }

  .lives {
    top: 86px;
    left: 50%;
    gap: 12px;
    transform: translateX(-50%);
  }

  .life {
    width: 38px;
    height: 38px;
  }

  .target-panel__eyebrow { font-size: 7px; }
  .round-meta { letter-spacing: 0.12em; }
  .target-panel { padding-bottom: 38px; }
  .target-word { font-size: clamp(27px, 9vw, 42px); min-height: 38px; }
  .target-hint { margin-top: 2px; }
  .board-wrap { height: min(100%, 96vw, 680px); max-width: 96vw; border-radius: 20px; }
  .game-footer { width: 96vw; grid-template-columns: auto 1fr; gap: 8px 10px; }
  .game-footer p { text-align: right; }
  .mobile-controls {
    grid-column: 1 / -1;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-areas: ". up ." "left down right";
    justify-content: center;
    gap: 10px;
  }
  .start-card { width: min(100%, 370px); }
  .hero-mark { margin-bottom: 12px; }
  .hero-mark__tile { width: 36px; height: 36px; border-radius: 10px; }
  .hero-mark__tile--head { width: 41px; height: 41px; }
  .primary-button { min-height: 50px; }
  .play-tutorial { margin-top: 7px; }
  .tutorial-cursor { display: none; }
  .tutorial-hand { display: block; width: 31px; height: 31px; }
  .mobile-pause-button {
    position: absolute;
    right: 0;
    top: -2px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(104, 67, 80, 0.18);
    border-radius: 12px;
    background: #fff1f1;
    color: var(--ink);
    cursor: pointer;
  }
  .mobile-pause-button .cute-icon { width: 22px; height: 22px; }
}

@media (max-height: 720px) and (min-width: 641px) {
  .topbar { min-height: 56px; padding-top: 9px; padding-bottom: 9px; }
  .game-layout { padding-top: 8px; padding-bottom: 7px; gap: 6px; }
  .target-word { min-height: 36px; font-size: 34px; }
  .target-hint { margin-top: 1px; }
  .game-footer { min-height: 18px; }
  .start-card { max-width: 370px; }
  .hero-mark { margin-bottom: 9px; }
  .hero-mark__tile { width: 34px; height: 34px; border-radius: 9px; font-size: 15px; }
  .hero-mark__tile--head { width: 39px; height: 39px; }
  .start-card h1 { font-size: 46px; }
  .primary-button { min-height: 47px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .topbar { min-height: 46px; padding: 5px 14px; }
  .game-layout {
    padding: 7px 14px;
    grid-template-columns: minmax(180px, 0.8fr) auto minmax(150px, 0.8fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: center;
    justify-items: stretch;
    gap: 16px;
  }
  .target-panel { width: auto; }
  .lives {
    top: -26px;
    left: 50%;
    transform: translateX(-50%);
  }
  .life {
    width: 38px;
    height: 38px;
  }
  .target-word { flex-wrap: wrap; font-size: clamp(26px, 5.8vw, 42px); }
  .board-wrap { justify-self: center; width: auto; height: 100%; max-width: none; }
  .game-footer { width: auto; display: flex; flex-direction: column; gap: 14px; }
  .game-footer p { max-width: 130px; line-height: 1.5; }
  .mobile-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-areas: ". up ." "left down right";
    justify-content: center;
    gap: 10px;
  }
  .start-card { max-width: 330px; }
  .hero-mark { display: none; }
  .start-card h1 { font-size: 38px; }
  .primary-button { min-height: 40px; }
  .play-tutorial { margin-top: 4px; }
  .tutorial-cursor { display: none; }
  .tutorial-hand { display: block; width: 27px; height: 27px; }
  .mobile-pause-button { display: grid; position: static; align-self: center; width: 44px; height: 44px; }
}

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