:root {
  color-scheme: light;
  --ink: #36271c;
  --muted: #765f4c;
  --cream: #fff8e9;
  --saffron: #f28b21;
  --marigold: #ffc83d;
  --red: #cf4936;
  --green: #377d55;
  --indigo: #314f78;
  --shadow: 0 20px 70px #55391422;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  background: #f7e4b9;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, #fff8d8 0 5rem, transparent 5.1rem),
    radial-gradient(circle at 93% 92%, #e9774e33 0 12rem, transparent 12.1rem),
    linear-gradient(145deg, #fff7df, #f4d69d);
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
}

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

.game-page {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 42px) max(20px, env(safe-area-inset-bottom));
}

.topbar {
  height: 52px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.back-link, .mini-brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}

.back-link { width: max-content; font-size: 14px; }
.back-link span { display: inline-block; margin-right: 5px; transition: transform .2s ease; }
.back-link:hover span { transform: translateX(-4px); }

.mini-brand { display: flex; align-items: center; gap: 10px; font-size: 20px; }
.mini-brand b { color: var(--red); }
.brand-gulli {
  width: 34px;
  height: 12px;
  display: inline-block;
  border: 2px solid #6d371d;
  border-radius: 80% 20% 80% 20%;
  background: #d98134;
  box-shadow: inset 0 2px #f7b760;
  transform: rotate(-12deg);
}

.top-actions { justify-self: end; display: flex; gap: 8px; }
.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #7d57283b;
  border-radius: 14px;
  color: var(--ink);
  background: #fffaf0cc;
  box-shadow: 0 6px 20px #68400f13;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  transition: transform .18s ease, background .18s ease;
}
.icon-button:hover { transform: translateY(-2px); background: #fff; }
.sound-off { display: none; }
.icon-button[aria-pressed="true"] .sound-on { display: none; }
.icon-button[aria-pressed="true"] .sound-off { display: inline; }

.game-shell {
  width: 100%;
  position: relative;
  overflow: hidden;
  border: clamp(5px, .8vw, 11px) solid #fff8e9;
  border-radius: clamp(22px, 3vw, 38px);
  background: #79cdf2;
  box-shadow: var(--shadow), 0 0 0 1px #7e522b26;
  isolation: isolate;
}

#game-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
  outline: 0;
  touch-action: none;
  user-select: none;
}

.hud {
  position: absolute;
  z-index: 5;
  inset: clamp(12px, 2.1vw, 28px) clamp(12px, 2.1vw, 28px) auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
}

.hud-card {
  width: max-content;
  min-width: 108px;
  padding: 10px 15px;
  border: 2px solid #ffffffa8;
  border-radius: 18px;
  background: #fff8e9e8;
  box-shadow: 0 8px 26px #41331d20;
  backdrop-filter: blur(8px);
}

