:root {
  color-scheme: dark;
  --ink: #111b18;
  --panel: #17251f;
  --panel-2: #21342a;
  --green: #56a93f;
  --green-bright: #82d84f;
  --gold: #f2b532;
  --cream: #f6f0d8;
  --muted: #b8c8bc;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #09120e;
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
button, canvas { -webkit-tap-highlight-color: transparent; }

#game-root {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  overflow: hidden; background: #102416;
  box-shadow: 0 0 80px rgba(0, 0, 0, .68);
}
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }
.sound-toggle {
  position: absolute; top: 72px; right: 12px; z-index: 32;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  color: #183018; background: #f2c642; border: 2px solid #fff0a0;
  font: 1000 23px/1 system-ui, sans-serif; box-shadow: 0 5px 16px rgba(0,0,0,.4);
}
.sound-toggle:hover { background: #ffda59; }
.sound-toggle:active { transform: translateY(2px); }
.sound-toggle.muted { color: #c7d1c9; background: #2a3931; border-color: #728178; }

#overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 18px; background: rgba(6, 14, 10, .76); z-index: 20;
}
#overlay-card {
  width: min(390px, 94%); max-height: min(88vh, 720px); overflow: auto;
  color: var(--cream); background: rgba(19, 31, 25, .97);
  border: 2px solid rgba(122, 205, 78, .55); border-radius: 22px;
  padding: 24px; text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .48), inset 0 0 0 1px rgba(255, 255, 255, .06);
  scrollbar-width: thin; scrollbar-color: var(--green) var(--panel);
}
#overlay-card.wide { width: min(860px, 96%); }
#overlay-card h1 { font-size: 28px; margin-bottom: 8px; }
#overlay-card h2 { font-size: 27px; line-height: 1.05; margin: 4px 0 12px; }
#overlay-card h3 { margin: 20px 0 9px; font-size: 17px; text-align: left; color: #ddedcf; }
#overlay-card p { color: var(--muted); margin: 7px 0 16px; font-size: 14px; line-height: 1.45; }

