:root {
  color-scheme: dark;
  --ink: #fff8ee;
  --muted: #b9c4d8;
  --line: rgba(255,255,255,.18);
  --panel: rgba(12,21,42,.94);
  --blue: #54c7ff;
  --yellow: #ffd166;
  --green: #42d97b;
  --pink: #ff5ca8;
  --purple: #bca7ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(255,209,102,.18), transparent 28%),
    radial-gradient(circle at 84% 10%, rgba(84,199,255,.2), transparent 30%),
    linear-gradient(155deg, #08122d 0%, #12335d 50%, #080d19 100%);
  color: var(--ink);
  touch-action: manipulation;
  user-select: none;
}

button, input { font: inherit; }
.shell {
  display: grid;
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  place-items: center;
}
@supports (height: 100dvh) { .shell { height: 100dvh; min-height: 100dvh; } }

.game {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(7px, 1.1dvh, 11px);
  width: min(100%, 560px);
  height: min(100%, 920px);
  min-height: 0;
}

.brand-header {
  display: grid;
  min-height: clamp(38px, 6.5dvh, 58px);
  place-items: center;
  text-align: center;
}

.game-logo {
  color: transparent;
  font-size: clamp(1.4rem, min(7dvw, 5.4dvh), 2.85rem);
  font-weight: 1000;
  line-height: .92;
  background: linear-gradient(90deg, #ffd166 0%, #54c7ff 42%, #ff5ca8 78%, #fff8ee 100%);
  background-clip: text;
  -webkit-background-clip: text;
  filter: drop-shadow(0 5px 0 rgba(5,10,24,.5)) drop-shadow(0 0 16px rgba(84,199,255,.34));
  text-transform: uppercase;
}

.site-tag {
  margin-top: 3px;
  color: rgba(255,248,238,.78);
  font-size: clamp(.62rem, min(2.2dvw, 1.9dvh), .88rem);
  font-weight: 900;
  letter-spacing: .08em;
}

.topbar, .bottombar {
  display: grid;
  align-items: center;
  gap: clamp(6px, 1.3dvw, 10px);
}
.topbar { grid-template-columns: repeat(3, 1fr); }
.bottombar { grid-template-columns: 1fr 1fr 1fr .7fr .7fr 1.05fr; }

.metric {
  min-width: 0;
  padding: clamp(6px, 1dvh, 9px) 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.09);
  box-shadow: 0 10px 28px rgba(0,0,0,.2);
}
.metric.center { text-align: center; }
.metric.right { text-align: right; }
.metric span {
  display: block;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 850;
  text-transform: uppercase;
}
.metric strong {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  font-size: clamp(1.02rem, 3.1dvh, 1.42rem);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-wrap {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255,255,255,.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px),
    rgba(4,10,28,.84);
  background-size: 34px 34px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), 0 18px 45px rgba(0,0,0,.3);
  overflow: hidden;
}

.solved-groups {
  display: grid;
  gap: 7px;
}

.solved-card {
  padding: 8px 10px;
  border: 2px solid rgba(255,255,255,.26);
  border-radius: 8px;
  color: #071225;
  text-align: center;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 7px 14px rgba(0,0,0,.22);
}
.solved-card strong {
  display: block;
  font-size: .86rem;
  font-weight: 1000;
  text-transform: uppercase;
}
.solved-card span {
  display: block;
  margin-top: 2px;
  font-size: .72rem;
  font-weight: 850;
}

.groups-board {
  align-self: center;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(6px, 1.5dvw, 10px);
}

.word-tile {
  min-width: 0;
  min-height: clamp(56px, 10.4dvh, 82px);
  padding: 7px 5px;
  border: 2px solid rgba(255,255,255,.22);
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fbff 0%, #d9e8ff 55%, #aecaff 100%);
  color: #071225;
  cursor: pointer;
  font-size: clamp(.72rem, 2.5dvw, .98rem);
  font-weight: 1000;
  line-height: 1.05;
  text-transform: uppercase;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.85), inset 0 -5px 0 rgba(18,102,255,.18), 0 8px 16px rgba(0,0,0,.24);
}
.word-tile.selected {
  background: linear-gradient(180deg, #fff6bf 0%, #ffd166 58%, #d69b12 100%);
  border-color: #fff8ee;
  transform: translateY(-2px);
}
.word-tile.solved {
  visibility: hidden;
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: 88%;
  transform: translate(-50%, -50%) scale(.96);
  color: #ffd524;
  font-size: clamp(1.2rem, 6vw, 2rem);
  font-weight: 1000;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 4px 14px rgba(0,0,0,.7);
}
.toast.pop { animation: toastPop 1700ms ease-out; }

.small-button, .primary-button, .secondary-button, .arcade-button, .store-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 950;
  min-height: 46px;
}
.small-button {
  padding: 0 8px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--yellow) 34%, #fff) 0%, var(--yellow) 54%, color-mix(in srgb, var(--yellow) 72%, #8a5a00) 100%);
  color: #121827;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.48), inset 0 -4px 0 rgba(89,51,0,.22), 0 7px 16px rgba(0,0,0,.24);
}
.primary-tap, .primary-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue) 34%, #fff) 0%, var(--blue) 52%, color-mix(in srgb, var(--blue) 72%, #071225) 100%);
  color: #071225;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.42), inset 0 -4px 0 rgba(5,10,24,.22), 0 8px 18px rgba(0,0,0,.26);
}
.buy-button, .store-button {
  border: 1px solid rgba(84,199,255,.45);
  background: linear-gradient(180deg, rgba(255,255,255,.2) 0%, rgba(255,255,255,.1) 50%, rgba(5,10,24,.22) 100%);
  color: var(--ink);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -4px 0 rgba(5,10,24,.22), 0 7px 16px rgba(0,0,0,.22);
}
.icon-button {
  width: 46px;
  min-width: 46px;
  padding: 0;
  font-size: 1.18rem;
  line-height: 1;
}
.primary-button, .secondary-button, .arcade-button, .store-button {
  width: 100%;
  margin-top: 12px;
  padding: 0 18px;
}
.secondary-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--yellow) 34%, #fff) 0%, var(--yellow) 54%, color-mix(in srgb, var(--yellow) 72%, #8a5a00) 100%);
  color: #121827;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.48), inset 0 -4px 0 rgba(89,51,0,.22), 0 7px 16px rgba(0,0,0,.24);
}

