:root {
  --bg: #12151c; --panel: #1c212c; --panel2: #232a38; --line: #343c4e; --text: #ece6d6; --dim: #a9a595;
  --brass: #d6a94a; --brass2: #f0cf7a; --nord: #4b79b6; --nord-d: #2a4a7c; --syd: #8d8f8a; --syd-d: #5a5c58;
  --good: #58c05a; --bad: #d4483a;
  --serif: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--serif); overflow: hidden; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; }

/* ---------- generiske kontroller (alle med eget tema) ---------- */
button, input, select { font-family: var(--serif); font-size: 15px; color: var(--text); }
button {
  background: #2c3446; border: 1px solid #46506a; border-radius: 6px; padding: 7px 12px; cursor: pointer; color: var(--brass2);
  transition: background .12s, border-color .12s, transform .05s;
}
button:hover:not(:disabled) { background: #36405a; border-color: var(--brass); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .42; cursor: not-allowed; }
button.primary { background: linear-gradient(#e0b64f, #b78a2a); border-color: #f2d27c; color: #22190a; font-weight: 700; }
button.primary:hover:not(:disabled) { background: linear-gradient(#f0c85f, #c99a32); border-color: #fff0b0; }
button.primary.big { padding: 11px 18px; font-size: 17px; width: 100%; }
button.linkbtn { background: none; border: none; color: var(--brass2); text-decoration: underline; padding: 2px 4px; }
button.linkbtn:hover:not(:disabled) { background: none; color: #fff; }
input, select {
  background: #141923; border: 1px solid #46506a; border-radius: 6px; padding: 8px 10px; color: var(--text); width: 100%;
}
input::placeholder { color: #6f7487; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23d6a94a' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px;
}
select option { background: #141923; color: var(--text); }
#in-name, #in-code, #wait-link, #chat-in, #sel-timer { background-color: #141923; color: var(--text); border-color: #46506a; }
#btn-create, #btn-join, #btn-copy, #btn-ready { color: #22190a; }
#btn-help, #btn-music-l, #btn-leave-w, #b-leave { color: var(--brass2); }
#b-sfx, #b-mus, #b-help { background: #2c3446; color: var(--brass2); padding: 5px 9px; font-size: 13px; }
#b-sfx.off, #b-mus.off { color: #7d8294; text-decoration: line-through; }
#chat-form button { background: #2c3446; color: var(--brass2); }
.tabs button { background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--dim); }
.tabs button.on { color: var(--brass2); border-bottom-color: var(--brass); }

/* ---------- lobby ---------- */
#lobby, #wait {
  display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, #26324a 0%, #12151c 70%);
}
#lobby::before, #wait::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background: linear-gradient(90deg, rgba(75,121,182,.28) 0 50%, rgba(141,143,138,.22) 50% 100%);
  mask-image: radial-gradient(ellipse at 50% 50%, transparent 25%, #000 100%); -webkit-mask-image: radial-gradient(ellipse at 50% 50%, transparent 25%, #000 100%);
}
.lobby-card { position: relative; width: min(760px, 100%); background: rgba(28,33,44,.94); border: 1px solid #4a5370; border-radius: 14px; padding: 26px 30px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.title-wrap { text-align: center; margin-bottom: 6px; }
h1 { margin: 0; font-size: 54px; letter-spacing: 6px; font-weight: 700; color: var(--brass2); text-shadow: 0 3px 0 #5a4310, 0 6px 18px rgba(0,0,0,.6); }
h1 span { color: #fff; font-size: 40px; }
.sub { letter-spacing: 5px; text-transform: uppercase; color: var(--dim); font-size: 13px; margin-top: 2px; }
.tag { text-align: center; color: var(--dim); margin: 12px 0 18px; }
.fld { display: block; font-size: 13px; color: var(--dim); margin-bottom: 12px; }
.fld > input, .fld > select, .fld > .seg { margin-top: 5px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.box { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 16px; }
.box h3 { margin: 0 0 10px; color: var(--brass2); font-weight: 600; }
.seg { display: flex; }
.segbtn { flex: 1; border-radius: 0; padding: 7px 4px; background: #1a2030; color: var(--dim); }
.segbtn:first-child { border-radius: 6px 0 0 6px; } .segbtn:last-child { border-radius: 0 6px 6px 0; }
.segbtn.on { background: var(--brass); color: #22190a; border-color: #f2d27c; font-weight: 700; }
.segbtn.nord.on { background: var(--nord); color: #fff; border-color: #8fb4ec; } .segbtn.syd.on { background: var(--syd); color: #111; border-color: #d1d3cb; }
#in-code { text-transform: uppercase; letter-spacing: 8px; font-size: 24px; text-align: center; }
.lobby-msg { min-height: 22px; text-align: center; color: #ff9d8f; margin-top: 12px; }
.lobby-foot { text-align: center; margin-top: 6px; color: var(--dim); }
.bigcode { font-size: 76px; letter-spacing: 16px; text-align: center; color: var(--brass2); font-weight: 700; margin: 4px 0 14px; padding-left: 16px; text-shadow: 0 4px 0 #5a4310; }
.linkrow { display: flex; gap: 8px; margin-bottom: 14px; } .linkrow input { flex: 1; } .linkrow button { width: auto; white-space: nowrap; }
.spinner { width: 34px; height: 34px; margin: 10px auto; border: 4px solid #3a435a; border-top-color: var(--brass); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#wait .lobby-card { text-align: center; }

/* ---------- spilskærm ---------- */
#game { display: flex; }
#mapwrap { position: relative; flex: 1; min-width: 0; background: #0e1118; overflow: hidden; }
#map { display: block; position: absolute; left: 0; top: 0; }
#side { width: 384px; background: var(--panel); border-left: 2px solid #3d465e; overflow-y: auto; display: flex; flex-direction: column; padding: 10px 12px 8px; gap: 9px; }
.hdr { display: flex; justify-content: space-between; align-items: center; }
.date { font-size: 24px; color: var(--brass2); text-transform: capitalize; font-weight: 700; }
.turn { color: var(--dim); font-size: 13px; }
.hdr-btns { display: flex; gap: 5px; }
.players { display: flex; flex-direction: column; gap: 6px; }
.pl { border-radius: 8px; padding: 7px 10px; border: 1px solid var(--line); background: var(--panel2); display: grid; grid-template-columns: 1fr auto; gap: 0 8px; align-items: center; }
.pl.N { border-left: 6px solid var(--nord); } .pl.S { border-left: 6px solid var(--syd); }
.pl .nm { font-weight: 700; } .pl .nm small { color: var(--dim); font-weight: 400; }
.pl .gd { text-align: right; color: var(--brass2); font-weight: 700; }
.pl .gd small { display: block; color: var(--dim); font-weight: 400; font-size: 11px; }
.pl .st { grid-column: 1 / 3; font-size: 12px; color: var(--dim); margin-top: 2px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #666; margin-right: 5px; }
.dot.on { background: var(--good); } .dot.off { background: var(--bad); }
.ok { color: var(--good); }
.timer { display: flex; align-items: center; gap: 8px; }
.timer .bar { flex: 1; height: 9px; background: #0f121a; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.timer .bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #e0b64f, #f2d27c); transition: width .25s linear; }
.timer.low .bar i { background: var(--bad); }
#ttxt { min-width: 62px; text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); }
.panel { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 14px; }
.panel:empty { display: none; }
.panel h4 { margin: 0 0 6px; color: var(--brass2); font-size: 15px; }
.panel .muted { color: var(--dim); font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.row > span.grow { flex: 1; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; margin-right: 4px; background: #333b4f; color: var(--text); }
.chip.N { background: var(--nord-d); } .chip.S { background: var(--syd-d); } .chip.X { background: #7a6a30; }
.units { display: inline-flex; gap: 10px; align-items: center; }
.units b { color: #fff; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { padding: 2px 9px; font-size: 16px; line-height: 1.2; }
.stepper span { min-width: 24px; text-align: center; font-weight: 700; }
.nbrs { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.nbrs button { padding: 3px 8px; font-size: 12.5px; }
.nbrs button.enemy { border-color: #b34a3d; color: #ffb3a8; } .nbrs button.free { border-color: #4a9d5b; color: #b4f0c0; }
.orders { list-style: none; margin: 0; padding: 0; }
.orders li { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 1px dashed #343c4e; }
.orders li:last-child { border-bottom: none; }
.orders li .x { padding: 0 7px; font-size: 14px; }
.actions { margin: 2px 0; }
#btn-ready.waiting { background: linear-gradient(#5b6a86, #3d4960); color: #fff; border-color: #8fa0c4; }
.score { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: 12px; text-align: center; color: var(--dim); }
.score div { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 2px; }
.score b { display: block; color: var(--text); font-size: 14px; } .score .n { color: #8fb4ec; } .score .s { color: #cfd1c9; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button .badge { background: var(--bad); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.log, .chat { flex: 1; min-height: 110px; overflow-y: auto; font-size: 13px; background: #161b25; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.log .t { color: var(--dim); font-size: 11px; margin-right: 4px; } .log div { padding: 2px 0; border-bottom: 1px dotted #2b3345; }
.chat { display: flex; flex-direction: column; padding: 0; }
#chat-msgs { flex: 1; overflow-y: auto; padding: 6px 8px; } #chat-msgs div { padding: 2px 0; } #chat-msgs b.N { color: #8fb4ec; } #chat-msgs b.S { color: #d6d8d0; }
#chat-form { display: flex; gap: 4px; padding: 6px; border-top: 1px solid var(--line); }
.foot { display: flex; justify-content: space-between; align-items: center; color: var(--dim); font-size: 12px; }
.code { letter-spacing: 3px; font-weight: 700; color: var(--dim); }

.tip { position: absolute; z-index: 5; pointer-events: none; background: rgba(15,18,26,.95); border: 1px solid var(--brass); border-radius: 8px; padding: 7px 10px; font-size: 13px; max-width: 250px; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
.tip b { color: var(--brass2); }
.banner { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 6; background: rgba(15,18,26,.95); border: 1px solid var(--brass); border-radius: 10px; padding: 10px 16px; max-width: 70%; box-shadow: 0 8px 24px rgba(0,0,0,.6); cursor: pointer; font-size: 14px; }
.banner h4 { margin: 0 0 4px; color: var(--brass2); } .banner div { padding: 1px 0; }
.phasebar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6; background: rgba(15,18,26,.92); border: 1px solid #5d6785; border-radius: 22px; padding: 7px 20px; font-size: 15px; }
.conn { position: absolute; left: 0; right: 0; top: 0; z-index: 9; background: #8a2a1f; text-align: center; padding: 6px; color: #fff; }

/* ---------- overlays (slag / duel) ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: #000; }
.stage { position: absolute; inset: 0; } .stage canvas { display: block; }
.btop { position: absolute; left: 0; right: 0; top: 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; padding: 10px 18px; background: linear-gradient(rgba(0,0,0,.72), rgba(0,0,0,0)); align-items: start; }
.bside b { font-size: 20px; } .bside.N b { color: #8fb4ec; } .bside.S { text-align: right; } .bside.S b { color: #d6d8d0; }
.hpbar { height: 14px; background: rgba(0,0,0,.55); border: 1px solid #667; border-radius: 7px; overflow: hidden; margin: 3px 0; }
.hpbar i { display: block; height: 100%; width: 100%; transition: width .3s; } .bside.N .hpbar i { background: linear-gradient(#78a4e0, #3e69a8); } .bside.S .hpbar i { background: linear-gradient(#cfd1c9, #8d8f8a); float: right; }
.bside small { color: #ccc; }
.bmid { text-align: center; } .bmid b { display: block; font-size: 20px; color: var(--brass2); text-shadow: 0 2px 6px #000; } #b-time { font-size: 24px; font-variant-numeric: tabular-nums; }
.bctl { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 16px 14px; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.82)); display: flex; gap: 10px; justify-content: center; align-items: stretch; flex-wrap: wrap; }
.gcard { background: rgba(24,28,38,.92); border: 2px solid #46506a; border-radius: 10px; padding: 7px 10px; min-width: 200px; cursor: pointer; }
.gcard.sel { border-color: var(--brass); box-shadow: 0 0 12px rgba(214,169,74,.5); }
.gcard h5 { margin: 0 0 4px; font-size: 14px; color: var(--brass2); display: flex; justify-content: space-between; }
.gcard .mini { height: 6px; background: #0f121a; border-radius: 3px; overflow: hidden; margin-bottom: 6px; } .gcard .mini i { display: block; height: 100%; background: var(--good); }
.stances { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.stances button { padding: 5px 2px; font-size: 12px; background: #2c3446; color: #d8d3c0; }
.stances button.on { background: var(--brass); color: #22190a; border-color: #f2d27c; font-weight: 700; }
.stances button small { display: block; font-size: 9px; opacity: .7; }
.gen { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.gen button { padding: 4px 10px; font-size: 12.5px; }
.resbanner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); text-align: center; padding: 20px 46px; background: rgba(10,12,18,.88); border: 2px solid var(--brass); border-radius: 14px; box-shadow: 0 12px 40px #000; }
.resbanner h2 { margin: 0 0 6px; font-size: 40px; color: var(--brass2); } .resbanner p { margin: 4px 0; font-size: 17px; }
.dtop { position: absolute; left: 0; right: 0; top: 0; padding: 10px 18px; background: linear-gradient(rgba(0,0,0,.72), rgba(0,0,0,0)); display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; }
.dtop .hp { height: 18px; background: rgba(0,0,0,.6); border: 1px solid #778; border-radius: 9px; overflow: hidden; } .dtop .hp i { display: block; height: 100%; }
.dtop .r { text-align: right; } .dtop .r .hp i { float: right; }
.dtop .nm { font-size: 18px; font-weight: 700; } .dtop .mid { text-align: center; min-width: 260px; } .dtop .mid .tm { font-size: 30px; color: var(--brass2); font-variant-numeric: tabular-nums; }
.track { position: relative; height: 10px; background: rgba(0,0,0,.55); border: 1px solid #778; border-radius: 5px; margin-top: 4px; } .track i { position: absolute; top: -5px; width: 14px; height: 18px; margin-left: -7px; border-radius: 4px; background: var(--brass2); border: 1px solid #000; } .track em { position: absolute; right: -3px; top: -9px; font-style: normal; font-size: 16px; }
.dhint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(10,12,18,.8); border: 1px solid #555d78; border-radius: 18px; padding: 6px 18px; font-size: 14px; color: #d8d3c0; white-space: nowrap; }

/* ---------- modal + toast ---------- */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(5,7,12,.72); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.modal-card { background: var(--panel); border: 2px solid var(--brass); border-radius: 14px; padding: 20px 26px; width: min(640px, 100%); max-height: 94vh; overflow: auto; box-shadow: 0 20px 60px #000; }
.modal-card h2 { margin: 0 0 4px; color: var(--brass2); } .modal-card h3 { color: var(--brass2); margin: 14px 0 4px; }
.modal-card p, .modal-card li { line-height: 1.45; } .modal-card ul { padding-left: 20px; margin: 4px 0; }
.modal-card .btns { display: flex; gap: 10px; margin-top: 16px; } .modal-card .btns button { flex: 1; padding: 10px; font-size: 16px; }
.vs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; margin: 12px 0; }
.vs .army { background: var(--panel2); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); text-align: center; }
.vs .army.N { border-top: 5px solid var(--nord); } .vs .army.S { border-top: 5px solid var(--syd); }
.vs .army h4 { margin: 0 0 4px; } .vs .vsx { font-size: 26px; color: var(--brass2); }
.keys kbd { background: #2c3446; border: 1px solid #55607c; border-bottom-width: 3px; border-radius: 5px; padding: 1px 7px; font-family: var(--serif); }
.modal-card .center { text-align: center; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast div { background: rgba(18,21,30,.97); border: 1px solid var(--brass); color: var(--text); padding: 9px 18px; border-radius: 22px; box-shadow: 0 8px 24px rgba(0,0,0,.6); animation: pop .2s; }
.toast div.err { border-color: var(--bad); color: #ffc7bf; }
@keyframes pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 900px) {
  #game { flex-direction: column; } #side { width: 100%; height: 52%; border-left: none; border-top: 2px solid #3d465e; }
  .cols { grid-template-columns: 1fr; } h1 { font-size: 38px; }
}
