:root {
  --bg: #101116; --panel: rgba(16, 17, 22, 0.94); --line: rgba(255, 255, 255, 0.12);
  --text: #f2f2f2; --dim: rgba(255, 255, 255, 0.62); --faint: rgba(255, 255, 255, 0.45);
  --gold: #f1c40f; --red: #c0392b; --blue: #2e86de; --green: #7bed9f; --bad: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-tap-highlight-color: transparent; user-select: none; }
canvas#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
[hidden] { display: none !important; }

button { font: inherit; font-weight: 600; color: var(--text); background: #2a2c35; border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 12px; min-height: 40px; cursor: pointer; }
button:hover:not(:disabled) { background: #343743; }
button:disabled { opacity: 0.4; cursor: default; }
button.gold { background: var(--gold); color: #111; border-color: transparent; }
button.gold:hover:not(:disabled) { background: #ffd83b; }
button.red { background: var(--red); border-color: transparent; }
button.blue { background: var(--blue); border-color: transparent; }
button.green { background: #16a085; border-color: transparent; }
button.on { outline: 2px solid var(--gold); }
input, select { font: inherit; color: var(--text); background: #1d1f26; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; }
input[type=range] { padding: 0; height: 32px; accent-color: var(--gold); background: none; border: 0; }

#bar { position: fixed; top: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5; }
#bar .logo { font-weight: 900; letter-spacing: 1px; color: var(--gold); font-size: 20px; }
#bar .grow { flex: 1; }
#bar button { min-height: 36px; padding: 6px 11px; }

#info { position: fixed; z-index: 4; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  left: 8px; right: 8px; bottom: max(22px, env(safe-area-inset-bottom)); max-height: 58vh; overflow: auto; }
#info h2 { margin: 0 24px 2px 0; font-size: 19px; }
#info .x { position: absolute; top: 6px; right: 6px; min-height: 0; padding: 2px 9px; background: none; border: 0; font-size: 20px; color: var(--faint); }
.sub { color: var(--dim); font-size: 13px; }
.hint { color: var(--faint); font-size: 13px; margin-top: 8px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.row > button { flex: 1; }
.big { font-size: 16px; margin-top: 6px; }
.odds { font-weight: 700; }

#toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); max-width: calc(100vw - 16px); z-index: 20;
  background: rgba(0, 0, 0, 0.82); padding: 10px 14px; border-radius: 10px; text-align: center; font-size: 16px; font-weight: 600;
  opacity: 0; transition: opacity 0.5s; pointer-events: none; }
#toast.show { opacity: 1; transition: opacity 0.1s; }

#overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 10; display: flex; align-items: center; justify-content: center; padding: 10px; }
#overlay.solid { background: #101116f2; }
#modal { background: #17181e; border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; width: min(560px, 100%);
  max-height: calc(100vh - 20px); overflow: auto; position: relative; }
#modal h1 { margin: 0 0 8px; font-size: 22px; }
#modal .x { position: absolute; top: 8px; right: 8px; background: none; border: 0; font-size: 22px; color: var(--faint); min-height: 0; }
#modal hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.title { text-align: center; font-size: 56px; font-weight: 900; color: var(--gold); letter-spacing: 2px; margin: 4px 0 0; line-height: 1; }
.tag { text-align: center; color: var(--dim); margin: 10px 0 14px; }
label.f { display: block; color: var(--dim); font-size: 13px; margin: 12px 0 5px; }
.swatches { display: flex; gap: 8px; }
.swatches button { flex: 1; height: 42px; }

/* crew list */
.fighter { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.fighter .nm { font-weight: 700; }
.fighter .lv { font-size: 12px; color: #111; background: var(--gold); border-radius: 6px; padding: 1px 6px; margin-right: 6px; font-weight: 800; }
.fighter .meta { color: var(--dim); font-size: 13px; grid-column: 1; }
.fighter .act { grid-row: 1 / span 3; grid-column: 2; display: flex; gap: 4px; align-items: center; }
.fighter .act button { min-height: 32px; padding: 4px 8px; font-size: 13px; }
.xpbar { height: 4px; background: #2a2c35; border-radius: 2px; overflow: hidden; grid-column: 1; margin-top: 3px; }
.xpbar i { display: block; height: 100%; background: var(--gold); }
.ranks { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.ranks span { background: #23252d; border-radius: 6px; padding: 2px 7px; font-size: 13px; }

/* clans */
.clan { padding: 10px 0; border-top: 1px solid var(--line); }
.clan .hd { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.clan .sw { width: 16px; height: 16px; border-radius: 4px; }
.log p { margin: 6px 0; }
.k-big { color: #feca57; } .k-war { color: #ff8a80; } .k-peace { color: var(--green); } .k-turf { color: var(--dim); }

/* battle */
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.plans button { min-height: 64px; text-align: left; }
.plans small { display: block; font-weight: 400; color: var(--dim); font-size: 12px; }
.vs { display: flex; justify-content: space-between; gap: 10px; margin: 8px 0; }
.vs div { flex: 1; background: #1f2128; border-radius: 10px; padding: 8px 10px; }
.vs b { font-size: 22px; display: block; }
.res { font-size: 26px; font-weight: 900; text-align: center; margin: 6px 0; }
.list { font-size: 14px; color: var(--dim); }
.list b { color: var(--text); }

#attrib { position: fixed; right: 6px; bottom: 3px; font-size: 10px; color: rgba(255, 255, 255, 0.45); z-index: 3; pointer-events: none; }

@media (min-aspect-ratio: 21/20) {
  #info { left: 12px; right: auto; top: 70px; bottom: auto; width: min(380px, 40vw); max-height: calc(100vh - 90px); }
}
@media (max-aspect-ratio: 21/20) {
  #bar .wide { display: none; }
  #bar .logo { display: none; }
}

/* battle screen */
canvas#battle { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 30; touch-action: none; display: block; image-rendering: pixelated; background: #000; }
#battle-floats { position: fixed; inset: 0; pointer-events: none; z-index: 32; overflow: hidden; }
#battle-floats .float { position: absolute; left: 0; top: 0; font-weight: 900; font-size: 15px; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; white-space: nowrap; }
#battle-ui { position: fixed; inset: 0; z-index: 31; pointer-events: none; }
#battle-ui > * { pointer-events: auto; }
.bh-top { position: absolute; top: max(6px, env(safe-area-inset-top)); left: 6px; right: 6px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: start; pointer-events: none; }
.bh-team { background: rgba(10, 11, 15, 0.82); border-left: 4px solid; border-radius: 8px; padding: 5px 8px; font-size: 12px; }
.bh-team:last-child { border-left: 0; border-right: 4px solid; text-align: right; }
.bh-name { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bh-count { color: var(--dim); }
.bh-bar { height: 5px; background: #2a2c35; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bh-bar i { display: block; height: 100%; transition: width 0.3s; }
.bh-team:last-child .bh-bar i { margin-left: auto; }
.bh-title { background: rgba(10, 11, 15, 0.82); border-radius: 8px; padding: 6px 8px; font-size: 12px; font-weight: 700; text-align: center; max-width: 34vw; }
.bh-bottom { position: absolute; left: 6px; right: 6px; bottom: max(8px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.bh-plans, .bh-ctrl { display: flex; gap: 5px; pointer-events: auto; }
.bh-plans button, .bh-ctrl button { flex: 1; min-height: 40px; padding: 6px 4px; background: rgba(30, 32, 40, 0.9); font-size: 14px; }
.bh-plans button.on, .bh-ctrl button.on { outline: 2px solid var(--gold); color: var(--gold); }
.bh-ctrl button.gold { background: var(--gold); color: #111; }
.bh-ctrl button.red { background: var(--red); }
.bh-feed { position: absolute; left: 8px; top: 72px; font-size: 13px; font-weight: 700; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000; pointer-events: none; max-width: 70vw; }
.bh-feed div { transition: opacity 1s; }
.bh-feed div.old { opacity: 0; }
.bh-banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none; opacity: 0; transform: scale(0.8); transition: opacity 0.25s, transform 0.25s; text-shadow: 3px 3px 0 #000; }
.bh-banner.show { opacity: 1; transform: none; }
.bh-banner b { display: block; font-size: 52px; font-weight: 900; letter-spacing: 2px; }
.bh-banner span { display: block; font-size: 16px; color: #fff; font-weight: 700; }
.plans button:last-child:nth-child(odd) { grid-column: span 2; }
.bh-plans button { font-size: 13px; }

.rosters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; max-height: 26vh; overflow: auto; }
.roster { border-left: 3px solid; padding-left: 6px; font-size: 13px; }
.roster div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster .lv { display: inline-block; min-width: 18px; text-align: center; font-size: 11px; color: #111; background: var(--gold); border-radius: 5px; font-weight: 800; }
#modal .list { margin-top: 4px; }
