:root {
  --bg: #0c0c0b; --bg2: #131311; --text: #ededdf; --dim: #8a8a7c; --accent: #ccff00; --line: #2a2a23;
  --display: "Archivo", system-ui, sans-serif; --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #16385f; color: var(--text); font: 14px/1.5 var(--mono); -webkit-font-smoothing: antialiased; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.card { background: rgba(12,12,11,.94); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(560px, 100%); backdrop-filter: blur(8px); }
#setup { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center; padding: 16px; overflow-y: auto; background: rgba(8,20,36,.55); }
#setup .card { margin: auto; }
#setup.is-off { display: none; }
.back { color: var(--dim); text-decoration: none; font-size: 12px; }
.back:hover { color: var(--accent); }
h1 { font: 900 clamp(34px, 8vw, 52px)/1 var(--display); letter-spacing: -.02em; margin: 10px 0 6px; }
h1::first-letter { color: var(--accent); }
.sub { color: var(--dim); margin-bottom: 18px; }
.sub b { color: var(--text); }
.lab { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin-bottom: 4px; }
.row { display: flex; gap: 8px; }
.row--end { justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
input[type=text], select { width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; }
input[type=text]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; font: 500 13px var(--mono); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--go { background: var(--accent); color: #0c0c0b; border-color: var(--accent); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chips button { background: none; border: 1px solid var(--line); color: var(--dim); border-radius: 99px; padding: 3px 10px; font: 12px var(--mono); cursor: pointer; }
.chips button:hover { color: var(--accent); border-color: var(--accent); }
.grid3 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.preview { position: relative; margin-top: 14px; background: #16385f; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
#preview { width: 100%; height: auto; aspect-ratio: 1; display: block; image-rendering: pixelated; max-height: 46vh; object-fit: contain; margin: 0 auto; }
.status { position: absolute; left: 8px; right: 8px; bottom: 8px; background: rgba(12,12,11,.85); border-radius: 6px; padding: 5px 9px; font-size: 12px; color: var(--text); }
.status.err { color: #ff8a7a; }
.fine { margin-top: 14px; font-size: 11px; color: var(--dim); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.pill { position: absolute; top: 10px; left: 10px; background: rgba(12,12,11,.85); color: var(--text); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; font: 12px var(--mono); cursor: pointer; }
#hint { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #0c0c0b; font-weight: 700; padding: 8px 16px; border-radius: 99px; pointer-events: none; text-align: center; max-width: 92vw; }
#hint:empty { display: none; }
#toasts { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; width: min(420px, 70vw); }
.toast { background: rgba(12,12,11,.88); border: 1px solid var(--line); padding: 5px 12px; border-radius: 8px; font-size: 12px; animation: fade 4.5s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
#board:empty { display: none; }
#board { position: absolute; top: 10px; right: 10px; width: 210px; background: rgba(12,12,11,.85); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 11px; }
#board .hd { display: flex; justify-content: space-between; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; font-size: 10px; margin-bottom: 4px; }
#board .r { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 6px; align-items: center; padding: 1px 0; }
#board .r.me { color: var(--accent); font-weight: 700; }
#board .sw { width: 10px; height: 10px; border-radius: 2px; }
#board .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .tr { color: var(--dim); }
#attacks { position: absolute; left: 10px; top: 52px; display: flex; flex-direction: column; gap: 4px; }
#attacks button { background: rgba(12,12,11,.85); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font: 11px var(--mono); cursor: pointer; text-align: left; }
#attacks button:hover { border-color: #ff6b5a; }
#bar { position: absolute; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; background: rgba(12,12,11,.92); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; max-width: calc(100vw - 16px); }
.stat { display: flex; flex-direction: column; min-width: 64px; }
.stat span, .ratio span { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); }
.stat b { font: 700 16px var(--display); }
.ratio { display: flex; flex-direction: column; width: 120px; }
.ratio b { color: var(--accent); }
.ratio input { width: 100%; accent-color: var(--accent); }
.build, .speed button { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: 500 12px var(--mono); cursor: pointer; }
.build small { color: var(--dim); margin-left: 4px; }
.build:disabled { opacity: .4; }
.build.on, .speed button.on { background: var(--accent); color: #0c0c0b; border-color: var(--accent); }
.build.on small { color: #0c0c0b; }
.speed { display: flex; gap: 4px; }
.speed button { padding: 7px 8px; }

#end { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); padding: 16px; }
.card--end h2 { font: 900 38px/1.1 var(--display); margin-bottom: 8px; }
.card--end p { color: var(--dim); }
.attrib { position: fixed; right: 6px; bottom: 4px; font-size: 10px; background: rgba(255,255,255,.7); color: #333; padding: 1px 6px; border-radius: 4px; z-index: 5; }
.attrib a { color: #1a4a8a; }
@media (max-width: 700px) {
  #board { width: 150px; font-size: 10px; }
  #board .tr { display: none; }
  #board .r { grid-template-columns: 10px 1fr auto; }
}
