:root {
  color-scheme: light;
  --page: #f7f2e8;
  --paper: #fffdf8;
  --ink: #1e2430;
  --muted: #667085;
  --line: #ded4c2;
  --teal: #167a7f;
  --teal-dark: #0f5f63;
  --red: #d9483b;
  --yellow: #f4b942;
  --blue: #3b6edb;
  --green: #28865c;
  --shadow: 0 22px 55px rgba(30, 36, 48, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@font-face {
  font-family: "Perry Gothic";
  src: url("fonts/perry_gothic/PERRYGOT.TTF") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Game Color Emoji";
  src: url("fonts/Game Color Emoji.ttc") format("truetype-collection");
  font-display: block;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  isolation: isolate;
  background: var(--page);
  color: var(--ink);
  font-family:
    Inter,
    "Game Color Emoji",
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
  overflow-x: clip;
}

body.app-loading {
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  top: 50%;
  left: 50%;
  width: calc(100vw + 12vmax);
  width: calc(100dvw + 12vmax);
  height: calc(100vh + 12vmax);
  height: calc(100dvh + 12vmax);
  z-index: -1;
  background:
    linear-gradient(rgba(247, 242, 232, 0.12), rgba(247, 242, 232, 0.12)),
    url("images/background.jpg") center center / cover no-repeat;
  transform: translate(-50%, -50%) translateZ(0);
  pointer-events: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible {
  outline: 4px solid rgba(63, 169, 245, 0.35);
  outline-offset: 3px;
}

.emoji-glyph {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.14em;
  object-fit: contain;
  pointer-events: none;
}

.game-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 18px;
  padding: 28px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding:
    calc(var(--safe-top) + 24px)
    calc(var(--safe-right) + 24px)
    calc(var(--safe-bottom) + 24px)
    calc(var(--safe-left) + 24px);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.82), transparent 42%),
    rgba(247, 242, 232, 0.94);
  backdrop-filter: blur(8px);
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
}

.loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding:
    calc(var(--safe-top) + 24px)
    calc(var(--safe-right) + 24px)
    calc(var(--safe-bottom) + 24px)
    calc(var(--safe-left) + 24px);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 42%),
    rgba(30, 36, 48, 0.36);
  backdrop-filter: blur(8px);
}

.setup-overlay[hidden] {
  display: none;
}

.setup-card {
  width: min(640px, 100%);
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 28px;
  border: 3px solid #2c2f36;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 248, 223, 0.96), rgba(255, 253, 248, 0.98));
  box-shadow:
    0 16px 0 #2c2f36,
    0 34px 80px rgba(30, 36, 48, 0.28);
}

