:root {
  color-scheme: light;
  --bg: #f5f0e6;
  --panel: #fffdf8;
  --panel-2: #17324d;
  --text: #203241;
  --muted: #64727b;
  --accent: #e2ad36;
  --accent-2: #2b7a78;
  --danger: #d96955;
  --shadow: 5px 5px 0 rgba(23, 50, 77, .14);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 0; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0;
  background:
    linear-gradient(rgba(23,50,77,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23,50,77,.035) 1px, transparent 1px),
    var(--bg);
  background-size: 3rem 3rem;
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
.game-shell { width: min(100%, 42rem); height: var(--game-visible-height, 100dvh); min-height: 0; margin: 0 auto; padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; gap: .85rem; overflow: hidden; }
.game-header, .scorebar, .game-actions { display: flex; align-items: center; gap: .65rem; }
.game-header { min-height: 3.8rem; justify-content: space-between; border-bottom: 1px solid #c9c0b2; }
.game-header h1 { min-width: 0; margin: 0; overflow: hidden; color: #17324d; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.35rem, 5vw, 1.8rem); text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.icon-button, .action-button { min-width: 3rem; min-height: 3rem; border: 2px solid #17324d; border-radius: 9px; background: var(--panel); color: #17324d; cursor: pointer; font-weight: 800; box-shadow: 3px 3px 0 rgba(23,50,77,.13); transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.icon-button, .back-link { flex: none; }
.icon-button, .action-button, .back-link, .metric-label, .metric-value { white-space: nowrap; }
.icon-button:hover, .action-button:hover { transform: translate(-1px,-2px); box-shadow: 5px 5px 0 rgba(23,50,77,.16); }
.icon-button:active, .action-button:active { transform: translate(1px, 2px) scale(.98); box-shadow: 1px 1px 0 rgba(23,50,77,.16); }
.icon-button:focus-visible, .action-button:focus-visible, .game-board button:focus-visible { outline: 3px solid var(--danger); outline-offset: 2px; }
.back-link { display: inline-grid; place-items: center; width: 3rem; height: 3rem; border: 2px solid #17324d; border-radius: 7px; background: var(--panel); color: #17324d; text-decoration: none; font-size: 1.4rem; font-weight: 900; }
.scorebar { justify-content: space-between; padding: .75rem 1rem; border: 1px solid #c9c0b2; border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.metric { min-width: 0; display: grid; gap: .12rem; }
.metric:last-child { text-align: right; }
.metric-label { color: var(--muted); font-size: .68rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.metric-value { color: #17324d; font-size: 1.2rem; font-variant-numeric: tabular-nums; font-weight: 900; transition: transform .18s ease, color .18s ease; }
.metric-value.bump { color: var(--accent-2); animation: metric-bump .3s ease; }
.game-stage { min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; container-type: size; touch-action: none; -webkit-user-select: none; user-select: none; }
.game-stage input, .game-stage textarea { touch-action: manipulation; -webkit-user-select: text; user-select: text; }
.game-actions { justify-content: center; }
.action-button { padding: .7rem 1rem; }
.action-button.primary { background: var(--accent); color: #17324d; }
.action-button[aria-pressed="true"] { background: var(--accent-2); color: white; }
.game-message { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 1.25rem; background: rgba(16, 38, 58, .72); backdrop-filter: blur(6px); animation: overlay-in .2s ease both; }
.game-message[hidden] { display: none; }
.message-card { width: min(100%, 24rem); max-height: calc(100dvh - 2.5rem); padding: 1.5rem; overflow: auto; overscroll-behavior: contain; border: 2px solid #17324d; border-radius: 12px; background: var(--panel); box-shadow: 7px 7px 0 rgba(0,0,0,.2); text-align: center; animation: card-in .28s cubic-bezier(.2,.8,.2,1) both; }
.message-card h2 { margin: 0 0 .55rem; color: #17324d; font-family: Georgia, "Times New Roman", serif; font-size: 1.8rem; }
.message-card h2 { text-wrap: balance; }
.message-card p { margin: 0 0 1.2rem; color: var(--muted); line-height: 1.55; text-wrap: pretty; }
.message-actions { display: flex; justify-content: center; gap: .65rem; }
.message-actions .action-button { flex: 1 1 0; }
.result-close { background: transparent; }
.win-celebration { position: fixed; inset: 0; z-index: 20; overflow: hidden; pointer-events: none; background: radial-gradient(circle at 50% 70%, rgba(226,173,54,.08), transparent 48%); }
.firework-burst { position: absolute; left: var(--burst-x); top: var(--burst-y); width: .45rem; height: .45rem; animation: firework-flash .85s ease-out var(--burst-delay) both; }
.firework-burst::after { content: ""; position: absolute; inset: -.2rem; border: 2px solid #fffdf8; border-radius: 50%; animation: firework-ring .75s ease-out var(--burst-delay) both; }
.firework-burst i { position: absolute; inset: 0; border-radius: 999px; background: var(--particle-color); box-shadow: 0 0 .45rem var(--particle-color); animation: firework-particle .9s cubic-bezier(.12,.72,.2,1) var(--burst-delay) both; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@keyframes metric-bump { 50% { transform: scale(1.18); } }
@keyframes overlay-in { from { opacity: 0; } }
@keyframes card-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }
@keyframes firework-particle {
  0% { opacity: 0; transform: translate(0, 0) scale(.2); }
  16% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--particle-x), var(--particle-y)) scale(.7); }
}
@keyframes firework-flash {
  0%, 8% { opacity: 0; transform: scale(.2); }
  18% { opacity: 1; transform: scale(1.6); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes firework-ring {
  0%, 12% { opacity: 0; transform: scale(.1); }
  20% { opacity: .9; }
  100% { opacity: 0; transform: scale(7); }
}
@media (max-height: 760px) and (orientation: portrait) {
  .game-shell { padding: max(.5rem, env(safe-area-inset-top)) .75rem max(.5rem, env(safe-area-inset-bottom)); gap: .55rem; }
  .game-header { min-height: 3rem; }
  .game-header h1 { font-size: clamp(1.2rem, 5vw, 1.55rem); }
  .icon-button, .action-button { min-height: 2.75rem; }
  .back-link { width: 2.75rem; height: 2.75rem; }
  .scorebar { padding: .55rem .75rem; }
  .metric-value { font-size: 1rem; }
  .game-actions { gap: .45rem; }
  .action-button { padding: .55rem .75rem; }
}
@media (max-height: 620px) and (orientation: landscape) {
  .game-shell { width: min(100%, 52rem); height: var(--game-visible-height, 100dvh); grid-template-columns: minmax(12rem, 1.15fr) minmax(0, 1.85fr); grid-template-rows: auto 1fr auto; }
  .game-header { grid-column: 1; }
  .game-header { gap: .45rem; }
  .game-header h1 { font-size: 1.05rem; }
  .icon-button { min-width: 2.5rem; min-height: 2.5rem; padding: .3rem .45rem; font-size: .78rem; }
  .back-link { min-width: 2.5rem; width: 2.5rem; min-height: 2.5rem; height: 2.5rem; font-size: .82rem; }
  .scorebar { grid-column: 1; align-self: start; }
  .game-stage { grid-column: 2; grid-row: 1 / span 3; }
  .game-actions { grid-column: 1; gap: .25rem; }
  .game-actions > .action-button { min-width: 0; flex: 1 1 0; padding: .35rem .25rem; font-size: .72rem; }
}
@media (max-width: 340px) {
  .game-shell { padding-left: .6rem; padding-right: .6rem; }
  .game-header, .game-actions { gap: .4rem; }
  .game-header h1 { font-size: 1.16rem; }
  .icon-button { min-width: 2.55rem; min-height: 2.55rem; padding: .3rem .4rem; font-size: .74rem; }
  .back-link { min-width: 2.55rem; width: 2.55rem; min-height: 2.55rem; height: 2.55rem; font-size: .82rem; }
  .action-button { min-width: 2.4rem; padding-left: .55rem; padding-right: .55rem; font-size: .84rem; }
  .message-card { padding: 1.1rem; }
  .message-actions { gap: .45rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
