:root {
  --bg: #05070d;
  --panel: #0e1a2e;
  --panel2: #142640;
  --edge: #8fb4e8;
  --text: #eef4ff;
  --dim: #8a9ab8;
  --accent: #f0b030;
  --team: #3466d6;
  --font: 'Press Start 2P', ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
body { -webkit-font-smoothing: none; user-select: none; }
.hidden { display: none !important; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; }

/* ---------------- Title ---------------- */
#title-bg { position: absolute; inset: 0; width: 100%; height: 100%; }
#title-content { position: relative; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; padding: 16px; }
.logo { text-align: center; filter: drop-shadow(0 4px 0 #000); }
.logo-halo { font-size: clamp(48px, 11vw, 112px); letter-spacing: .18em; color: #dfe8f4;
  background: linear-gradient(#ffffff 0%, #c8d4e4 45%, #7f8ea8 55%, #dfe8f4 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.logo-sub { margin-top: 10px; font-size: clamp(12px, 2.6vw, 24px); letter-spacing: .3em; color: var(--accent); text-shadow: 3px 3px 0 #5a2a00; }
.title-menu { display: flex; flex-direction: column; gap: 10px; min-width: min(360px, 100%); }
.title-foot { position: absolute; bottom: 12px; left: 16px; right: 16px; text-align: center; font-size: 8px; color: var(--dim); line-height: 1.6; }
.btn { font-family: var(--font); font-size: 12px; color: var(--text); background: linear-gradient(#1c3358, #0e1a2e); border: 3px solid var(--edge);
  border-radius: 6px; padding: 12px 16px; cursor: pointer; text-align: left; box-shadow: 0 4px 0 #000; position: relative; }
.btn:hover, .btn.sel { background: linear-gradient(#2c5aa0, #18305a); color: #fff; }
.btn.sel::before, .btn:hover::before { content: '▶'; position: absolute; left: -22px; color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn small { display: block; margin-top: 6px; font-size: 8px; color: var(--dim); line-height: 1.5; }

/* ---------------- Board ---------------- */
#play { display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, #0d1626 0%, #05070d 70%); }
#board-wrap { position: relative; }
#board { display: block; box-shadow: 0 0 0 4px #000, 0 0 0 7px #34445e, 0 12px 40px #000; cursor: none; }
#help-strip { margin-top: 18px; display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; font-size: 8px; color: var(--dim); padding: 0 16px; }
#help-strip b { color: var(--text); }

.panel { background: linear-gradient(var(--panel2), var(--panel)); border: 3px solid var(--edge); border-radius: 6px; box-shadow: 0 3px 0 #000, inset 0 0 0 2px #000; }
.hud { position: absolute; pointer-events: none; transition: opacity .15s; }
#hud-co { top: 8px; left: 8px; display: flex; gap: 8px; padding: 6px 10px 6px 6px; align-items: center; border-color: var(--team); }
#hud-co.right { left: auto; right: 8px; }
#hud-co canvas { width: 48px; height: 48px; border: 2px solid #000; border-radius: 3px; }
#hud-co .co-name { font-size: 9px; margin-bottom: 6px; }
#hud-co .funds { font-size: 11px; color: var(--accent); margin-bottom: 6px; }
#hud-co .meter { display: flex; gap: 2px; }
#hud-co .star { width: 12px; height: 12px; clip-path: polygon(50% 0, 63% 35%, 100% 38%, 71% 61%, 80% 100%, 50% 78%, 20% 100%, 29% 61%, 0 38%, 37% 35%); background: #2a3348; position: relative; overflow: hidden; }
#hud-co .star i { position: absolute; left: 0; bottom: 0; top: 0; background: var(--accent); }
#hud-co .power-on { font-size: 8px; color: #ff7; animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .3; } }

#hud-info { bottom: 8px; left: 8px; display: flex; gap: 6px; }
#hud-info.right { left: auto; right: 8px; }
.card { width: 84px; padding: 6px; text-align: center; font-size: 8px; line-height: 1.5; }
.card canvas { width: 48px; height: 48px; display: block; margin: 2px auto 4px; }
.card .nm { font-size: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .stat { display: flex; justify-content: space-between; color: var(--dim); }
.card .stat b { color: var(--text); font-weight: normal; }

#forecast { position: absolute; padding: 8px 10px; font-size: 9px; line-height: 1.7; pointer-events: none; white-space: nowrap; }
#forecast .big { font-size: 14px; color: var(--accent); }

.menu { position: absolute; padding: 6px; min-width: 150px; z-index: 5; }
.menu .mtitle { font-size: 8px; color: var(--dim); padding: 4px 6px 8px; }
.menu .item { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 10px; padding: 7px 8px 7px 22px; border-radius: 3px; cursor: pointer; position: relative; white-space: nowrap; }
.menu .item canvas { width: 32px; height: 32px; margin: -6px 6px -6px -4px; }
.menu .item .lbl { display: flex; align-items: center; flex: 1; }
.menu .item .rt { color: var(--accent); }
.menu .item.sel { background: #2c5aa0; }
.menu .item.sel::before { content: '▶'; position: absolute; left: 6px; color: var(--accent); font-size: 9px; }
.menu .item.off { opacity: .4; }
.menu .desc { font-size: 8px; color: var(--dim); padding: 8px 6px 2px; max-width: 260px; white-space: normal; line-height: 1.6; border-top: 2px solid #22334f; margin-top: 4px; }

#banner { position: absolute; left: 0; right: 0; top: 40%; transform: translateY(-50%); padding: 14px; text-align: center; font-size: 18px; letter-spacing: .1em;
  background: linear-gradient(90deg, transparent, var(--team) 20%, var(--team) 80%, transparent); text-shadow: 3px 3px 0 #000; animation: slidein .35s ease-out; z-index: 6; pointer-events: none; display: flex; align-items: center; justify-content: center; gap: 16px; }
#banner canvas { width: 64px; height: 64px; border: 3px solid #000; }
#banner small { display: block; font-size: 9px; margin-top: 8px; color: #fff8; letter-spacing: .05em; }
@keyframes slidein { from { transform: translate(-100%, -50%); } to { transform: translate(0, -50%); } }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 7; }

#battle { position: absolute; z-index: 8; border: 4px solid #000; box-shadow: 0 0 0 3px var(--edge), 0 10px 40px #000; cursor: pointer; }

/* ---------------- Dialog ---------------- */
#dialog { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(760px, calc(100% - 32px)); display: flex; gap: 12px; padding: 12px;
  background: linear-gradient(#18243a, #0b1220); border: 3px solid var(--edge); border-radius: 8px; box-shadow: 0 6px 0 #000; z-index: 20; cursor: pointer; }
#dialog-portrait { width: 96px; height: 96px; flex: none; border: 3px solid #000; border-radius: 4px; }
.dialog-body { flex: 1; position: relative; }
#dialog-name { font-size: 10px; color: var(--accent); margin-bottom: 10px; }
#dialog-text { font-size: 11px; line-height: 1.9; min-height: 64px; }
.dialog-next { position: absolute; right: 2px; bottom: -4px; font-size: 10px; color: var(--accent); animation: blink .7s steps(2) infinite; }

/* ---------------- Modal ---------------- */
#modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
#modal-box { max-width: min(860px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; }
#modal h2 { margin: 0 0 18px; font-size: 16px; color: var(--accent); letter-spacing: .08em; }
#modal h3 { font-size: 11px; margin: 18px 0 10px; color: #b8d0ff; }
#modal p, #modal li { font-size: 9px; line-height: 1.9; color: #d8e2f4; }
#modal ul { padding-left: 18px; margin: 6px 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.row .btn { flex: 1; min-width: 140px; text-align: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.opt { border: 3px solid #2a3c5c; border-radius: 6px; padding: 10px; cursor: pointer; background: #0c1626; font-size: 9px; line-height: 1.6; display: flex; gap: 10px; align-items: flex-start; }
.opt:hover { border-color: #5a7cb8; }
.opt.sel { border-color: var(--accent); background: #1a2a48; }
.opt canvas { width: 48px; height: 48px; flex: none; border: 2px solid #000; }
.opt .t { font-size: 10px; margin-bottom: 4px; }
.opt .d { color: var(--dim); font-size: 8px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { font-family: var(--font); font-size: 9px; padding: 8px 10px; background: #0c1626; color: var(--text); border: 3px solid #2a3c5c; border-radius: 4px; cursor: pointer; }
.seg button.sel { border-color: var(--accent); background: #1a2a48; }
.mission { display: flex; gap: 14px; align-items: center; }
.mission .lock { color: var(--dim); }
table.intel { border-collapse: collapse; font-size: 9px; width: 100%; }
table.intel td, table.intel th { padding: 6px 8px; border-bottom: 2px solid #1d2c48; text-align: left; line-height: 1.6; }
table.intel th { color: var(--dim); font-weight: normal; }
.dmgtable td { text-align: center !important; }

@media (max-width: 600px) {
  #help-strip { display: none; }
  .card { width: 70px; }
  #dialog-portrait { width: 64px; height: 64px; }
  #dialog-text { font-size: 9px; }
}

.sym { font-family: system-ui, -apple-system, 'Segoe UI Symbol', sans-serif; font-size: 1.15em; letter-spacing: 0; }
.card .sym { font-size: 12px; line-height: 1; }

/* ---------------- Online ---------------- */
#hud-co .pname { font-size: 8px; color: var(--dim); margin: -2px 0 6px; }
#net-status { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 9; padding: 8px 12px; font-size: 8px; line-height: 1.6;
  background: #3a1010e8; border: 2px solid #f86; border-radius: 4px; pointer-events: none; text-align: center; max-width: 80%; }
#chat { position: absolute; left: 8px; bottom: 120px; z-index: 9; display: flex; flex-direction: column; gap: 4px; pointer-events: none; max-width: 60%; }
.chat-line { font-size: 9px; line-height: 1.6; padding: 6px 8px; background: #0b1220e0; border: 2px solid #34445e; border-radius: 4px; transition: opacity 1s; }
.chat-line.fade { opacity: 0; }
.field { font-family: var(--font); font-size: 12px; padding: 10px; width: 100%; background: #0c1626; color: var(--text); border: 3px solid #2a3c5c; border-radius: 4px; outline: none; }
.field:focus { border-color: var(--accent); }
.code { font-size: 28px; letter-spacing: .3em; color: var(--accent); margin: 8px 0 14px; }
.share { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.share .field { flex: 1; min-width: 200px; font-size: 9px; }
.room { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.room .btn { flex: none; padding: 8px 12px; font-size: 9px; }
.muted { color: var(--dim); font-size: 9px; line-height: 1.8; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.quick button { font-family: var(--font); font-size: 9px; padding: 8px 10px; background: #0c1626; color: var(--text); border: 2px solid #2a3c5c; border-radius: 4px; cursor: pointer; }
.quick button:hover { border-color: var(--accent); }
.linkbtn { background: none; border: none; color: var(--accent); font-family: inherit; font-size: inherit; cursor: pointer; text-decoration: underline; padding: 0; }

/* HUD scales with the board */
:root { --hud: 1; }
#hud-co { transform: scale(var(--hud)); transform-origin: top left; }
#hud-co.right { transform-origin: top right; }
#hud-info { transform: scale(var(--hud)); transform-origin: bottom left; }
#hud-info.right { transform-origin: bottom right; }