.setup-progress {
  margin: 0;
  color: #8a5b00;
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.setup-title {
  margin: 0;
  color: #243140;
  font-size: clamp(2rem, 4.4vw, 2.8rem);
  line-height: 1.02;
  font-family: "Perry Gothic", Georgia, "Times New Roman", serif;
  text-align: center;
}

.setup-copy {
  margin: -8px 0 0;
  color: #5f6775;
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.setup-panel[hidden] {
  display: none;
}

.setup-choices {
  display: grid;
  gap: 14px;
  width: 100%;
}

.setup-choice {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px 20px;
  border: 3px solid #2c2f36;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: #243140;
  text-align: center;
  box-shadow: 0 6px 0 #2c2f36;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease,
    border-color 140ms ease;
}

.setup-choice:hover {
  transform: translateY(-1px);
}

.setup-choice:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #2c2f36;
}

.setup-choice.active {
  border-color: #c6184a;
  background: linear-gradient(180deg, #fff8c9, #fff0a8);
  box-shadow:
    0 6px 0 #2c2f36,
    0 0 0 5px rgba(198, 24, 74, 0.12);
}

.setup-choice-icon,
.setup-choice-state {
  display: inline-flex;
  align-items: center;
  gap: 0.24em;
}

.setup-choice-icon {
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  line-height: 1;
}

.setup-choice-icon .emoji-glyph {
  width: 0.95em;
  height: 0.95em;
}

.setup-choice-state {
  color: #1f3044;
  font-size: clamp(1.25rem, 3vw, 1.55rem);
  font-weight: 900;
  line-height: 1;
}

.setup-choice small {
  color: #5f6775;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.35;
}

.setup-actions {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.setup-action {
  min-width: 144px;
  min-height: 58px;
  padding: 0 20px;
  border: 3px solid #2c2f36;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  font-size: 1.16rem;
  font-weight: 900;
  box-shadow: 0 5px 0 #2c2f36;
}

.setup-action.secondary {
  background: #ffffff;
  color: #243140;
}

.setup-action[hidden] {
  visibility: hidden;
}

.setup-action:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #2c2f36;
}

.loading-card {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 32px 28px;
  border: 2px solid #2c2f36;
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 24px 60px rgba(30, 36, 48, 0.18);
  text-align: center;
}

.loading-card h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.6;
  font-family: "Perry Gothic", Georgia, "Times New Roman", serif;
  color: #243140;
}

.loading-status {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.loading-spinner {
  width: 74px;
  height: 74px;
  border: 6px solid rgba(36, 49, 64, 0.14);
  border-top-color: #c6184a;
  border-right-color: #f4b942;
  border-bottom-color: #bcc6d0;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.82),
    0 0 0 8px rgba(255, 255, 255, 0.36);
  animation: loadingSpin 880ms linear infinite;
}

.game-board {
  width: min(1120px, 100%);
  min-height: min(760px, calc(100dvh - 56px));
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr;
  overflow: hidden;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.5);
  box-shadow: var(--shadow);
  backdrop-filter: blur(3px);
}

.site-footer {
  width: min(1120px, 100%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 8px calc(var(--safe-bottom) + 4px);
  color: rgba(30, 36, 48, 0.78);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  opacity: 0.68;
}

.site-footer a {
  color: inherit;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.14em;
}

.site-footer a:hover {
  color: var(--teal-dark);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px 30px 20px;
  background: #ffffff;
  border-bottom: 2px solid var(--line);
}

.brand-block {
  min-width: 0;
}

.brand-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: clamp(81px, 12vw, 132px);
  height: clamp(81px, 12vw, 132px);
  flex: 0 0 auto;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: clamp(3.36rem, 6.72vw, 6.384rem);
  display: inline-block;
  line-height: 1.14;
  letter-spacing: 0;
  font-family: "Perry Gothic", Georgia, "Times New Roman", serif;
  padding-top: 0.15em;
  transform: translateY(0.08em);
  background: linear-gradient(
    90deg,
    #ff4d4d 0%,
    #ff9f1c 16%,
    #ffd166 32%,
    #5fd068 48%,
    #3fa9f5 64%,
    #8b5cf6 82%,
    #ff5db1 100%
  );
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}

.settings-toggle {
  width: 70px;
  height: 70px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff8df;
  color: #5b3b00;
  font-size: 2.16rem;
  line-height: 1;
  box-shadow: 0 4px 0 #2c2f36;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

.settings-toggle:hover {
  background: #ffe89c;
}

.settings-toggle:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2c2f36;
}

.settings-toggle.active {
  background: #ffe089;
}

.settings-toggle-wobble {
  animation: settingsWobble 2s ease-in-out 1;
}

.settings-strip {
  display: flex;
  justify-content: flex-end;
  padding: 14px 30px 0;
  background: rgba(255, 253, 248, 0.5);
}

.round-card,
.score-card {
  min-width: 92px;
  min-height: 76px;
  display: grid;
  place-items: center;
  padding: 10px 14px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #ffffff;
}

.score-card {
  min-width: 128px;
  background: #fff8df;
}

.round-card span,
.score-card span {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.round-card small,
.score-card small {
  color: var(--muted);
  font-weight: 800;
}

.score-card small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  line-height: 1.05;
  white-space: nowrap;
}

.score-card small .emoji-glyph {
  width: 0.9em;
  height: 0.9em;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 14px;
  align-items: stretch;
  padding: 14px 30px 18px;
  border-bottom: 2px solid var(--line);
  background: rgba(255, 253, 248, 0.5);
  max-height: min(62dvh, 660px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.controls[hidden] {
  display: none;
}

.controls > * {
  min-width: 0;
  grid-column: auto;
  grid-row: auto;
  padding: 14px 16px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.tile-count-control {
  grid-column: 1 / -1;
}

.quarter-control {
  grid-column: 1 / -1;
}

.timer-control {
  grid-column: 1 / -1;
}

.volume-control {
  grid-column: 1 / -1;
}

.tile-count-control,
.volume-control,
.case-control,
.order-control,
.sfx-control,
.monster-control,
.auto-skip-control,
.timer-control,
.quarter-control {
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px 14px;
  align-items: center;
}

.tile-count-control,
.volume-control {
  grid-template-columns: auto auto minmax(0, 1fr);
  justify-content: stretch;
  width: 100%;
}

.case-control,
.order-control,
.sfx-control,
.monster-control,
.auto-skip-control {
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
}

.tile-count-control span,
.volume-control span,
.case-control > span,
.order-control > span,
.sfx-control > span,
.monster-control > span,
.auto-skip-control > span,
.timer-control > span,
.quarter-control > span {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.monster-control > span,
.settings-toggle {
  font-family:
    "Game Color Emoji",
    Inter,
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Noto Color Emoji",
    sans-serif;
}

.tile-count-control strong,
.volume-control strong {
  justify-self: start;
  min-width: 42px;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
  font-size: 1.2rem;
}

.tile-count-control input,
.volume-control input {
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
  height: 40px;
  accent-color: var(--teal);
  appearance: none;
  background: transparent;
  justify-self: start;
}

.tile-count-control input {
  width: 100%;
}

.volume-control input {
  width: 100%;
}

.tile-count-control input::-webkit-slider-runnable-track,
.volume-control input::-webkit-slider-runnable-track {
  height: 16px;
  border: 2px solid #2c2f36;
  border-radius: 999px;
  background: rgba(22, 122, 127, 0.22);
}

.tile-count-control input::-webkit-slider-thumb,
.volume-control input::-webkit-slider-thumb {
  appearance: none;
  width: 32px;
  height: 32px;
  margin-top: -10px;
  border: 2px solid #2c2f36;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 3px 0 #2c2f36;
}

.tile-count-control input::-moz-range-track,
.volume-control input::-moz-range-track {
  height: 16px;
  border: 2px solid #2c2f36;
  border-radius: 999px;
  background: rgba(22, 122, 127, 0.22);
}

.tile-count-control input::-moz-range-thumb,
.volume-control input::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border: 2px solid #2c2f36;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 3px 0 #2c2f36;
}

.tile-count-control input::-moz-range-progress,
.volume-control input::-moz-range-progress {
  height: 16px;
  border-radius: 999px;
  background: rgba(22, 122, 127, 0.56);
}

.case-options,
.order-options,
.quarter-options {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  min-height: 58px;
  display: grid;
  gap: 4px;
  padding: 4px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
}

.case-options,
.order-options {
  grid-template-columns: repeat(2, 1fr);
}

.case-options {
  grid-template-columns: repeat(3, 1fr);
}

.timer-presets {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 6px;
  justify-self: stretch;
  width: 100%;
}

.timer-control {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  justify-content: stretch;
}

.timer-control > span,
.timer-presets,
.timer-duration-field,
.timer-toggle {
  justify-self: stretch;
}

.quarter-control {
  grid-column: 1 / -1;
}

.quarter-options {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.case-option,
.order-option,
.quarter-option {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 500;
}

.case-option.active,
.order-option.active,
.quarter-option.active {
  background: var(--yellow);
  color: #2c2f36;
}

.sfx-toggle {
  grid-column: 1 / -1;
  min-height: 58px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 400;
}

.sfx-toggle.active {
  background: var(--yellow);
  color: #2c2f36;
}

.monster-toggle {
  grid-column: 1 / -1;
  min-height: 58px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 950;
}

.monster-toggle.active {
  background: var(--yellow);
  color: #2c2f36;
}

.auto-skip-toggle {
  grid-column: 1 / -1;
  min-height: 58px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 950;
}

.auto-skip-toggle.active {
  background: var(--yellow);
  color: #2c2f36;
}

.timer-toggle,
.timer-duration-field {
  min-height: 58px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
}

.timer-toggle {
  min-width: 118px;
  padding: 0 18px;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 950;
  width: 100%;
}

.timer-toggle.active {
  background: var(--yellow);
  color: #2c2f36;
}

.timer-preset {
  min-height: 58px;
  padding: 0 14px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 900;
}

.timer-preset.active {
  background: var(--yellow);
  color: #2c2f36;
}

.timer-preset,
.case-option,
.order-option,
.quarter-option,
.sfx-toggle,
.monster-toggle,
.auto-skip-toggle,
.timer-toggle {
  width: 100%;
}

.timer-duration-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  min-width: 0;
  width: 100%;
}

.timer-duration-field input {
  width: 100%;
  min-width: 5ch;
  border: 0;
  background: transparent;
  color: #2c2f36;
  font-size: 1.1rem;
  font-weight: 900;
  text-align: right;
}

.timer-duration-field small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.play-button {
  position: relative;
  min-height: 58px;
  min-width: 190px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: linear-gradient(180deg, #f4f6f8 0%, #d5dbe2 52%, #b7c0c9 100%);
  color: #243140;
  font-size: 1.18rem;
  font-weight: 900;
  box-shadow: 0 5px 0 #2c2f36;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform;
}

.play-cluster {
  position: relative;
}

.play-sparkles {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: calc(100% + 56px);
  height: 112px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  contain: paint;
}

.play-sparkle {
  position: absolute;
  display: block;
  width: 14px;
  height: 14px;
  opacity: 0;
  transform: translate3d(0, 0, 0) scale(0.25) rotate(0deg);
  pointer-events: none;
  will-change: transform, opacity;
  background: currentColor;
  clip-path: polygon(
    50% 0%,
    61% 34%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 34%
  );
}

.play-sparkle.silver {
  color: rgba(255, 255, 255, 0.96);
  text-shadow:
    0 0 8px rgba(255, 255, 255, 0.92),
    0 0 14px rgba(255, 255, 255, 0.34);
}

.play-sparkle.ruby {
  color: rgba(198, 24, 74, 0.92);
  text-shadow:
    0 0 8px rgba(198, 24, 74, 0.82),
    0 0 14px rgba(198, 24, 74, 0.32);
}

.sparkle-1 {
  top: 14%;
  left: 14%;
  width: 16px;
  height: 16px;
}

.sparkle-2 {
  top: 46%;
  left: 22%;
  width: 14px;
  height: 14px;
}

.sparkle-3 {
  top: 8%;
  left: 32%;
  width: 17px;
  height: 17px;
}

.sparkle-4 {
  top: 56%;
  left: 42%;
  width: 14px;
  height: 14px;
}

.sparkle-5 {
  top: 16%;
  left: 53%;
  width: 16px;
  height: 16px;
}

.sparkle-6 {
  top: 38%;
  left: 62%;
  width: 17px;
  height: 17px;
}

.sparkle-7 {
  top: 12%;
  left: 73%;
  width: 16px;
  height: 16px;
}

.sparkle-8 {
  top: 48%;
  left: 84%;
  width: 14.5px;
  height: 14.5px;
}

.sparkle-9 {
  top: 22%;
  left: 91%;
  width: 14px;
  height: 14px;
}

.sparkle-10 {
  top: 6%;
  left: 8%;
  width: 13px;
  height: 13px;
}

.sparkle-11 {
  top: 32%;
  left: 18%;
  width: 15px;
  height: 15px;
}

.sparkle-12 {
  top: 68%;
  left: 27%;
  width: 13px;
  height: 13px;
}

.sparkle-13 {
  top: 4%;
  left: 46%;
  width: 14px;
  height: 14px;
}

.sparkle-14 {
  top: 62%;
  left: 56%;
  width: 15px;
  height: 15px;
}

.sparkle-15 {
  top: 26%;
  left: 67%;
  width: 13px;
  height: 13px;
}

.sparkle-16 {
  top: 66%;
  left: 76%;
  width: 14px;
  height: 14px;
}

.sparkle-17 {
  top: 10%;
  left: 86%;
  width: 15px;
  height: 15px;
}

.sparkle-18 {
  top: 42%;
  left: 96%;
  width: 13px;
  height: 13px;
}

.play-button:hover {
  background: linear-gradient(180deg, #fbfcfd 0%, #dde3e8 52%, #c0c9d1 100%);
}

.play-button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #2c2f36;
}

.play-button svg {
  width: 55px;
  height: 55px;
  fill: currentColor;
}

.play-button span {
  font-size: 2em;
  line-height: 1;
}

.play-button-wobble-a,
.play-button-wobble-b {
  animation-duration: 2s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: 1;
}

.play-button-wobble-a {
  animation: settingsWobble 2s ease-in-out 1;
}

.play-button-wobble-b {
  animation-name: settingsWobbleAlt;
}

.play-sparkles-a .play-sparkle:nth-child(odd) {
  animation: playButtonMagicStars 1.7s ease-out 1;
}

.play-sparkles-a .play-sparkle:nth-child(even) {
  animation: playButtonMagicStarsReverse 1.7s ease-out 1;
}

.play-sparkles-b .play-sparkle:nth-child(odd) {
  animation: playButtonMagicStarsAlt 1.7s ease-out 1;
}

.play-sparkles-b .play-sparkle:nth-child(even) {
  animation: playButtonMagicStarsReverseAlt 1.7s ease-out 1;
}

.fullscreen-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  width: 64px;
  height: 64px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #2c2f36;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #1e2430;
  box-shadow: 0 5px 0 #2c2f36;
  backdrop-filter: blur(6px);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.fullscreen-toggle:hover {
  background: #fff8df;
}

.fullscreen-toggle:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #2c2f36;
}

.fullscreen-toggle svg {
  position: absolute;
  width: 29px;
  height: 29px;
  fill: currentColor;
  transition: opacity 120ms ease, transform 120ms ease;
}

.fullscreen-toggle-exit {
  opacity: 0;
  transform: scale(0.86);
}

.fullscreen-toggle.is-fullscreen {
  background: var(--teal);
  color: #fff;
}

.fullscreen-toggle.is-fullscreen .fullscreen-toggle-enter {
  opacity: 0;
  transform: scale(0.86);
}

.fullscreen-toggle.is-fullscreen .fullscreen-toggle-exit {
  opacity: 1;
  transform: scale(1);
}

.prompt-strip {
  min-height: 54px;
  display: grid;
  grid-template-columns:
    minmax(110px, auto)
    minmax(190px, 240px)
    minmax(128px, auto);
  grid-template-areas: "round play score";
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 10px 30px;
  border-bottom: 2px solid var(--line);
  background: rgba(255, 248, 223, 0.5);
  color: #5b3b00;
  font-weight: 850;
  text-align: center;
}

.prompt-strip.with-timer {
  grid-template-columns:
    minmax(110px, auto)
    minmax(190px, 240px)
    minmax(110px, auto)
    minmax(128px, auto);
  grid-template-areas: "round play timer score";
}

.round-card {
  grid-area: round;
}

.score-card {
  grid-area: score;
}

.play-cluster {
  grid-area: play;
  min-width: 0;
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 6px;
}

.prompt-text {
  min-height: 1.25em;
  overflow-wrap: anywhere;
  font-size: clamp(0.92rem, 1.8vw, 1.05rem);
  line-height: 1.15;
}

.prompt-text:empty {
  display: none;
}

.timer-card {
  grid-area: timer;
  min-width: 110px;
  min-height: 76px;
  display: grid;
  place-items: center;
  padding: 10px 14px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: #fff3c8;
}

.timer-card:not([hidden]) {
  cursor: pointer;
}

.timer-card:not([hidden]):active {
  transform: translateY(2px);
}

.timer-card span {
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1;
  color: #7a4d00;
}

.timer-card small {
  color: var(--muted);
  font-weight: 800;
}

.timer-card[hidden] {
  display: none !important;
}

.timer-control-attention {
  border-color: var(--yellow);
  box-shadow:
    0 0 0 4px rgba(244, 185, 66, 0.26),
    0 0 0 10px rgba(244, 185, 66, 0.12);
  animation: timerControlPulse 1.4s ease-out 1;
}

.wrong-alert {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(30, 36, 48, 0.26);
}

.wrong-alert[hidden] {
  display: none;
}

.wrong-alert-card {
  width: min(620px, 86vw);
  min-height: 20vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 28px;
  border: 3px solid #2c2f36;
  border-radius: 8px;
  background: #fff8df;
  color: #5b1d13;
  text-align: center;
  box-shadow: 0 12px 0 #2c2f36;
  animation: wrongAlertPop 180ms ease both;
}

.timer-alert-card {
  background: #fff4ca;
  color: #6b4b00;
}

.timer-alert-character {
  font-size: clamp(2.88rem, 8.8vw, 4.8rem);
  white-space: normal;
}

.timer-alert-dismiss {
  min-width: 140px;
  min-height: 56px;
  padding: 0 18px;
  border: 2px solid #2c2f36;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 900;
  box-shadow: 0 4px 0 #2c2f36;
}

.timer-alert-dismiss:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2c2f36;
}

.wrong-alert-character {
  font-size: clamp(4rem, 12vw, 7rem);
  line-height: 1;
}

.wrong-alert-card p {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2.6rem);
  font-weight: 950;
  line-height: 1.15;
}

.attack-value {
  color: var(--red);
}

.monster-name {
  color: #000;
  background: #fff;
  padding: 0 0.18em;
  border-radius: 0.2em;
}

.final-score-positive {
  color: var(--blue);
}

.final-score-negative {
  color: var(--red);
}

.tiles-area {
  min-height: 0;
  padding: 26px 30px 30px;
  background: rgba(255, 253, 248, 0.5);
}

.score-card span.score-positive {
  color: var(--blue);
}

.score-card span.score-negative {
  color: var(--red);
}

.score-card span.score-neutral {
  color: var(--ink);
}

.letter-grid {
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  align-content: center;
}

.letter-tile {
  position: relative;
  container-type: size;
  flex: 0 0 160px;
  width: 160px;
  aspect-ratio: 1 / 1;
  min-height: 116px;
  display: grid;
  place-items: center;
  border: 3px solid #2c2f36;
  border-radius: 8px;
  color: #fff;
  font-size: clamp(3.4rem, 9vw, 6.8rem);
  font-weight: 500;
  line-height: 1;
  box-shadow: 0 7px 0 #2c2f36;
  user-select: none;
  overflow: hidden;
  transition:
    filter 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

.letter-tile:hover {
  filter: brightness(1.04);
}

.letter-tile.selected {
  transform: translateY(5px);
  box-shadow: 0 2px 0 #2c2f36;
  outline: 5px solid rgba(22, 122, 127, 0.28);
}

.letter-tile.correct,
.letter-tile.correct:nth-child(4n + 1),
.letter-tile.correct:nth-child(4n + 2),
.letter-tile.correct:nth-child(4n + 3),
.letter-tile.correct:nth-child(4n + 4) {
  background: #8fd3ff;
  color: #11324d;
  transform: translateY(5px);
  box-shadow: 0 2px 0 #2c2f36;
  outline: 6px solid rgba(244, 185, 66, 0.6);
  animation: correctPop 360ms ease both;
}

.tile-reward {
  position: absolute;
  right: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: inline-flex;
  gap: 0.12em;
  font-size: clamp(0.9rem, 2.1vw, 1.35rem);
  line-height: 1;
  white-space: nowrap;
}

.tile-score-bonus {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.14em;
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-size: 25cqh;
  font-weight: 700;
  line-height: 1;
  color: #f2d43d;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  transform: translate(-50%, -50%);
  animation: tileScoreBonusFloat 1.25s ease-out forwards;
}

.tile-score-bonus .emoji-glyph {
  width: 0.92em;
  height: 0.92em;
  vertical-align: -0.1em;
}

.letter-tile.wrong,
.letter-tile.wrong:nth-child(4n + 1),
.letter-tile.wrong:nth-child(4n + 2),
.letter-tile.wrong:nth-child(4n + 3),
.letter-tile.wrong:nth-child(4n + 4) {
  background: #7b8088;
  color: #fff;
  animation: shake 360ms ease both;
  outline: 6px solid rgba(217, 72, 59, 0.45);
}

.success-burst {
  position: fixed;
  inset: 0;
  z-index: 15;
  overflow: hidden;
  pointer-events: none;
}

.success-star {
  position: absolute;
  top: 0;
  left: 0;
  font-size: var(--star-size, 2rem);
  line-height: 1;
  opacity: 0;
  transform: translate3d(var(--star-x), var(--star-y), 0) scale(0.25)
    rotate(0deg);
  animation: successSparkle 820ms ease-out forwards;
  animation-delay: var(--star-delay, 0ms);
  text-shadow:
    0 0 11px rgba(255, 255, 255, 0.92),
    0 0 22px rgba(244, 185, 66, 0.78),
    0 0 34px rgba(255, 226, 123, 0.58);
}

@keyframes correctPop {
  0% {
    transform: translateY(0) scale(1);
  }

  55% {
    transform: translateY(5px) scale(1.06);
  }

  100% {
    transform: translateY(5px) scale(1);
  }
}

@keyframes tileScoreBonusFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, -38%) scale(0.88);
  }

  18% {
    opacity: 1;
    transform: translate(-50%, -52%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -92%) scale(1.04);
  }
}