.hud-label {
  display: block;
  color: #87684f;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.score-card strong { font-size: clamp(24px, 3vw, 38px); line-height: 1; }
.hud-center { display: flex; gap: 7px; }
.level-pill, .wind-pill {
  padding: 8px 12px;
  border-radius: 999px;
  color: #fff;
  background: #3a704fdd;
  box-shadow: 0 7px 20px #1b4a2a26;
  backdrop-filter: blur(6px);
  font-size: 12px;
}
.wind-pill { background: #314f78df; }
.level-pill span { opacity: .8; }
.wind-arrow { display: inline-block; font-size: 17px; line-height: 0; transition: transform .25s ease; }

.status-card {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 14px;
}
.status-card strong { display: block; font-size: 20px; }
.lives { display: flex; gap: 5px; color: var(--red); font-size: 17px; text-shadow: 0 1px #fff; }
.lives span.lost { color: #c7b9ab; transform: scale(.75); }

.coach {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: clamp(16px, 3vw, 36px);
  transform: translateX(-50%);
  padding: 10px 17px;
  border: 2px solid #fff9;
  border-radius: 99px;
  color: #fff;
  background: #35261dcc;
  box-shadow: 0 8px 30px #291d1540;
  font-size: clamp(11px, 1.25vw, 16px);
  font-weight: 900;
  letter-spacing: .02em;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  white-space: nowrap;
}

.toast {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 32%;
  opacity: 0;
  transform: translate(-50%, 10px) scale(.85) rotate(-2deg);
  color: #fff;
  text-shadow: 0 3px 0 #75371b;
  font-size: clamp(28px, 5vw, 68px);
  font-weight: 900;
  pointer-events: none;
}
.toast.show { animation: toast-pop 1s cubic-bezier(.2,.9,.3,1) both; }
@keyframes toast-pop {
  0% { opacity: 0; transform: translate(-50%, 18px) scale(.75) rotate(-4deg); }
  18%, 68% { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(1.08) rotate(1deg); }
}

.overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 36px);
  overflow-y: auto;
  background: linear-gradient(120deg, #402613cf, #8a4d25a8);
  backdrop-filter: blur(8px);
}

.start-overlay {
  background:
    radial-gradient(circle at 80% 15%, #ffcf4d55 0 6rem, transparent 6.1rem),
    linear-gradient(120deg, #2c2017e8, #754120c9);
}

.start-card, .dialog-card {
  width: min(720px, 94%);
  max-height: 100%;
  padding: clamp(22px, 3.1vw, 42px);
  overflow-y: auto;
  border: 2px solid #fff;
  border-radius: clamp(24px, 3vw, 38px);
  text-align: center;
  background: #fff8e9f7;
  box-shadow: 0 25px 80px #26120870;
}

.title-mark { position: relative; width: 90px; height: 34px; margin: 0 auto 5px; }
.title-stick { position: absolute; width: 88px; height: 11px; left: 0; top: 10px; border-radius: 20px; background: linear-gradient(#9b5528, #6d351e); transform: rotate(-8deg); box-shadow: inset 0 2px #d28a49; }
.title-gulli { position: absolute; width: 37px; height: 15px; right: 0; top: 2px; border-radius: 100% 15%; background: #ed9a38; transform: rotate(25deg); box-shadow: inset 0 2px #ffc765; }

.kicker {
  margin: 0 0 7px;
  color: var(--green);
  font-size: clamp(10px, 1vw, 13px);
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 9px;
  color: var(--ink);
  font-size: clamp(42px, 6vw, 74px);
  line-height: .94;
  letter-spacing: -.06em;
}
h1 span { color: var(--red); }
h2 { margin-bottom: 10px; font-size: clamp(34px, 4vw, 52px); line-height: 1; letter-spacing: -.04em; }
.lede { max-width: 590px; margin: 0 auto; color: var(--muted); font-size: clamp(13px, 1.45vw, 17px); line-height: 1.45; }

.how-to {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: clamp(16px, 2.2vw, 25px) 0 14px;
}
.how-to div {
  min-width: 0;
  padding: 12px 8px;
  border: 1px solid #d7b98e;
  border-radius: 17px;
  background: #fffdf8;
}
.step-number { width: 23px; height: 23px; display: grid; place-items: center; margin: 0 auto 5px; border-radius: 50%; color: white; background: var(--saffron); font-size: 12px; font-weight: 900; }
.how-to strong, .how-to small { display: block; }
.how-to strong { font-size: 15px; }
.how-to small { margin-top: 2px; color: #8a715b; font-size: 10px; }
.controls-copy { margin: 0 0 16px; color: #826b57; font-size: clamp(10px, 1vw, 12px); }

.primary-button {
  min-width: 190px;
  padding: 13px 22px;
  border: 0;
  border-radius: 15px;
  color: white;
  background: linear-gradient(135deg, #e35c35, #c33d32);
  box-shadow: 0 9px 0 #912b24, 0 16px 25px #a8413038;
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
  transition: transform .15s ease, box-shadow .15s ease;
}
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 11px 0 #912b24, 0 19px 28px #a8413045; }
.primary-button:active { transform: translateY(5px); box-shadow: 0 4px 0 #912b24; }
.primary-button span { display: inline-block; margin-left: 8px; }

.compact-card { width: min(520px, 95%); }
.compact-card > p:not(.kicker) { color: var(--muted); }
.text-button {
  display: block;
  margin: 18px auto 0;
  padding: 6px;
  border: 0;
  color: #79583d;
  background: transparent;
  cursor: pointer;
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.link-button { width: max-content; }
.trophy { width: 72px; height: 72px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 50% 50% 45% 45%; color: #7b471c; background: var(--marigold); box-shadow: 0 8px 0 #d48e1e; font-size: 38px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0 24px; }
.result-grid div { padding: 13px; border: 1px solid #dfc6a1; border-radius: 15px; background: #fffdf8; }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: #8c725c; font-size: 11px; text-transform: uppercase; }
.result-grid strong { margin-top: 3px; font-size: 24px; }

.touch-controls {
  display: none;
  grid-template-columns: 72px minmax(150px, 230px) 72px;
  justify-content: center;
  gap: 10px;
  margin: 15px auto 0;
  touch-action: none;
  user-select: none;
}
.control-button {
  height: 62px;
  border: 1px solid #a87a443f;
  border-radius: 19px;
  color: var(--ink);
  background: #fff9ed;
  box-shadow: 0 7px 0 #d6b77d, 0 12px 25px #6f4a2222;
  cursor: pointer;
  font-weight: 900;
}
.control-button:active, .control-button.pressed { transform: translateY(5px); box-shadow: 0 2px 0 #d6b77d; }
.aim-button span, .aim-button small { display: block; }
.aim-button span { font-size: 24px; line-height: 20px; }
.aim-button small { margin-top: 4px; color: #8c6e53; }
.strike-button { color: white; background: linear-gradient(135deg, #ef733c, #c94032); box-shadow: 0 7px 0 #922d25, 0 12px 25px #8d34262c; }
.strike-button:active, .strike-button.pressed { box-shadow: 0 2px 0 #922d25; }
.strike-icon { margin-right: 7px; color: #ffdd5c; }

.desktop-tip { margin: 14px 0 0; color: #6f5744; text-align: center; font-size: 12px; font-weight: 700; }
kbd { padding: 3px 7px; border: 1px solid #b99d78; border-bottom-width: 3px; border-radius: 6px; background: #fffaf0; font: 800 11px system-ui; }

@media (max-width: 820px), (pointer: coarse) {
  .touch-controls { display: grid; }
  .desktop-tip { display: none; }
  .game-page { padding-inline: 8px; }
  .topbar { height: 45px; margin-bottom: 8px; }
  .mini-brand { font-size: 17px; }
  .brand-gulli { width: 27px; height: 10px; }
  .icon-button { width: 38px; height: 38px; }
  .back-link { font-size: 0; }
  .back-link span { font-size: 25px; }
  .game-shell { border-width: 4px; border-radius: 22px; }
}

@media (max-width: 610px) {
  .hud-card { min-width: 0; padding: 7px 10px; border-radius: 13px; }
  .score-card strong { font-size: 22px; }
  .hud-center { gap: 4px; }
  .level-pill, .wind-pill { padding: 6px 8px; font-size: 9px; }
  .status-card { gap: 7px; }
  .status-card strong { font-size: 15px; }
  .lives { gap: 2px; font-size: 12px; }
  .hud-label { font-size: 8px; }
  .coach { padding: 6px 10px; bottom: 9px; }
  .how-to { gap: 5px; }
  .how-to div { padding: 8px 3px; }
  .start-card, .dialog-card { padding: 18px 16px 22px; }
  .title-mark { display: none; }
  .controls-copy { display: none; }
  .primary-button { padding-block: 11px; }
  .touch-controls { grid-template-columns: 62px minmax(145px, 210px) 62px; }
}

@media (max-height: 690px) and (min-width: 700px) {
  .game-page { padding-top: 6px; }
  .topbar { height: 38px; margin-bottom: 4px; }
  .icon-button { width: 35px; height: 35px; }
  .start-card { padding: 16px 28px 20px; }
  .title-mark { display: none; }
  .how-to { margin-block: 12px 10px; }
  .desktop-tip { margin-top: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