.arcade-store-arcade-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 0 0 14px;
  border: 2px solid #1266ff;
  background: linear-gradient(180deg, #fff 0%, #f2f8ff 44%, #d4e8ff 100%);
  color: #071225;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.95), inset 0 -4px 0 rgba(18,102,255,.2), 0 8px 20px rgba(18,102,255,.22);
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
}
.arcade-store-arcade-button .bleep-blue { color: #1266ff; text-transform: uppercase; }

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(5,8,18,.72);
  backdrop-filter: blur(10px);
}
.overlay.show { display: flex; }
.panel {
  width: min(100%, 410px);
  max-height: min(92dvh, 780px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0,0,0,.42);
  text-align: center;
}
.kicker {
  margin: 0;
  color: var(--yellow);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
h1 {
  margin: 8px 0 0;
  font-size: clamp(2rem, 9dvw, 3.2rem);
  line-height: .95;
}
.panel p:not(.kicker) {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.42;
}
.score-form {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  text-align: left;
}
.score-form label {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 900;
  text-transform: uppercase;
}
.score-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255,255,255,.1);
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
}
.initials-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.high-score { color: var(--yellow)!important; }
.home-scores {
  max-height: 28dvh;
  margin-top: 14px;
  overflow: auto;
  text-align: left;
}
.home-scores h2 { margin: 0 0 6px; font-size: 1rem; }
.home-scores ol { margin: 0; padding-left: 25px; }
.home-scores li { padding: 2px 0; color: var(--muted); font-size: .86rem; font-weight: 750; }
.home-scores[hidden], .score-form[hidden], button[hidden] { display: none!important; }
.pause-action-row { display: contents; }
.pause-action-row:has(>button:not([hidden]) + button:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 8px;
  margin-top: 12px;
}
.pause-action-row:has(>button:not([hidden]) + button:not([hidden])) > button {
  width: 100%!important;
  min-width: 0;
  margin-top: 0!important;
}

@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -35%) scale(.8); }
  15%, 72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -72%) scale(1.08); }
}

@media (max-width: 430px) {
  .bottombar { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 42px; }
  .small-button { min-height: 42px; padding: 0 6px; font-size: .8rem; }
  .icon-button { width: auto; min-width: 0; }
  .word-tile { min-height: clamp(49px, 9.4dvh, 68px); font-size: clamp(.62rem, 2.7dvw, .82rem); }
  .board-wrap { padding: 9px; }
}
/* Compact high-score entry row: Initials, City, Save. */
.score-form {
  display: grid;
  grid-template-columns: minmax(4.2rem, 4.9rem) minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: end;
}

.score-form label[for="initialsInput"] {
  grid-column: 1;
  grid-row: 1;
}

.score-form label[for="cityInput"] {
  grid-column: 2;
  grid-row: 1;
}

.initials-row {
  display: contents;
}

.initials-row input,
#initialsInput {
  grid-column: 1;
  grid-row: 2;
  width: 4.8rem;
  min-width: 0;
  text-align: center;
}

.city-input,
#cityInput {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
}

.initials-row button,
.score-form button[type="submit"] {
  grid-column: 3;
  grid-row: 2;
  min-width: 4.1rem;
  padding-inline: 10px;
}

.score-form datalist {
  display: none;
}

.score-form .high-score,
#highScoreText {
  grid-column: 1 / -1;
}
/* Keep the Arcade return button visible on initials/end-game overlays. */
.overlay {
  align-items: flex-start !important;
  overflow: auto !important;
  padding-top: max(10px, env(safe-area-inset-top)) !important;
  padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}

.panel {
  max-height: calc(100dvh - 20px) !important;
}

.arcade-store-arcade-button {
  position: sticky;
  top: 0;
  z-index: 5;
}