@keyframes loadingSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-7px);
  }

  50% {
    transform: translateX(7px);
  }

  75% {
    transform: translateX(-4px);
  }
}

@keyframes wrongAlertPop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes timerControlPulse {
  0% {
    transform: scale(0.98);
    box-shadow:
      0 0 0 0 rgba(244, 185, 66, 0.34),
      0 0 0 0 rgba(244, 185, 66, 0.2);
  }

  45% {
    transform: scale(1.01);
    box-shadow:
      0 0 0 6px rgba(244, 185, 66, 0.22),
      0 0 0 14px rgba(244, 185, 66, 0.1);
  }

  100% {
    transform: scale(1);
    box-shadow:
      0 0 0 4px rgba(244, 185, 66, 0.26),
      0 0 0 10px rgba(244, 185, 66, 0.12);
  }
}

@keyframes playButtonMagicStars {
  0% {
    opacity: 0;
    transform: translate(-16px, 16px) scale(0.2) rotate(-18deg);
  }

  20% {
    opacity: 1;
    transform: translate(0, 0) scale(1.1) rotate(6deg);
  }

  52% {
    opacity: 1;
    transform: translate(6px, -10px) scale(0.96) rotate(12deg);
  }

  100% {
    opacity: 0;
    transform: translate(18px, -24px) scale(1.34) rotate(24deg);
  }
}