.game-logo { display: block; width: min(320px, 92%); height: 166px; object-fit: contain; margin: -24px auto -10px; }
.player-portrait { display: block; width: 100%; height: 330px; object-fit: contain; object-position: center bottom; }
.start-layout { display: grid; grid-template-columns: minmax(220px, .85fr) minmax(320px, 1.15fr); align-items: end; gap: 18px; }
.start-art { align-self: stretch; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.start-content { padding: 4px 10px 6px; }
.lead { font-size: 15px !important; color: #d6e5d6 !important; }
.control-note {
  margin: 10px 0 16px; padding: 11px 12px; border-radius: 12px;
  background: #102018; color: #aebfb2; font-size: 12px; line-height: 1.5;
  border: 1px solid rgba(126, 190, 89, .25);
}
.control-note b { color: #e6f2dd; }
.unlock-note, .claimed-note, .ad-note, .status-note, .ad-busy {
  margin: 8px 0; color: #b8c8bc; font-size: 12px; line-height: 1.35;
}
.ad-note { color: #e6c975; }
.status-note { color: #a8eb83; font-weight: 700; }

.btn {
  display: block; width: 100%; min-height: 46px; margin: 9px 0; padding: 11px 15px;
  font: 800 15px/1.2 system-ui, sans-serif; color: #eff8e8;
  background: #2a4937; border: 1px solid rgba(157, 220, 114, .25); border-radius: 13px;
  cursor: pointer; box-shadow: 0 5px 0 rgba(7, 15, 10, .45);
}
.btn:hover { background: #355e43; }
.btn:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(7, 15, 10, .45); }
.btn.primary { color: #182012; background: var(--gold); border-color: #ffe17c; }
.btn.primary:hover { background: #ffc94b; }
.btn.secondary { background: #294438; }
.btn.reward-btn { color: #163118; background: #77c84c; border-color: #b4ef83; font-size: 13px; }
.btn.text-btn { min-height: 40px; color: #9eb1a3; background: transparent; border-color: transparent; box-shadow: none; }
.btn:disabled { color: #6e7f72; background: #27302b; border-color: #38433c; cursor: default; box-shadow: none; transform: none; }

.eyebrow { color: #8ed45c; font-size: 11px; font-weight: 900; letter-spacing: .11em; text-transform: uppercase; }
.complete-badge {
  display: inline-block; padding: 6px 10px; margin-bottom: 5px; border-radius: 999px;
  color: #173016; background: #8bd15b; font-size: 11px; font-weight: 900; text-transform: uppercase;
}
.reward { color: #ffd45a; }

.shop-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; text-align: left; }
.coin-badge {
  display: flex; align-items: center; gap: 8px; min-width: 108px; padding: 7px 11px;
  border-radius: 999px; background: #101d17; border: 1px solid rgba(237, 190, 69, .45); color: #ffe075;
}
.coin-small { width: 30px; height: 30px; object-fit: contain; }
.shop-explain { text-align: left; max-width: 650px; }
.shop-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.shop-row {
  display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 10px;
  min-width: 0; padding: 11px; text-align: left; background: #1d3026;
  border: 1px solid rgba(130, 202, 70, .2); border-radius: 15px;
}
.shop-icon { width: 58px; height: 58px; object-fit: contain; grid-row: span 2; }
.shop-icon.tool { filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .35)); }
.shop-row .info { min-width: 0; }
.shop-row .name { font-size: 14px; font-weight: 900; color: #eff7ea; }
.shop-row .name span { color: #86be6a; font-size: 11px; white-space: nowrap; }
.shop-row .desc { margin-top: 3px; color: #9eafa2; font-size: 11px; line-height: 1.3; }
.shop-row .shop-buy { grid-column: 1 / -1; margin: 2px 0 0; min-height: 38px; padding: 8px; font-size: 12px; }

#touch-ui { position: absolute; inset: 0; pointer-events: none; z-index: 10; display: none; }
body.touch #touch-ui { display: block; }

.joystick {
  pointer-events: auto; position: absolute;
  left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom));
  width: 132px; height: 132px; border-radius: 50%; touch-action: none;
  background: rgba(12, 29, 20, .58); border: 3px solid rgba(174, 231, 126, .55);
  box-shadow: 0 9px 28px rgba(0, 0, 0, .34), inset 0 0 0 2px rgba(255,255,255,.04);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.joystick-guide {
  position: absolute; inset: 24px; border-radius: 50%;
  border: 2px dashed rgba(218, 244, 192, .20); pointer-events: none;
}
.joystick-guide::before, .joystick-guide::after {
  content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(225, 246, 204, .13); border-radius: 999px;
}
.joystick-guide::before { width: 64px; height: 2px; }
.joystick-guide::after { width: 2px; height: 64px; }
.joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%; background: rgba(83, 151, 66, .94); border: 3px solid rgba(224, 250, 194, .82);
  box-shadow: 0 5px 13px rgba(0,0,0,.34), inset 0 2px 5px rgba(255,255,255,.13);
  pointer-events: none; transform: translate3d(0,0,0); will-change: transform;
}

.touch-btn {
  pointer-events: auto; position: absolute; width: 88px; height: 88px; border-radius: 50%;
  border: 3px solid rgba(255, 235, 145, .72); background: rgba(30, 58, 39, .82); color: #fff1b0;
  font-size: 11px; font-weight: 900; touch-action: none; user-select: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .38);
}
.touch-btn:active, .touch-menu-btn:active { transform: scale(.95); }
#btn-action { right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); }

.touch-menu-btn {
  pointer-events: auto; position: absolute;
  left: max(10px, env(safe-area-inset-left)); top: max(128px, calc(env(safe-area-inset-top) + 122px));
  min-width: 58px; height: 42px; padding: 0 10px; border-radius: 13px;
  border: 2px solid rgba(174, 231, 126, .54); background: rgba(15, 34, 24, .88); color: #eef8e8;
  font: 900 10px/1 system-ui, sans-serif; letter-spacing: .04em; touch-action: none; user-select: none;
  box-shadow: 0 5px 16px rgba(0,0,0,.34);
}

.test-result { text-align: left; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre-wrap; }

@media (max-width: 720px), (max-height: 600px) {
  #overlay { padding: 10px; }
  #overlay-card, #overlay-card.wide { width: min(520px, 96%); max-height: 92%; padding: 17px; border-radius: 17px; }
  .start-layout { grid-template-columns: 1fr; gap: 0; }
  .start-art { display: none; }
  .game-logo { height: 126px; margin: -20px auto -5px; }
  .control-note { margin: 7px 0 10px; padding: 8px; }
  .shop-grid { grid-template-columns: 1fr; }
  .shop-row { grid-template-columns: 52px 1fr auto; }
  .shop-icon { width: 48px; height: 48px; grid-row: auto; }
  .shop-row .shop-buy { grid-column: auto; width: auto; min-width: 98px; margin: 0; }
  .sound-toggle { top: 128px; }
}

@media (max-width: 420px) {
  #overlay-card, #overlay-card.wide { padding: 14px; }
  #overlay-card h2 { font-size: 23px; }
  .game-logo { height: 105px; }
  .lead { font-size: 13px !important; margin-bottom: 9px !important; }
  .control-note { font-size: 10px; }
  .btn { min-height: 43px; margin: 7px 0; font-size: 14px; }
  .shop-head { align-items: flex-start; }
  .shop-row { grid-template-columns: 45px 1fr; }
  .shop-row .shop-buy { grid-column: 1 / -1; width: 100%; }
  .shop-icon { width: 42px; height: 42px; }
  .sound-toggle { top: 128px; right: 8px; width: 40px; height: 40px; font-size: 21px; }
}

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


@media (max-width: 480px) {
  .joystick { width: 118px; height: 118px; }
  .joystick-guide { inset: 22px; }
  .joystick-knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
  .touch-btn { width: 82px; height: 82px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .joystick { width: 100px; height: 100px; bottom: max(10px, env(safe-area-inset-bottom)); }
  .joystick-guide { inset: 19px; }
  .joystick-knob { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
  .touch-btn { width: 72px; height: 72px; bottom: max(10px, env(safe-area-inset-bottom)); }
  .touch-menu-btn { top: max(70px, calc(env(safe-area-inset-top) + 64px)); }
}
