* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --navy: #102044;
  --ink: #17213c;
  --cream: #fff8df;
  --gold: #ffc94a;
  --green: #5dce72;
  --blue: #4e83ff;
  --panel: rgba(255,255,255,.94);
}
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  color: var(--ink);
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  background: radial-gradient(circle at 15% 10%, #3b71cd 0, transparent 30%), linear-gradient(145deg, #112145, #254d87 58%, #3f79a5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .2;
  background-image: linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 24px 24px;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; border: 0; }
button:active { transform: translateY(2px) scale(.98); }
.game-shell { height: 100%; max-width: 1240px; margin: auto; padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 12px; }
.topbar { min-height: 68px; display: flex; align-items: center; justify-content: space-between; color: white; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: clamp(22px, 3vw, 34px); line-height: 1; letter-spacing: -.03em; }
.brand p { margin: 5px 0 0; opacity: .76; font-size: 13px; font-weight: 700; }
.brand-block { width: 42px; height: 42px; background: var(--gold); border-radius: 8px; box-shadow: inset -7px -7px 0 #e5a72b, 0 5px 0 rgba(5,17,43,.4); position: relative; }
.brand-block::after { content: ""; position: absolute; width: 20px; height: 20px; left: 28px; top: 22px; background: #ff8f4a; border-radius: 5px; box-shadow: inset -4px -4px 0 #d86a31; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.time-panel { min-height: 45px; display: flex; align-items: center; gap: 8px; padding: 5px 11px; border: 1px solid rgba(255,255,255,.25); border-radius: 12px; color: white; background: rgba(5,18,47,.34); box-shadow: inset 0 1px rgba(255,255,255,.14); }
.time-panel > span { font-size: 22px; }
.time-panel strong, .time-panel small { display: block; white-space: nowrap; }
.time-panel strong { font-size: 11px; letter-spacing: .12em; }
.time-panel small { margin-top: 2px; font-size: 8px; font-weight: 850; letter-spacing: .07em; opacity: .72; }
.time-panel .builder-level { color: #ffd76a; opacity: 1; }
.music-button { min-height: 45px; padding: 0 13px; border: 1px solid rgba(255,255,255,.25); border-radius: 12px; color: white; background: rgba(5,18,47,.34); box-shadow: inset 0 1px rgba(255,255,255,.14); font-size: 10px; font-weight: 950; letter-spacing: .08em; }
.music-button[aria-pressed="false"] { color: #aebbd1; }
.stats { display: flex; gap: 10px; }
.stats > div { min-width: 100px; padding: 8px 15px; border: 1px solid rgba(255,255,255,.25); border-radius: 13px; background: rgba(5,18,47,.34); box-shadow: inset 0 1px rgba(255,255,255,.14); }
.stats .tower-stat { min-width: 138px; display: flex; align-items: flex-end; gap: 9px; }
.tower-preview { width: 24px; height: 35px; display: flex; flex-direction: column-reverse; gap: 1px; padding: 2px; border: 1px solid rgba(255,255,255,.32); border-radius: 4px 4px 1px 1px; background: rgba(4,13,34,.28); }
.tower-preview i { display: block; width: 100%; min-height: 2px; flex: 1 1 auto; border-radius: 1px; background: linear-gradient(90deg, #8997a7, #d3dae0 48%, #71808f); box-shadow: inset 0 -1px rgba(0,0,0,.28); }
.stat-label { display: block; font-size: 9px; letter-spacing: .14em; opacity: .68; }
.stats strong { font-size: 20px; }
.play-area { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(430px, 1fr) 320px; gap: 14px; }
.world-card, .control-card { border-radius: 22px; box-shadow: 0 17px 45px rgba(3,13,35,.33), inset 0 1px rgba(255,255,255,.7); overflow: hidden; }
.world-card { position: relative; background: linear-gradient(#91d8ff 0%, #c6edff 45%, #79c66b 45.3%, #4b8e50 100%); min-height: 0; }
#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
#gameCanvas:focus-visible { outline: 4px solid var(--gold); outline-offset: -5px; }
.control-card { background: var(--panel); padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.phase-heading h2 { margin: 8px 0 5px; font-size: 20px; line-height: 1.08; }
.phase-heading p { margin: 0; color: #63708c; font-family: system-ui, sans-serif; font-size: 12px; line-height: 1.35; }
.desktop-guide { display: none; }
.desktop-guide span { align-items: center; gap: 5px; color: #53617e; font-family: system-ui, sans-serif; font-size: 9px; }
.desktop-guide kbd { min-width: 44px; padding: 3px 5px; border: 1px solid #bcc6d8; border-bottom-width: 3px; border-radius: 5px; color: #273858; background: white; text-align: center; font: 800 9px system-ui, sans-serif; }
.desktop-guide b { font-weight: 700; }
.desktop-guide p { grid-column: 1 / -1; margin: 1px 0 0; color: #71809a; font: 10px/1.3 system-ui, sans-serif; }
.phase-badge { display: inline-flex; color: white; font-size: 10px; letter-spacing: .12em; font-weight: 900; padding: 5px 9px; border-radius: 6px; }
.phase-badge.drop { background: var(--blue); }
.phase-badge.build { background: #1e9a51; }
.next-delivery { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 11px; border: 1px solid #bac8e3; border-radius: 12px; background: linear-gradient(145deg, #f8fbff, #e7eefb); box-shadow: inset 0 1px white; }
.next-delivery span, .next-delivery strong { display: block; }
.next-delivery span { color: #72809b; font-size: 8px; font-weight: 950; letter-spacing: .13em; }
.next-delivery strong { margin-top: 3px; color: #263d69; font-size: 12px; }
.next-piece-preview { flex: 0 0 auto; display: grid; gap: 2px; min-width: 66px; min-height: 34px; place-content: center; padding: 3px; border-radius: 8px; background: rgba(31,54,94,.09); }
.next-piece-preview i { width: 15px; height: 15px; border-radius: 3px; }
.next-piece-preview i.filled { box-shadow: inset -4px -4px rgba(0,0,0,.2), inset 2px 2px rgba(255,255,255,.25); }
.score-guide { border: 1px solid #e2ce89; border-radius: 10px; color: #65531e; background: #fff8d9; font-family: system-ui, sans-serif; }
.score-guide summary { padding: 7px 10px; cursor: pointer; font-size: 9px; font-weight: 900; letter-spacing: .08em; }
.score-guide p { margin: 0; padding: 0 10px 6px; font-size: 9px; line-height: 1.3; }
.control-section { display: flex; flex-direction: column; gap: 10px; }
.button-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.game-button { min-height: 68px; border-radius: 14px; color: #23345d; background: #e7ecf7; box-shadow: inset 0 -4px #c6cfdf; display: grid; place-items: center; padding: 6px; }
.game-button.accent { background: #fff1bd; box-shadow: inset 0 -4px #edce68; }
.game-button span { font-size: 26px; line-height: 1; }
.game-button small { font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.wide-button, .primary-button { min-height: 54px; border-radius: 14px; background: linear-gradient(#ffcf54, #f2aa2f); color: #4e3311; font-weight: 950; letter-spacing: .04em; box-shadow: inset 0 -5px rgba(161,93,15,.25), 0 5px 10px rgba(100,65,16,.16); }
.wide-button.green { color: white; background: linear-gradient(#62d979, #2fa952); box-shadow: inset 0 -5px rgba(12,104,45,.28), 0 5px 10px rgba(16,105,47,.15); }
.energy-row { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 850; }
.energy-pips { display: flex; gap: 4px; }
.energy-pips i { display: block; width: 14px; height: 14px; background: #dce2ed; transform: rotate(45deg); border-radius: 3px; }
.energy-pips i.full { background: var(--gold); box-shadow: inset -3px -3px #dc9f25; }
.tool-switch { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; gap: 4px; border-radius: 13px; background: #e6ebf3; }
.tool-button { min-height: 45px; border-radius: 10px; color: #68748e; background: transparent; font-weight: 850; }
.tool-button.selected { color: #1e315a; background: white; box-shadow: 0 3px 8px rgba(34,52,84,.16); }
.tool-button.detonate.selected { color: #8e2222; background: #fff0e8; outline: 2px solid #df5a3e; }
.inventory-label { margin: 0; font-size: 10px; color: #7b8498; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.inventory { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.inventory-button { min-width: 0; padding: 6px 2px; border-radius: 10px; background: #edf0f5; color: #41506d; box-shadow: inset 0 -3px #d5dae3; }
.inventory-button.selected { outline: 3px solid var(--blue); background: white; }
.inventory-button:disabled { opacity: .42; }
.inventory-cube { width: 22px; height: 22px; display: block; margin: auto auto 3px; border-radius: 4px; box-shadow: inset -5px -5px rgba(0,0,0,.18), inset 3px 3px rgba(255,255,255,.2); }
.inventory-cube.special { height: 24px; background: none !important; box-shadow: none; font-size: 21px; line-height: 24px; }
.inventory-button small { display: block; font-size: 9px; text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inventory-button b { font-size: 11px; }
.golem-card { padding: 10px; border: 1px solid #d9c47a; border-radius: 12px; background: linear-gradient(145deg, #fff8da, #f3e8b7); color: #4b452e; font-family: system-ui, sans-serif; }
.golem-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.golem-heading span { font-size: 8px; font-weight: 900; letter-spacing: .11em; color: #8c7020; }
.golem-heading strong { font-size: 12px; }
.golem-body { display: flex; gap: 10px; align-items: center; margin-top: 7px; }
.golem-pattern { flex: 0 0 auto; display: grid; gap: 2px; padding: 4px; border-radius: 7px; background: rgba(66,52,20,.12); }
.golem-pattern i { width: 12px; height: 12px; border-radius: 2px; background: transparent; }
.golem-pattern i.filled { box-shadow: inset -3px -3px rgba(0,0,0,.2), inset 2px 2px rgba(255,255,255,.22); }
.golem-copy { min-width: 0; }
.golem-copy b { font-size: 11px; }
.golem-copy p, .golem-power { margin: 2px 0 0; font-size: 9px; line-height: 1.3; }
.golem-power { color: #78682d; }
.golem-button { width: 100%; min-height: 34px; margin-top: 7px; border-radius: 8px; color: white; background: linear-gradient(#8f7aff, #6554ce); box-shadow: inset 0 -3px rgba(35,25,116,.3); font-size: 9px; font-weight: 900; letter-spacing: .06em; }
.audio-mixer { border: 1px solid #d8deea; border-radius: 11px; background: #f4f7fb; color: #3e4e6e; font-family: system-ui, sans-serif; }
.audio-mixer summary { padding: 8px 10px; cursor: pointer; font-size: 11px; font-weight: 850; letter-spacing: .04em; }
.mixer-controls { display: grid; gap: 4px; padding: 0 10px 10px; }
.mixer-controls label { display: flex; justify-content: space-between; font-size: 10px; font-weight: 750; }
.mixer-controls output { color: #526da4; font-variant-numeric: tabular-nums; }
.mixer-controls input { width: 100%; accent-color: var(--blue); }
.tip-card { margin-top: auto; display: flex; gap: 9px; align-items: flex-start; padding: 10px; border-radius: 12px; background: #fff4c9; border: 1px solid #f0d984; }
.tip-card p { margin: 0; font-family: system-ui, sans-serif; font-size: 11px; line-height: 1.35; color: #6d591b; }
.bulb { font-size: 18px; }
.overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 20px; background: rgba(9,28,60,.76); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); }
.overlay-card { width: min(430px, 92%); text-align: center; padding: 28px; border-radius: 22px; background: var(--cream); box-shadow: 0 20px 60px rgba(0,0,0,.4), inset 0 2px white; }
.overlay-card h2 { margin: 8px 0; font-size: clamp(24px, 4vw, 36px); line-height: 1.02; }
.overlay-card p:not(.eyebrow) { color: #667089; font-family: system-ui, sans-serif; line-height: 1.45; }
.eyebrow { margin: 12px 0 0; color: #db732d; font-size: 10px; letter-spacing: .16em; font-weight: 950; }
.primary-button { width: 100%; margin-top: 8px; font-size: 17px; }
.hero-piece { display: grid; grid-template-columns: repeat(3, 24px); width: max-content; margin: 0 auto; transform: rotate(-5deg); }
.hero-piece i { width: 25px; height: 25px; background: #5fcf72; border: 2px solid #318a48; box-shadow: inset -5px -5px #3eaa58; }
.hero-piece i:first-child { grid-column: 2; }
.end-icon { font-size: 58px; }
.end-overlay { background: rgba(48,7,12,.82); }
.end-card { border: 4px solid #c83d3d; background: #fff3e8; box-shadow: 0 20px 65px rgba(27,0,3,.66), inset 0 2px white; }
.end-card .eyebrow { color: #a62b2b; }
.end-card h2 { color: #8d1919; font-size: clamp(38px, 6vw, 58px); letter-spacing: .035em; text-shadow: 0 2px white; }
.end-card .end-reason { margin: 8px 0 15px; color: #49292c; font-weight: 800; }
.end-results { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 12px 0; }
.end-results span { padding: 11px 7px; border: 2px solid #e1c0a4; border-radius: 11px; background: #fffaf3; }
.end-results small, .end-results strong { display: block; }
.end-results small { color: #8a6d5b; font: 850 9px/1.2 system-ui, sans-serif; letter-spacing: .1em; }
.end-results strong { margin-top: 4px; color: #3b2c2a; font-size: 18px; }
.danger-button { color: white; background: linear-gradient(#e95b4f, #b92f31); box-shadow: inset 0 -5px rgba(90,7,10,.28), 0 5px 10px rgba(100,16,16,.2); }
.toast { position: absolute; left: 50%; top: 14px; z-index: 3; transform: translate(-50%, -15px); opacity: 0; padding: 8px 14px; color: white; background: rgba(19,36,72,.88); border-radius: 999px; font-size: 12px; font-weight: 850; pointer-events: none; transition: .22s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.hazard-alert { position: absolute; z-index: 4; top: 14px; right: 14px; padding: 9px 12px; border: 2px solid #ffd067; border-radius: 11px; color: #fff4c2; background: rgba(117,29,14,.92); box-shadow: 0 5px 18px rgba(39,5,0,.35); font-size: 11px; font-weight: 950; letter-spacing: .08em; animation: emberPulse .9s ease-in-out infinite alternate; }
@keyframes emberPulse { to { transform: scale(1.035); box-shadow: 0 5px 24px rgba(255,99,31,.52); } }
.hidden { display: none !important; }
.orientation-hint { display: none; }
body[data-world-time="night"] { background: radial-gradient(circle at 78% 8%, #344b88 0, transparent 25%), linear-gradient(145deg, #050a20, #101d46 58%, #25395f); }
body[data-world-time="night"] .control-card { background: rgba(234,240,255,.96); box-shadow: 0 17px 45px rgba(0,0,0,.52), inset 0 1px white; }
body[data-world-time="night"] .world-card { background: linear-gradient(#07112e, #182750 52%, #263d3b 52.3%, #142d29); }
body[data-world-time="night"] .time-panel { border-color: rgba(151,183,255,.5); background: rgba(2,7,28,.58); box-shadow: 0 0 16px rgba(127,158,255,.18), inset 0 1px rgba(255,255,255,.12); }
@media (hover: hover) and (pointer: fine) {
  .desktop-guide { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; padding: 9px; border: 1px solid #d8deea; border-radius: 11px; background: #f4f7fb; }
  .desktop-guide span { display: flex; }
}
@media (pointer: coarse) and (max-width: 760px), (pointer: coarse) and (orientation: portrait) {
  .orientation-hint { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; padding: 30px; text-align: center; color: white; background: #132751; font-weight: 850; }
}
@media (max-height: 650px) and (orientation: landscape) {
  .game-shell { padding-top: 7px; padding-bottom: 7px; gap: 7px; }
  .topbar { min-height: 50px; }
  .brand-block { width: 34px; height: 34px; }
  .brand p { display: none; }
  .stats > div { padding: 5px 12px; }
  .play-area { grid-template-columns: minmax(420px, 1fr) 290px; gap: 9px; }
  .control-card { padding: 10px; gap: 7px; }
  .desktop-guide { display: none; }
  .phase-heading h2 { font-size: 17px; margin: 5px 0 3px; }
  .phase-heading p { font-size: 10px; }
  .control-section { gap: 7px; }
  .game-button { min-height: 55px; }
  .wide-button { min-height: 44px; }
  .tip-card { padding: 7px; }
}