@keyframes playButtonMagicStarsAlt {
  0% {
    opacity: 0;
    transform: translate(-16px, 16px) scale(0.2) rotate(-18deg);
  }

  20% {
    opacity: 1;
    transform: translate(0, 0) scale(1.1) rotate(6deg);
  }

  52% {
    opacity: 1;
    transform: translate(6px, -10px) scale(0.96) rotate(12deg);
  }

  100% {
    opacity: 0;
    transform: translate(18px, -24px) scale(1.34) rotate(24deg);
  }
}

@keyframes playButtonMagicStarsReverse {
  0% {
    opacity: 0;
    transform: translate(18px, 14px) scale(0.28) rotate(20deg);
  }

  24% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(-8deg);
  }

  58% {
    opacity: 1;
    transform: translate(-8px, -8px) scale(0.92) rotate(-14deg);
  }

  100% {
    opacity: 0;
    transform: translate(-22px, -22px) scale(1.26) rotate(-26deg);
  }
}

@keyframes playButtonMagicStarsReverseAlt {
  0% {
    opacity: 0;
    transform: translate(18px, 14px) scale(0.28) rotate(20deg);
  }

  24% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(-8deg);
  }

  58% {
    opacity: 1;
    transform: translate(-8px, -8px) scale(0.92) rotate(-14deg);
  }

  100% {
    opacity: 0;
    transform: translate(-22px, -22px) scale(1.26) rotate(-26deg);
  }
}

