/* Tank Craft: felt-tip on graph paper. Wobbly hand-drawn borders (uneven border-radius), Bangers for shouting,
   Patrick Hand for everything else. */
:root {
    --paper: #fbf7ec; --grid: rgba(70, 110, 190, .16); --ink: #26283b; --muted: #6b6d80;
    --red: #e2433b; --blue: #2f80ed; --yellow: #ffd23f; --green: #3bb273; --orange: #ff8a00;
    --wob: 255px 15px 225px 15px / 15px 225px 15px 255px;
    --wob2: 15px 255px 15px 225px / 225px 15px 255px 15px;
    --hand: 'Patrick Hand', 'Comic Sans MS', system-ui, sans-serif;
    --shout: 'Bangers', 'Patrick Hand', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overscroll-behavior: none; }
body {
    font-family: var(--hand); color: var(--ink); font-size: 18px; line-height: 1.35;
    background-color: var(--paper);
    background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 24px 24px;
    -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { min-height: 100%; padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.topbar h2 { font-family: var(--shout); font-size: 34px; letter-spacing: .04em; font-weight: 400; }
.link { text-decoration: underline; text-underline-offset: 4px; padding: 8px 4px; font-size: 19px; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 6px 18px;
    background: #fff; border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 3px 4px 0 var(--ink);
    font-size: 20px; transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translate(3px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn.big { min-height: 62px; font-size: 26px; width: 100%; }
.btn.small { min-height: 40px; padding: 4px 10px; font-size: 18px; box-shadow: 2px 3px 0 var(--ink); }
.btn.primary { background: var(--yellow); }
.btn.danger { background: #ffd6d2; }
.btn.on { background: #cfe3ff; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ── menu ── */
.menu-wrap { max-width: 460px; margin: 0 auto; display: grid; gap: 14px; justify-items: center; text-align: center; padding-top: 2vh; }
.logo { font-family: var(--shout); font-weight: 400; line-height: .85; font-size: clamp(64px, 18vw, 110px); letter-spacing: .03em; transform: rotate(-4deg); }
.logo span { display: block; color: var(--yellow); -webkit-text-stroke: 3px var(--ink); text-shadow: 5px 6px 0 var(--ink); }
.logo span + span { color: var(--red); margin-left: .5em; }
.tag { font-size: 22px; color: var(--muted); margin-top: -4px; }
.menu-tank { display: grid; justify-items: center; padding: 8px 18px 10px; background: #fff; border: 3px solid var(--ink); border-radius: var(--wob2); box-shadow: 4px 5px 0 var(--ink); }
.menu-tank canvas { width: 150px; height: 150px; }
.menu-tank b { font-size: 24px; } .menu-tank small { color: var(--muted); }
.name-row { display: flex; gap: 8px; align-items: center; font-size: 20px; }
.name-row input, #ed-name, #join-code { padding: 6px 12px; border: 3px solid var(--ink); border-radius: var(--wob2); background: #fff; width: 180px; }
.menu-buttons { display: grid; gap: 12px; width: 100%; }

/* ── garage ── */
.section { font-family: var(--shout); font-weight: 400; font-size: 24px; letter-spacing: .04em; margin: 10px 0 8px; }
.tank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tank-card { position: relative; display: grid; justify-items: center; gap: 2px; padding: 8px 8px 10px; background: #fff; border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 3px 4px 0 var(--ink); text-align: center; }
.tank-card.active { background: #fff6cc; }
.tank-card canvas { width: 120px; height: 120px; }
.tank-card b { font-size: 20px; } .tank-card small { color: var(--muted); font-size: 15px; }
.tank-card .card-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
.tank-card .badge { position: absolute; top: 6px; left: 8px; font-size: 14px; background: var(--yellow); border: 2px solid var(--ink); border-radius: 10px; padding: 0 6px; }

/* ── editor ── */
#editor { display: grid; grid-template-rows: auto 1fr auto; height: 100%; padding-bottom: max(6px, env(safe-area-inset-bottom)); gap: 6px; }
.ed-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#ed-name { width: 150px; }
#ed-hue { width: 90px; accent-color: var(--red); }
.ed-main { display: grid; grid-template-columns: 1fr 250px; gap: 8px; min-height: 0; }
#ed-canvas { width: 100%; height: 100%; min-height: 0; border: 3px solid var(--ink); border-radius: 12px; background: var(--paper); touch-action: none; }
.ed-side { display: grid; align-content: start; gap: 8px; overflow: auto; }
.budget { position: relative; height: 34px; border: 3px solid var(--ink); border-radius: var(--wob2); background: #fff; overflow: hidden; }
.budget .bar { position: absolute; inset: 0; width: var(--p, 0%); background: var(--green); transition: width .2s; }
.budget .bar.over { background: var(--red); }
.budget b { position: relative; display: block; text-align: center; line-height: 28px; font-size: 20px; }
.weight { position: relative; height: 30px; border: 2px solid var(--ink); border-radius: var(--wob); background: #fff; overflow: hidden; }
.weight i { position: absolute; inset: 0; width: var(--p, 50%); background: var(--green); transition: width .2s; }
.weight.medium i { background: var(--yellow); } .weight.heavy i { background: var(--orange); }
.weight span { position: relative; display: block; text-align: center; line-height: 26px; font-size: 16px; white-space: nowrap; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 18px; }
.errors { color: var(--red); font-size: 17px; }
.hint { color: var(--blue); font-size: 17px; }
.tools { display: grid; gap: 6px; padding: 8px; border: 2px dashed var(--ink); border-radius: 12px; background: rgba(255,255,255,.7); }
.part-name { font-size: 17px; }
.palette { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: thin; }
.palette button { flex: none; display: grid; justify-items: center; width: 66px; padding: 4px 2px; background: #fff; border: 2px solid var(--ink); border-radius: var(--wob2); box-shadow: 2px 3px 0 var(--ink); }
.palette button span { font-size: 24px; line-height: 1.1; }
.palette button small { font-size: 14px; }
.palette button.body { background: #e7f0ff; }
.palette button.gun { background: #f0e9ff; }
.palette button.on { background: var(--yellow); }
@media (max-width: 760px) {
    .ed-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
    .ed-side { max-height: 30vh; }
    #ed-name { width: 110px; }
}
@media (max-height: 520px) and (orientation: landscape) {
    .ed-main { grid-template-columns: 1fr 230px; grid-template-rows: none; }
    .ed-side { max-height: none; }
    .btn.small { min-height: 34px; padding: 2px 8px; font-size: 16px; }
}

/* ── setup screens ── */
.setup { max-width: 520px; margin: 0 auto; display: grid; gap: 14px; }
.choice { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.choice button { display: grid; gap: 2px; padding: 10px 6px; background: #fff; border: 3px solid var(--ink); border-radius: var(--wob); font-size: 22px; box-shadow: 3px 4px 0 var(--ink); }
.choice button small { font-size: 15px; color: var(--muted); }
.choice button.on { background: #cfe3ff; }
.field { display: flex; align-items: center; gap: 10px; font-size: 21px; }
.field input[type=range] { flex: 1; accent-color: var(--red); }
.field.check { font-size: 20px; flex-wrap: wrap; gap: 6px 10px; } .field.check input { width: 26px; height: 26px; accent-color: var(--red); } .field.check small { color: var(--muted); font-size: 16px; flex-basis: 100%; margin-left: 36px; }
.zone-warn { position: absolute; bottom: calc(max(10px, env(safe-area-inset-bottom)) + 40px); left: 50%; transform: translateX(-50%); padding: 6px 16px; background: var(--red); color: #fff; border: 3px solid var(--ink); border-radius: var(--wob2); font-size: 22px; pointer-events: none; animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55; } }
.field select { padding: 4px 10px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; }
.note { font-size: 19px; }
#join-code { width: 120px; text-transform: uppercase; }
.room-line { font-size: 21px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.lobby-list { list-style: none; display: grid; gap: 8px; }
.lobby-list li { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: #fff; border: 2px solid var(--ink); border-radius: var(--wob2); }
.lobby-list canvas { width: 46px; height: 46px; }
.lobby-list b { flex: 1; } .lobby-list small { color: var(--muted); }

/* ── battle ── */
#game { position: fixed; inset: 0; padding: 0; overflow: hidden; touch-action: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-btn { width: 44px; height: 44px; font-size: 22px; background: #fff; border: 3px solid var(--ink); border-radius: var(--wob2); box-shadow: 2px 3px 0 var(--ink); }
.score { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 70vw; }
.score span { padding: 2px 10px; background: rgba(255,255,255,.9); border: 2px solid var(--ink); border-radius: var(--wob2); font-size: 18px; }
.score span.me { background: #fff6cc; }
.feed { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 54px); right: max(10px, env(safe-area-inset-right)); display: grid; gap: 4px; justify-items: end; pointer-events: none; }
.feed p { padding: 1px 10px; background: rgba(255,255,255,.85); border: 2px solid var(--ink); border-radius: 10px; font-size: 16px; animation: feed 5s forwards; }
@keyframes feed { 80% { opacity: 1; } 100% { opacity: 0; } }
.banner { position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) rotate(-3deg); font-family: var(--shout); font-size: clamp(40px, 9vw, 80px); color: var(--yellow); -webkit-text-stroke: 3px var(--ink); text-shadow: 4px 5px 0 var(--ink); pointer-events: none; white-space: nowrap; animation: pop .4s; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.4) rotate(-12deg); } }
.hud-hp { position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; pointer-events: none; }
.hp { width: min(36vw, 240px); height: 20px; border: 3px solid var(--ink); border-radius: var(--wob2); background: #fff; overflow: hidden; }
.hp i { display: block; height: 100%; width: var(--p, 100%); background: var(--green); transition: width .15s; }
.hp.low i { background: var(--red); }
.hud-hp b { font-size: 18px; text-shadow: 0 0 4px #fff; }
.stick { position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); width: 150px; height: 150px; border: 3px dashed rgba(38,40,59,.5); border-radius: 50%; background: rgba(255,255,255,.35); touch-action: none; }
.knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border: 3px solid var(--ink); border-radius: 50%; background: #fff; box-shadow: 2px 3px 0 var(--ink); pointer-events: none; }
.right-pad { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; }
.fire { width: 110px; height: 110px; border-radius: 50%; background: var(--red); color: #fff; font-family: var(--shout); font-size: 32px; letter-spacing: .05em; border: 4px solid var(--ink); box-shadow: 3px 5px 0 var(--ink); -webkit-text-stroke: 1px var(--ink); touch-action: none; }
.fire.down { transform: translate(3px, 5px); box-shadow: 0 0 0 var(--ink); }
.spin { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 6px; background: rgba(255,255,255,.85); border: 2px solid var(--ink); border-radius: 14px; text-align: center; }
.spin small { font-size: 14px; grid-column: 1 / -1; }
.spin button { min-width: 54px; padding: 4px 6px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; font-size: 16px; }
.spin button.on { background: var(--yellow); }
@media (hover: hover) and (pointer: fine) { .stick { opacity: .5; } }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(251,247,236,.5); }
.overlay .card { display: grid; gap: 10px; justify-items: center; min-width: 280px; max-width: 92vw; max-height: 86vh; overflow: auto; padding: 16px 22px; background: #fff; border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 5px 6px 0 var(--ink); text-align: center; }
.overlay h2 { font-family: var(--shout); font-weight: 400; font-size: 40px; letter-spacing: .04em; }
#dead { background: transparent; pointer-events: none; place-items: start center; padding-top: 18vh; }
#res-table { border-collapse: collapse; font-size: 19px; }
#res-table td, #res-table th { padding: 3px 12px; border-bottom: 2px dashed rgba(38,40,59,.25); }
#res-table tr.win td { background: #fff6cc; }

.how { max-width: 560px; margin: auto; padding: 18px 22px; border: 3px solid var(--ink); border-radius: var(--wob); background: var(--paper); color: var(--ink); box-shadow: 6px 7px 0 var(--ink); }
.how::backdrop { background: rgba(38,40,59,.35); }
.how h2 { font-family: var(--shout); font-weight: 400; font-size: 36px; }
.how ol { display: grid; gap: 8px; margin: 10px 0 10px 1.2em; }
.how form { text-align: right; margin-top: 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 8px 16px; background: var(--ink); color: #fff; border-radius: 12px; font-size: 19px; z-index: 50; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
