:root {
  color-scheme: light;
  --ink: #17324d;
  --cream: #fff7e5;
  --sky: #ddf4ff;
  --card: #fff;
  --primary: #08775f;
  --secondary: #2056a8;
  --yellow: #ffd45c;
  --orange: #e8872e;
  --coral: #f26a4f;
  --purple: #6941c6;
  --shadow: 0 16px 38px rgb(23 50 77 / 16%);
  font-family: ui-rounded, "Arial Rounded MT Bold", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; overflow-x: hidden; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% 16%, rgb(255 212 92 / 34%) 0 52px, transparent 53px),
    linear-gradient(180deg, var(--sky), var(--cream));
}
button { font: inherit; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.hidden { display: none !important; }
.app, .screen { min-height: 100dvh; }
.screen { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.screen--center { display: grid; place-items: center; }
.card, .panel { background: rgb(255 255 255 / 95%); border: 3px solid rgb(23 50 77 / 10%); border-radius: 28px; box-shadow: var(--shadow); }
.menu-card { width: min(100%, 520px); text-align: center; padding: 22px clamp(20px, 5vw, 44px) 28px; }
.menu-card h1, .page-panel h1 { margin: 2px 0 10px; font-size: clamp(30px, 6vw, 42px); }
.menu-card p { margin: 8px 0 20px; font-size: clamp(16px, 2.5vw, 19px); line-height: 1.5; }
.eyebrow { color: #0a625d; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; font-size: 14px !important; margin: 0 !important; }
.sprite { background: url("../assets/game-sprites-hand-throw-v2.png") no-repeat; background-size: 300% 200%; }
.sprite--hero-ready { margin: 0 auto -4px; width: 190px; aspect-ratio: 1; background-position: 0 100%; }
.button-stack { display: grid; gap: 12px; }
.button { min-height: 52px; padding: 12px 22px; border: 0; border-radius: 16px; color: #fff; font-size: 19px; font-weight: 800; cursor: pointer; box-shadow: 0 5px 0 rgb(23 50 77 / 22%); transition: transform .12s ease, filter .12s ease; }
.button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgb(23 50 77 / 22%); }
.button--primary { background: var(--primary); }
.button--secondary { background: var(--secondary); }
.button--warm { background: var(--orange); }
.key-hint { font-size: 14px !important; color: #47647d; }
kbd { border: 1px solid #9ab0c4; border-bottom-width: 3px; border-radius: 6px; padding: 2px 7px; background: #fff; }
.loading-card { padding: 36px; text-align: center; }
.spinner { width: 60px; height: 60px; margin: auto; border: 8px solid #cdeafa; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-panel { max-width: 920px; margin: auto; padding: clamp(18px, 4vw, 36px); }
.page-heading { display: flex; align-items: center; gap: 18px; margin-bottom: 24px; }
.page-heading h1 { margin-bottom: 0; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.level-card { min-height: 118px; border: 3px solid #bdd9eb; border-radius: 20px; background: #f8fdff; color: var(--ink); cursor: pointer; font-weight: 800; padding: 12px 8px; }
.level-card span { display: block; }
.level-card .level-number { font-size: 29px; }
.level-card .level-detail { margin-top: 6px; font-size: 13px; color: #47647d; }
.level-card.locked { background: #e9f0f4; border-style: dashed; cursor: not-allowed; }
.level-card.cleared { border-color: var(--primary); background: #ebfff8; }

.game-screen { display: grid; place-items: center; padding: 0; background: #bde9fb; }
.game-shell { position: relative; width: min(100vw, calc(100dvh * .75), 720px); aspect-ratio: 3 / 4; min-height: 0; overflow: hidden; background: var(--sky); border-radius: clamp(0px, 3vw, 28px); box-shadow: var(--shadow); touch-action: manipulation; }
.canvas-wrap { position: absolute; inset: 0; }
canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.hud { position: absolute; z-index: 5; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; pointer-events: none; }
.hud-pill { justify-self: start; min-height: 48px; display: flex; align-items: center; padding: 8px 14px; border-radius: 999px; background: rgb(255 255 255 / 94%); border: 2px solid rgb(23 50 77 / 10%); font-size: clamp(16px, 3vw, 21px); font-weight: 800; }
.hud-remaining { justify-self: center; }
.mini-knife { display: inline-block; width: 31px; height: 31px; background: url("../assets/game-sprites-hand-throw-v2.png") 100% 0 / 300% 200% no-repeat; }
.hud-actions { justify-self: end; display: flex; gap: 8px; pointer-events: auto; }
.icon-button { width: 50px; height: 50px; display: grid; place-items: center; border: 2px solid rgb(23 50 77 / 16%); border-radius: 50%; background: #fff; color: var(--ink); cursor: pointer; font-size: 24px; box-shadow: 0 3px 0 rgb(23 50 77 / 14%); }
.icon-button svg { width: 38px; height: 38px; }
.direction-badge { position: absolute; z-index: 3; top: 44%; right: 4%; display: flex; align-items: center; gap: 3px; padding: 5px 9px; border-radius: 999px; background: rgb(255 255 255 / 90%); font-weight: 800; font-size: clamp(12px, 2.4vw, 16px); transition: transform .2s ease, box-shadow .2s ease; }
.direction-badge svg { width: 30px; height: 30px; }
.direction-badge.warning { transform: scale(1.12); box-shadow: 0 0 0 6px rgb(255 212 92 / 60%); }
.wind-badge { position: absolute; z-index: 4; top: 44%; left: 4%; display: flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 999px; background: rgb(255 255 255 / 92%); color: var(--ink); font-size: clamp(12px, 2.4vw, 16px); font-weight: 900; box-shadow: 0 4px 14px rgb(23 50 77 / 15%); }
.wind-arrow { color: #2056a8; font-size: 27px; line-height: 1; }
.game-controls { position: absolute; z-index: 6; left: 0; right: 0; bottom: max(12px, env(safe-area-inset-bottom)); display: grid; place-items: center; pointer-events: none; }
.throw-button { pointer-events: auto; width: clamp(76px, 14vw, 94px); aspect-ratio: 1; border: 5px solid #fff; border-radius: 50%; background: var(--primary); color: #fff; font-size: clamp(18px, 3vw, 23px); font-weight: 900; box-shadow: 0 7px 0 #064c47, 0 10px 24px rgb(23 50 77 / 22%); cursor: pointer; touch-action: manipulation; }
.throw-button span { display: block; font-size: 11px; opacity: .85; }
.throw-button:disabled { filter: grayscale(.25); opacity: .55; cursor: default; }
.countdown { position: absolute; z-index: 8; inset: 0; display: grid; place-items: center; background: rgb(23 50 77 / 18%); color: #fff; font-size: clamp(88px, 24vw, 160px); font-weight: 900; text-shadow: 0 7px 0 var(--ink); }
.game-message { position: absolute; z-index: 4; top: 35%; left: 50%; transform: translateX(-50%); color: var(--ink); font-size: clamp(20px, 4vw, 30px); font-weight: 900; opacity: 0; pointer-events: none; }
.game-message.show { animation: pop-message .65s ease both; }
@keyframes pop-message { 0% { opacity: 0; transform: translate(-50%, 15px) scale(.7); } 25%, 70% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -10px); } }

.modal-layer { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgb(23 50 77 / 55%); }
.dialog { width: min(100%, 460px); padding: 24px clamp(22px, 5vw, 38px) 30px; border-radius: 26px; background: #fff; color: var(--ink); text-align: center; box-shadow: 0 24px 70px rgb(0 0 0 / 28%); }
.dialog-art { color: var(--yellow); -webkit-text-stroke: 2px var(--ink); font-size: 62px; line-height: 1; }
.dialog h2 { margin: 10px 0 8px; font-size: clamp(26px, 6vw, 34px); }
.dialog p { margin: 0 0 22px; font-size: 17px; line-height: 1.55; }
.modal-layer--collision {
  place-items: start center;
  padding-top: max(76px, calc(env(safe-area-inset-top) + 64px));
  background: linear-gradient(180deg, rgb(23 50 77 / 18%), transparent 48%);
  pointer-events: none;
}
.dialog--collision {
  pointer-events: auto;
  width: min(94%, 430px);
  padding: 12px 16px 16px;
  border: 3px solid rgb(232 135 46 / 75%);
  box-shadow: 0 10px 28px rgb(23 50 77 / 20%);
}
.dialog--collision .dialog-art { display: none; }
.dialog--collision h2 { margin: 0 0 3px; font-size: clamp(22px, 5vw, 28px); }
.dialog--collision p { margin: 0 0 10px; font-size: clamp(14px, 3vw, 16px); line-height: 1.35; }
.dialog--collision .button-stack { grid-template-columns: 1fr 1fr; gap: 8px; }
.dialog--collision .button { min-height: 46px; padding: 9px 12px; font-size: clamp(15px, 3vw, 18px); }
.shop-fab {
  position: fixed; z-index: 30; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  min-height: 58px; display: flex; align-items: center; gap: 7px; padding: 9px 15px;
  border: 3px solid #fff; border-radius: 999px; background: #7a4b17; color: #fff;
  font-size: 16px; font-weight: 900; box-shadow: 0 7px 0 #4c2c0b, 0 12px 28px rgb(23 50 77 / 25%); cursor: pointer;
}
.shop-fab strong { min-width: 2ch; color: var(--yellow); font-size: 20px; }
.shop-fab:disabled { opacity: .55; cursor: wait; }
.shop-layer { position: fixed; z-index: 40; inset: 0; display: grid; place-items: center; padding: 16px; background: rgb(23 50 77 / 62%); }
.shop-panel {
  width: min(100%, 860px); max-height: min(90dvh, 820px); overflow: auto; padding: clamp(18px, 4vw, 30px);
  border: 4px solid #ffd45c; border-radius: 28px; background: #fffaf0; color: var(--ink); box-shadow: 0 24px 70px rgb(0 0 0 / 30%);
}
.shop-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.shop-heading h2 { margin: 3px 0 12px; font-size: clamp(27px, 5vw, 38px); }
.shop-balance { display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 999px; background: #fff0b8; font-size: 19px; }
.shop-balance strong { font-size: 24px; }
.equipped-summary { margin: 12px 0 16px; color: #47647d; font-weight: 700; }
.shop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.shop-card { display: grid; align-content: start; gap: 7px; padding: 15px; border: 3px solid #c7dcea; border-radius: 20px; background: #fff; }
.shop-card.equipped { border-color: var(--primary); background: #ebfff8; box-shadow: inset 0 0 0 2px rgb(8 119 95 / 12%); }
.shop-card-icon { font-size: 34px; line-height: 1; }
.shop-card h3 { margin: 0; font-size: 20px; }
.shop-card p { min-height: 42px; margin: 0; color: #47647d; font-size: 14px; line-height: 1.45; }
.shop-card .button { min-height: 46px; padding: 9px 12px; font-size: 16px; }
.blind-box-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; margin-top: 18px; padding: 16px; border: 3px dashed #e8872e; border-radius: 20px; background: #fff4df; }
.blind-box-card h3 { margin: 0 0 5px; font-size: 23px; }
.blind-box-card p { margin: 0; color: #65431f; line-height: 1.45; }
.shop-result { min-height: 28px; margin: 13px 0 0; color: #0a625d; text-align: center; font-size: 18px; font-weight: 900; }
.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; }
.noscript { padding: 30px; text-align: center; }

@media (max-width: 599px) {
  .level-grid { grid-template-columns: repeat(2, 1fr); }
  .page-panel { min-height: calc(100dvh - 32px); }
  .game-shell { width: min(100vw, calc(100dvh * .75)); border-radius: 0; }
  .hud { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; }
  .hud-pill { min-height: 44px; padding: 6px 10px; }
  .icon-button { width: 46px; height: 46px; }
  .icon-button svg { width: 34px; height: 34px; }
  .shop-fab { min-height: 52px; padding: 7px 12px; font-size: 14px; }
  .shop-grid { grid-template-columns: repeat(2, 1fr); }
  .shop-card { padding: 12px; }
  .shop-card p { min-height: 0; }
  .blind-box-card { grid-template-columns: 1fr; }
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .spinner { animation: none; border-top-color: var(--primary); }
}