@keyframes successSparkle {
  0% {
    opacity: 0;
    transform: translate3d(var(--star-x), var(--star-y), 0) scale(0.25)
      rotate(0deg);
  }

  18% {
    opacity: 1;
    transform: translate3d(
        calc(var(--star-x) + var(--star-dx) * 0.35),
        calc(var(--star-y) + var(--star-dy) * 0.35),
        0
      )
      scale(1.18) rotate(110deg);
  }

  100% {
    opacity: 0;
    transform: translate3d(
        calc(var(--star-x) + var(--star-dx)),
        calc(var(--star-y) + var(--star-dy)),
        0
      )
      scale(0.82) rotate(240deg);
  }
}

@keyframes settingsWobble {
  0%,
  100% {
    transform: rotate(0deg);
  }

  10% {
    transform: rotate(-14deg);
  }

  20% {
    transform: rotate(12deg);
  }

  30% {
    transform: rotate(-10deg);
  }

  40% {
    transform: rotate(8deg);
  }

  50% {
    transform: rotate(-6deg);
  }

  60% {
    transform: rotate(5deg);
  }

  70% {
    transform: rotate(-4deg);
  }

  80% {
    transform: rotate(3deg);
  }

  90% {
    transform: rotate(-2deg);
  }
}

@keyframes settingsWobbleAlt {
  0%,
  100% {
    transform: rotate(0deg);
  }

  10% {
    transform: rotate(-14deg);
  }

  20% {
    transform: rotate(12deg);
  }

  30% {
    transform: rotate(-10deg);
  }

  40% {
    transform: rotate(8deg);
  }

  50% {
    transform: rotate(-6deg);
  }

  60% {
    transform: rotate(5deg);
  }

  70% {
    transform: rotate(-4deg);
  }

  80% {
    transform: rotate(3deg);
  }

  90% {
    transform: rotate(-2deg);
  }
}

.letter-tile:nth-child(4n + 1) {
  background: var(--red);
}

.letter-tile:nth-child(4n + 2) {
  background: var(--blue);
}

.letter-tile:nth-child(4n + 3) {
  background: var(--green);
}

.letter-tile:nth-child(4n + 4) {
  background: var(--yellow);
  color: #2c2f36;
}

.letter-tile.correct {
  background: #128453;
  color: #fff;
}

.letter-tile.shuffle-in {
  animation: popIn 260ms ease both;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 720px) {
  .game-shell {
    padding: 0;
  }

  .game-board {
    min-height: 100dvh;
    border-width: 0;
    border-radius: 0;
  }

  .game-header,
  .controls,
  .settings-strip,
  .prompt-strip,
  .tiles-area {
    padding-left: max(18px, var(--safe-left));
    padding-right: max(18px, var(--safe-right));
  }

  .game-header {
    padding-top: max(26px, var(--safe-top));
  }

  .tiles-area {
    padding-bottom: max(30px, var(--safe-bottom));
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .tile-count-control,
  .quarter-control,
  .case-control,
  .order-control,
  .sfx-control,
  .monster-control,
  .auto-skip-control,
  .timer-control,
  .volume-control {
    grid-column: 1;
    grid-row: auto;
  }

  .tile-count-control,
  .volume-control {
    grid-template-columns: auto auto;
  }

  .tile-count-control input,
  .volume-control input {
    grid-column: 1 / -1;
    grid-row: auto;
    width: 100%;
  }

  .quarter-options {
    grid-template-columns: 1fr 1fr;
  }

  .timer-control {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .timer-presets {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-self: stretch;
    width: 100%;
  }

  .timer-duration-field,
  .timer-toggle {
    width: 100%;
  }

  .settings-toggle {
    width: 62px;
    height: 62px;
    font-size: 1.9rem;
  }

  .play-button {
    width: 100%;
  }

  .fullscreen-toggle {
    right: 14px;
    bottom: 14px;
    width: 58px;
    height: 58px;
  }

  .letter-grid {
    gap: 12px;
  }

  .letter-tile {
    flex-basis: 132px;
    width: 132px;
    min-height: 92px;
  }

  .setup-card {
    padding: 24px 18px 20px;
  }

  .setup-actions {
    flex-direction: column-reverse;
  }

  .setup-action {
    width: 100%;
  }
}

@media (min-width: 721px) and (max-width: 1180px) {
  .game-shell {
    padding: 14px;
    min-height: auto;
    place-items: start center;
  }

  .game-board {
    min-height: min(760px, calc(100dvh - 28px));
    height: auto;
    max-height: none;
  }
}

@media (min-width: 721px) and (max-width: 1180px) and (orientation: portrait) {
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .tile-count-control,
  .quarter-control,
  .timer-control,
  .volume-control {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .case-control,
  .order-control,
  .sfx-control,
  .monster-control,
  .auto-skip-control {
    grid-column: auto;
    grid-row: auto;
  }

  .tile-count-control,
  .volume-control {
    grid-template-columns: auto auto minmax(0, 1fr);
  }

  .timer-control {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .timer-presets {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-self: stretch;
    width: 100%;
  }

  .timer-duration-field,
  .timer-toggle {
    width: 100%;
  }
}

@media (max-width: 960px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .tile-count-control,
  .volume-control {
    grid-template-columns: auto auto;
  }

  .tile-count-control input,
  .volume-control input {
    grid-column: 1 / -1;
    grid-row: auto;
    width: 100%;
  }

  .timer-control {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .timer-duration-field,
  .timer-toggle {
    grid-column: 1;
  }
}

@media (max-width: 430px) {
  .prompt-strip {
    grid-template-columns: 1fr;
    grid-template-areas:
      "play"
      "round"
      "score";
  }

  .prompt-strip.with-timer {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "play play"
      "round timer"
      "score score";
  }

  .play-cluster {
    width: 100%;
  }

  .play-button,
  .round-card,
  .timer-card,
  .score-card {
    width: 100%;
    min-width: 0;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 960px),
  (hover: none) and (pointer: coarse) and (max-height: 500px) {
  .fullscreen-toggle {
    display: none;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  body::before {
    width: calc(100lvw + 18vmax);
    height: calc(100lvh + 18vmax);
    background-position: center center;
  }

  .game-header,
  .controls,
  .settings-strip,
  .prompt-strip,
  .tiles-area {
    padding-left: max(18px, var(--safe-left));
    padding-right: max(18px, var(--safe-right));
  }
}

@media (max-width: 340px) {
  .prompt-strip {
    grid-template-columns: 1fr;
    grid-template-areas:
      "play"
      "round"
      "score";
  }

  .prompt-strip.with-timer {
    grid-template-columns: 1fr;
    grid-template-areas:
      "play"
      "round"
      "timer"
      "score";
  }

  .play-cluster,
  .play-button,
  .round-card,
  .timer-card,
  .score-card {
    width: 100%;
  }
}
