:root {
  color-scheme: dark;
  --bg: #121826;
  --panel: #1b2334;
  --panel-2: #222d42;
  --line: #33415c;
  --text: #e8edf7;
  --muted: #94a3bd;
  --accent: #e0b84a;
  --danger: #e06c6c;
  --ok: #69c58a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  font-size: 14px;
  overflow: hidden;
}
button, input, select { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.section-title { margin: 18px 0 8px; font-weight: 700; color: var(--accent); }

.login-screen { height: 100%; display: grid; place-items: center; background: radial-gradient(circle at 50% 0%, #243151, #121826 70%); }
.login-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr); gap: 14px; width: min(1220px, 96vw); max-height: 94vh; }
.login-card {
  min-width: 0; max-height: 94vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; box-shadow: 0 18px 60px rgba(0,0,0,.45);
}
.login-side { min-width: 0; max-height: 94vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: 0 18px 60px rgba(0,0,0,.45); }
.login-side .section-title { margin-top: 0; }
.login-side .scenario-picker { grid-template-columns: 1fr; }
.side-note { margin-top: 14px; font-size: 11px; line-height: 1.6; }
.login-card h1 { margin: 0 0 4px; font-size: 28px; color: var(--accent); }
.subtitle { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; margin: 14px 0 4px; color: var(--muted); }
.password-row { display: flex; gap: 8px; align-items: stretch; }
.password-row input { flex: 1; min-width: 0; }
.password-row .btn { flex: 0 0 auto; }
.full { width: 100%; }
#change-scenario-btn { margin-top: 12px; }
input, select {
  width: 100%; padding: 9px 11px; border-radius: 7px;
  border: 1px solid var(--line); background: #101725; color: var(--text); outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.status { font-size: 12px; color: var(--muted); }
.scenario-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.scenario-card {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; cursor: pointer;
  background: var(--panel-2); transition: .12s;
}
.scenario-card:hover { border-color: var(--accent); }
.scenario-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.scenario-year { color: var(--accent); font-size: 11px; font-weight: 700; }
.scenario-name { font-weight: 700; margin: 2px 0 4px; }
.scenario-desc { color: var(--muted); font-size: 11px; line-height: 1.45; }
.scenario-goals { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; color: #d9c38f; font-size: 10px; }
.scenario-meta { color: var(--muted); font-size: 10px; margin-top: 6px; }
.error { color: var(--danger); font-size: 12px; line-height: 1.6; background: #3a2027; border: 1px solid #7a3a45; border-radius: 8px; padding: 10px; }
.faction-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.character-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; max-height: 300px; overflow: auto; padding-right: 3px; }
.character-card {
  display: grid; grid-template-columns: 62px 1fr; gap: 10px; align-items: center; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px;
  transition: .12s;
}
.character-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.character-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.character-name b { font-size: 14px; }
.character-role { color: var(--muted); font-size: 10px; margin: 3px 0; }
.character-stats { color: var(--accent); font-size: 10px; }
.character-tags { display: flex; gap: 5px; margin-top: 5px; }
.tag { font-size: 9px; padding: 1px 6px; border-radius: 8px; background: #34405a; color: var(--text); }
.tag.ruler { background: #7a5a1e; color: #ffe6a6; }
.tag.legend { background: #58406d; }
.tag.disputed { background: #6c4b34; }
.tag.fictional { background: #3c4a5e; color: #c8d4e6; }
.character-preview {
  display: flex; gap: 14px; align-items: center; margin-top: 12px; padding: 12px;
  border: 1px solid var(--accent); border-radius: 10px; background: #202a3e;
}
.preview-portrait { flex: 0 0 auto; }
.preview-title { font-size: 18px; font-weight: 700; color: var(--accent); }
.preview-note { color: var(--muted); font-size: 11px; line-height: 1.5; margin-top: 6px; }
.faction-card {
  border: 1px solid var(--line); border-radius: 9px; padding: 12px; cursor: pointer;
  background: var(--panel-2); transition: .12s;
}
.faction-card:hover { border-color: var(--accent); }
.faction-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.faction-card .name { font-weight: 700; }
.faction-card .desc { color: var(--muted); font-size: 11px; margin-top: 5px; line-height: 1.4; }
.faction-card .taken { color: var(--danger); font-size: 11px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

.portrait-frame {
  display: inline-block; width: var(--portrait-size, 64px); height: var(--portrait-size, 64px);
  flex: 0 0 auto; border-radius: 9px; overflow: hidden; border: 1px solid #6b5330;
  background: #1b2334; box-shadow: 0 2px 8px rgba(0,0,0,.35); vertical-align: middle;
  position: relative;
}
.portrait-sprite {
  display: block; width: 100%; height: 100%;
  background-image: var(--sprite-url); background-repeat: no-repeat;
  background-size: 400% 100%; background-position: 0% 0;
  animation: sprite-idle 1.8s linear infinite; animation-delay: var(--sprite-delay, 0s);
  filter: sepia(.08) saturate(.95) contrast(1.02);
}
#tab-officers .portrait-sprite { animation: none; }
.officer-portrait {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  z-index: 1; pointer-events: none;
  filter: sepia(.08) saturate(.95) contrast(1.02);
}
.officer-portrait.missing { display: none; }
.portrait-seal {
  position: absolute; left: 4px; bottom: 3px; max-width: 70%; z-index: 2;
  font-size: calc(var(--portrait-size, 64px) * .12); line-height: 1.2;
  color: #fff3d0; background: rgba(24, 18, 10, .58); border-radius: 3px; padding: 1px 3px;
  font-family: Georgia, 'Noto Serif KR', serif; pointer-events: none;
}
@keyframes sprite-idle {
  0%, 24.999% { background-position: 0% 0; }
  25%, 49.999% { background-position: 33.333% 0; }
  50%, 74.999% { background-position: 66.667% 0; }
  75%, 100% { background-position: 100% 0; }
}
@media (prefers-reduced-motion: reduce) { .portrait-sprite { animation: none; background-position: 0% 0; } }
.message { min-height: 20px; margin-top: 10px; color: var(--danger); }
.version-badge { display: inline-block; margin-left: 6px; padding: 2px 7px; border-radius: 10px; background: #34405a; color: #f0d48a; font-size: 11px; font-weight: 600; vertical-align: middle; letter-spacing: .3px; }
.network-info { margin-top: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: rgba(255,255,255,.03); color: var(--muted); font-size: 11px; line-height: 1.8; }
.network-info b { color: #f0d48a; font-weight: 600; }
.help { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.6; }
.secure-note { margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--accent); background: rgba(240,212,138,.08); color: #f0d48a; font-size: 11px; line-height: 1.6; border-radius: 4px; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 7px; padding: 9px 14px; cursor: pointer; transition: .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); background: #2b3852; }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.tiny { padding: 5px 9px; font-size: 12px; }
.btn.small { padding: 6px 10px; font-size: 12px; }

.game-screen { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.game-screen .topbar { padding-right: 360px; }
.brand { font-size: 18px; font-weight: 800; color: var(--accent); white-space: nowrap; cursor: pointer; }
.brand:hover { text-shadow: 0 0 10px rgba(240,212,138,.45); }
.brand span { color: var(--text); font-size: 13px; font-weight: 400; }
.you-badge { display: flex; align-items: center; gap: 8px; padding-right: 14px; border-right: 1px solid var(--line); }
.you-meta { display: flex; flex-direction: column; line-height: 1.25; }
.you-meta b { font-size: 13px; color: var(--accent); }
.you-meta span { font-size: 10px; color: var(--muted); }
.date-info { font-weight: 700; }
.turn-info { color: var(--muted); flex: 1; display: inline-flex; align-items: center; flex-wrap: nowrap; gap: 8px; min-width: 0; white-space: nowrap; }
.turn-copy { display: inline-flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#end-turn-btn { flex: 0 0 auto; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.audio-controls { display: flex; align-items: center; gap: 6px; padding-left: 10px; border-left: 1px solid var(--line); }
.audio-controls select, .audio-controls select option {
  width: 88px; padding: 4px 6px; font-size: 11px;
  background: #101725; color: var(--text);
}
.audio-controls select:focus { border-color: var(--accent); }
.audio-controls input[type="range"] { width: 84px; padding: 0; accent-color: var(--accent); }
.audio-switch { display: inline-flex; align-items: center; cursor: pointer; }
.audio-switch input { position: absolute; width: 0; height: 0; opacity: 0; }
.audio-switch-track {
  position: relative; width: 34px; height: 18px; border-radius: 999px;
  background: #3a4459; border: 1px solid var(--line); transition: background .2s;
}
.audio-switch-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: #cbd5e1; transition: transform .2s, background .2s;
}
.audio-switch input:checked + .audio-switch-track { background: var(--accent); }
.audio-switch input:checked + .audio-switch-track::after { transform: translateX(16px); background: #fff; }
.audio-volume-value { min-width: 30px; font-size: 11px; color: var(--muted); }
.btn.audio-off { opacity: .55; text-decoration: line-through; }
.event-banner {
  background: #4a3a1c; border-bottom: 1px solid var(--accent); padding: 8px 18px; color: #ffe1a0;
}
.opponent-banner {
  display: flex; align-items: center; gap: 12px; padding: 7px 18px;
  background: linear-gradient(90deg, #2a2034, #3a2a20); border-bottom: 1px solid #a8674f; color: #ffe6cf;
}
.opponent-banner.hidden { display: none; }
.opponent-copy { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.opponent-copy b { font-size: 12px; color: #ffc98a; }
.opponent-copy span { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.opponent-progress { flex: 1; height: 4px; max-width: 160px; margin-left: auto; border-radius: 4px; background: #17121d; overflow: hidden; }
.opponent-progress::after { content: ''; display: block; width: 40%; height: 100%; background: #e7a34a; animation: opponent-progress 1.5s linear infinite; }
.march-icon { width: 26px; height: 26px; flex: 0 0 auto; overflow: visible; }
.march-icon path { fill: none; stroke: #ffd48f; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.march-icon .march-flag { fill: #d05a4a; stroke: #ffd48f; }
.march-icon .march-body { fill: #5d789c; }
.march-icon .march-legs { animation: march-legs .6s ease-in-out infinite alternate; }
.march-icon .march-flag { transform-origin: 7px 3px; animation: march-flag .9s ease-in-out infinite alternate; }
@keyframes march-legs { from { transform: translateX(-1px); } to { transform: translateX(1px); } }
@keyframes march-flag { from { transform: skewY(-7deg); } to { transform: skewY(7deg); } }
@keyframes opponent-progress { from { transform: translateX(-100%); } to { transform: translateX(350%); } }
.turn-popup-backdrop { position: fixed; inset: 0; display: grid; place-items: center; z-index: 30; background: rgba(4, 8, 16, .38); pointer-events: none; }
.turn-popup-backdrop.hidden { display: none; }
.turn-popup { width: min(420px, 90vw); padding: 18px 20px; border: 1px solid var(--accent); border-radius: 14px; background: linear-gradient(145deg, #232c43, #171c2b); box-shadow: 0 18px 48px rgba(0,0,0,.55); animation: turn-popup-in .18s ease-out; }
.turn-popup-head { display: flex; align-items: center; gap: 10px; }
.turn-popup-heading { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.turn-popup-heading b { color: #ffd76a; font-size: 15px; }
.turn-popup-heading span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-popup-current { margin: 14px 0 8px; padding: 10px 12px; min-height: 38px; border-radius: 8px; background: rgba(240,212,138,.08); color: #f2f5fb; font-size: 12px; line-height: 1.5; }
.turn-popup-progress { height: 6px; border-radius: 6px; background: #0f1420; overflow: hidden; }
.turn-popup-progress > div { height: 100%; background: linear-gradient(90deg, #d9a441, #ffe09b); transition: width .35s ease; }
.turn-popup-list { display: flex; flex-direction: column; gap: 5px; margin-top: 12px; }
.turn-popup-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-left: 3px solid transparent; border-radius: 6px; background: rgba(255,255,255,.03); font-size: 12px; opacity: .65; }
.turn-popup-row.done { opacity: .85; }
.turn-popup-row.active { opacity: 1; background: rgba(217,164,65,.12); border-left-color: var(--faction-color, var(--accent)); }
.turn-popup-marker { width: 14px; color: #ffd76a; text-align: center; }
.turn-popup-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-popup-row-status { color: var(--muted); font-size: 11px; }
@keyframes turn-popup-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .turn-popup { animation: none; }
  .turn-popup-progress > div { transition: none; }
  .march-icon .march-legs, .march-icon .march-flag, .opponent-progress::after { animation: none; }
}
.layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(390px, .95fr); gap: 12px; padding: 12px; flex: 1; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.map-panel { display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15px; }
#map { flex: 1; width: 100%; min-height: 0; background: #1a2740; border-radius: 0 0 10px 10px; cursor: grab;
  touch-action: none;
}
#map:active { cursor: grabbing; }
.map-image { pointer-events: none; opacity: 0; transition: opacity .18s ease; }
.map-image.ready { opacity: 1; }
.map-grid-line { stroke: #fff; stroke-width: .16; opacity: .16; vector-effect: non-scaling-stroke; pointer-events: none; }
.map-frame { fill: none; stroke: #d8b663; stroke-width: .8; pointer-events: none; filter: drop-shadow(0 0 .4px #000); }
.map-footer { padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; }
.map-line { stroke: #5e4a2c; stroke-width: .3; opacity: .5; }
.map-capital-ring { fill: none; stroke: #f7e2a6; stroke-width: .32; opacity: .85; pointer-events: none; }
.map-owned-halo { opacity: .3; pointer-events: none; filter: drop-shadow(0 0 .7px rgba(0, 0, 0, .75)); }
.map-city { cursor: pointer; }
.map-city .map-hit { fill: transparent; }
.map-city .castle-shadow { fill: #000; opacity: .28; pointer-events: auto; }
.map-city .castle-wing { fill: #8b7355; stroke: #1a120c; stroke-width: .12; pointer-events: auto; }
.map-city .castle-wall { stroke: #1a120c; stroke-width: .16; stroke-linejoin: round; pointer-events: auto; }
.map-city .castle-tower { fill: #4a3a28; stroke: #e0b84a; stroke-width: .12; pointer-events: auto; }
.map-city .castle-roof { fill: #2b1e16; stroke: #e0b84a; stroke-width: .12; pointer-events: auto; }
.map-city .castle-gate { fill: #0d1422; opacity: .85; pointer-events: auto; }
.map-city .castle-flag-pole { fill: none; stroke: #e8edf7; stroke-width: .08; pointer-events: auto; }
.map-city .castle-flag { stroke: #0d1422; stroke-width: .06; pointer-events: auto; }
.map-city .castle-stone { fill: #f0d48a; opacity: .5; pointer-events: auto; }
.map-city .castle-stake { stroke: #d8b663; stroke-width: .14; fill: none; pointer-events: auto; }
.map-city .castle-rampart { stroke: #e0b84a; stroke-width: .16; fill: none; opacity: .7; pointer-events: auto; }
.map-city .castle-outer { stroke: #1a120c; stroke-width: .4; fill: none; pointer-events: auto; }
.map-city .castle-battlement { stroke: #ffe3a0; stroke-width: .16; fill: none; pointer-events: auto; }
.map-city.def-1 .castle-wall { stroke-width: .12; }
.map-city.def-2 .castle-wall { stroke-width: .18; }
.map-city.def-3 .castle-wall { stroke-width: .22; }
.map-city.def-4 .castle-wall { stroke: #ffe3a0; stroke-width: .28; }
.map-city.def-4 .castle-shadow { opacity: .4; }
.map-city .castle-icon { pointer-events: auto; }
.map-city .castle-faction-pole { fill: none; stroke: #e8edf7; stroke-width: .1; pointer-events: auto; }
.map-city .castle-faction-flag { stroke: #0d1422; stroke-width: .06; pointer-events: auto; }
.map-selection-ring { fill: none; stroke: #ef4444; opacity: .95; pointer-events: none; }
.map-city.selected .castle-wall { stroke: #fff; stroke-width: .26; }
.map-city.selected .castle-icon { filter: drop-shadow(0 0 2px rgba(239, 68, 68, .8)); }
.map-label-leader { stroke: #d8b663; opacity: .75; fill: none; pointer-events: auto; cursor: pointer; }
.map-label { fill: #e8edf7; font-size: 1.7px; text-anchor: middle; pointer-events: auto; cursor: pointer; paint-order: stroke; stroke: #0d1422; stroke-width: .45px; }
.map-label.small { font-size: 1.45px; }
.map-war-path { fill: none; stroke: #ff9a6b; stroke-width: .42; stroke-dasharray: 1.2 .7; opacity: .95; pointer-events: none; animation: march-path 1.1s linear infinite; }
.map-war-path-shadow { fill: none; stroke: #1a0f0c; stroke-width: .9; opacity: .55; pointer-events: none; }
.march-marker { pointer-events: none; filter: drop-shadow(0 0 .5px #ffcf8a); }
.march-marker circle { fill: #d0503f; stroke: #ffe2ab; stroke-width: .2; }
.march-marker path { fill: #ffe2ab; stroke: #4a2118; stroke-width: .1; }
@keyframes march-path { to { stroke-dashoffset: -3.8; } }
@media (prefers-reduced-motion: reduce) { .map-war-path { animation: none; } }

.side-panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; overflow-x: auto; }
.tab { flex: 1 0 auto; min-width: 52px; padding: 10px 5px; font-size: 12px; background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.tab-content { flex: 1; overflow: auto; padding: 14px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.info-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 10px 0 14px; }
.info-box { background: var(--panel-2); border-radius: 8px; padding: 9px; }
.info-box[data-stat-info] { cursor: pointer; transition: background .15s, outline-color .15s; outline: 1px solid transparent; }
.info-box[data-stat-info]:hover { background: #243044; outline-color: var(--accent); }
.info-box[data-stat-info] .label::after { content: '  ?'; color: var(--accent); font-weight: 700; }
.city-report-head { display: flex; align-items: center; gap: 14px; padding: 4px 0 14px; }
.city-report-head img { width: 72px; height: 72px; object-fit: contain; filter: drop-shadow(0 3px 8px rgba(0,0,0,.45)); }
.city-report-head b { color: var(--accent); font-size: 14px; }
.city-report-rows { display: grid; gap: 5px; }
.report-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 6px 9px; border-radius: 6px; background: var(--panel-2); font-size: 12px; }
.report-row span { color: var(--muted); }
.report-row b { font-weight: 600; overflow-wrap: anywhere; }
.city-name-link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline dotted rgba(240,212,138,.5); }
.city-name-link:hover { color: #fff0c7; }
.info-box .label { color: var(--muted); font-size: 11px; }
.info-box .value { font-size: 17px; font-weight: 700; }
.bar { height: 4px; background: #111827; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.defense-detail { padding: 10px 12px; margin: -4px 0 14px; border: 1px solid var(--line); border-left: 3px solid #d8b663; border-radius: 8px; background: var(--panel-2); font-size: 12px; line-height: 1.6; }
.defense-detail .bar { margin: 6px 0; }
.defense-detail.def-1 { border-left-color: #a07745; }
.defense-detail.def-2 { border-left-color: #c9a45a; }
.defense-detail.def-3 { border-left-color: #d8b663; }
.defense-detail.def-4 { border-left-color: #ffe3a0; box-shadow: inset 0 0 18px rgba(255,227,160,.08); }

.officer-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0 14px; }
.officer-row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 4px; align-items: start;
  background: var(--panel-2); border: 1px solid transparent; border-radius: 7px; padding: 5px 6px; cursor: pointer;
}
.officer-row > input[type="radio"] { display: none; }
.officer-row.selected { border-color: var(--accent); }
.officer-row .stats { color: var(--muted); font-size: 9px; }
.officer-row .skill { color: var(--accent); font-size: 9px; }
.officer-name.editable { cursor: text; border-bottom: 1px dashed var(--muted); }
.portrait-click { display: inline-flex; cursor: zoom-in; }
.officer-actions { grid-column: 1 / -1; display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 4px; }
.portrait-large { display: flex; justify-content: center; padding: 14px 0; }
.portrait-upload-preview { width: min(256px, 78vw); height: min(256px, 78vw); object-fit: cover; border-radius: 10px; border: 1px solid var(--accent); box-shadow: 0 4px 16px rgba(0,0,0,.45); }
.rename-input { width: 120px; padding: 3px 6px; font-size: 13px; }
.ronin-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel-2); border: 1px solid transparent; border-radius: 7px; padding: 7px 9px;
}
.ronin-info { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex-wrap: nowrap; white-space: nowrap; }
.ronin-info .stats { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.officer-cell { display: flex; align-items: center; gap: 8px; }
.cmd-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.cmd-grid .btn { padding: 8px 2px; font-size: 11px; line-height: 1.15; white-space: normal; }
.subhead { font-weight: 700; margin: 14px 0 6px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 6px 5px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.right, th.right { text-align: right; }
.log-filters { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.log-filters .btn.active { background: var(--accent); color: #1a1a1a; }
.log-entry { padding: 6px 0; border-bottom: 1px solid var(--line); line-height: 1.5; }
.log-entry .meta { color: var(--muted); font-size: 11px; margin-right: 8px; }
.log-entry .log-who { display: inline-flex; align-items: center; margin-right: 6px; color: #f0d48a; font-weight: 700; }
.log-entry.mine { border-left: 2px solid #61b57a; padding-left: 8px; }
.log-entry.war { border-left: 2px solid #d0503f; padding-left: 8px; }
.diplomacy-row { background: var(--panel-2); border-radius: 8px; padding: 10px; margin-bottom: 9px; }
.diplomacy-row .row { justify-content: space-between; }
.faction-link { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; color: inherit; font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline dotted rgba(255,255,255,.35); }
.faction-link:hover { color: var(--accent); }
.badge { padding: 2px 7px; border-radius: 10px; font-size: 11px; background: #34405a; }
.badge.war { background: #6c2f34; }
.badge.alliance { background: #2d6344; }
.badge.truce { background: #5a5030; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2c3a55; border: 1px solid var(--accent); padding: 10px 18px; border-radius: 8px; z-index: 50; max-width: 80vw; }
.dialogue { position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; width: min(560px, 88vw); padding: 10px 16px 10px 10px; background: linear-gradient(100deg, rgba(24,33,52,.97), rgba(42,54,78,.96)); border: 2px solid #d8b663; border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.5); z-index: 45; pointer-events: none; }
.dialogue.hidden { display: none; }
.dialogue-portrait { flex: 0 0 auto; line-height: 0; }
.dialogue-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.dialogue-body b { color: #ffd76a; font-size: 13px; }
.dialogue-body span { color: #f2f5fb; font-size: 14px; line-height: 1.5; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 40; }
.modal { width: min(480px, 92vw); max-height: 85vh; overflow: auto; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 20px; }
.modal.wide { width: min(900px, 94vw); }
.modal .history-status { padding: 8px 12px; margin-bottom: 10px; border-radius: 6px; background: rgba(240,212,138,.08); color: #f0d48a; font-size: 12px; }
.modal .history-content h4 { margin: 16px 0 4px; color: #f0d48a; font-size: 14px; }
.modal .history-content p { margin: 5px 0; line-height: 1.75; font-size: 13px; }
.modal .history-content p.history-bullet { padding-left: 12px; color: #cfd8e8; }
.modal .history-table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 12px; }
.modal .history-table th, .modal .history-table td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.modal .history-table th { width: 120px; background: #27334a; color: #f0d48a; }
.modal h3 { margin: 0 0 10px; color: var(--accent); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal label { display: block; margin: 10px 0 4px; color: var(--muted); }
.combat-table td { white-space: nowrap; }
.combat-table td.wrap { white-space: normal; line-height: 1.5; }
.combat-table td.reason { color: #ffb3ad; }
.combat-table td.advice { color: #b9e6c0; }
.combat-speaker { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.combat-speaker > div { display: flex; flex-direction: column; gap: 4px; }
.combat-speaker b { color: var(--accent); font-size: 13px; }
.combat-speaker span { font-size: 13px; line-height: 1.5; }

.exit-btn { position: fixed; top: 14px; right: 20px; z-index: 950; padding: 6px 12px; border-radius: 8px; border: 1px solid #e06c6c; background: #4a2229; color: #ffd9d9; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.4); }
.exit-btn:hover { background: #7a2f37; }
.logout-btn { right: 100px; border-color: #6fa8dc; background: #1f3b58; color: #d9ecff; }
.logout-btn:hover { background: #2f5c87; }
.guide-fab { position: fixed; right: 20px; bottom: 20px; width: 52px; height: 52px; border-radius: 50%; border: 2px solid #f0d48a; background: #a4352c; color: #fff6dc; font-size: 26px; font-weight: 700; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.45); z-index: 900; }
.guide-fab:hover { background: #c94b4b; }
.guide-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: grid; place-items: center; z-index: 1000; padding: 16px; }
.guide-modal { width: min(860px, 96vw); max-height: 88vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; overflow: hidden; box-shadow: 0 18px 60px rgba(0,0,0,.6); }
.guide-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: #202b40; }
.guide-head h2 { margin: 0; color: var(--accent); font-size: 18px; }
.guide-body { overflow: auto; padding: 18px 24px 28px; line-height: 1.75; font-size: 14px; }
.guide-content h2 { margin: 22px 0 8px; font-size: 17px; color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.guide-content h3 { margin: 16px 0 4px; font-size: 15px; color: #f0d48a; }
.guide-content p, .guide-content ul, .guide-content ol { margin: 6px 0; }
.guide-content ul, .guide-content ol { padding-left: 20px; }
.guide-content li { margin: 3px 0; }
.guide-content table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.guide-content th, .guide-content td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.guide-content th { background: #27334a; color: #f0d48a; }
.guide-note { margin: 12px 0; padding: 10px 14px; border-left: 4px solid var(--accent); background: rgba(240,212,138,.09); border-radius: 4px; color: #f0d48a; }

.chat-panel { position: fixed; right: 20px; bottom: 84px; z-index: 800; width: min(360px, calc(100vw - 40px)); height: min(420px, calc(100vh - 150px)); display: flex; flex-direction: column; background: linear-gradient(160deg, rgba(24,33,52,.98), rgba(34,45,66,.98)); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 16px 46px rgba(0,0,0,.6); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #202b40; }
.chat-head b { color: var(--accent); font-size: 13px; }
.chat-head .btn { margin-left: auto; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 12px; line-height: 1.5; }
.chat-row { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.chat-meta { display: block; margin-bottom: 2px; color: #f0d48a; font-size: 10px; }
.chat-meta .chat-faction { color: var(--muted, #9aa7bd); }
.chat-text { display: block; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: rgba(0,0,0,.16); }
.chat-form input { flex: 1; min-width: 0; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #101725; color: var(--text); font: inherit; }
.you-portrait-click { display: inline-flex; line-height: 0; cursor: pointer; border-radius: 4px; }
.you-portrait-click:hover { filter: brightness(1.18); }

.progress-bar { height: 5px; margin-top: 5px; border-radius: 4px; background: #101725; overflow: hidden; border: 1px solid rgba(255,255,255,.05); }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, #8a6a2f, var(--accent)); transition: width .2s; }
.progress-bar.loyalty-bar > div { background: linear-gradient(90deg, #3f7d63, var(--ok)); }
.progress-bar.trust-bar { margin: 6px 0; }
.progress-bar.trust-bar > div { background: linear-gradient(90deg, #3d6b9c, #7ab6e6); }
.objective-mini { flex: 0 1 220px; min-width: 120px; max-width: 220px; font-size: 10px; color: #f0d48a; }
.objective-mini-head { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.objective-mini-head .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.objective-mini .progress-bar { margin-top: 3px; }
.ap-meter { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; margin: 6px 0 10px; padding: 7px 10px; border: 1px solid #6b5330; border-radius: 7px; background: rgba(240,212,138,.07); font-size: 12px; }
.ap-meter .progress-bar { margin: 0; }
.ap-meter .muted { font-size: 10px; }
.facility-grid, .world-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.facility-card, .world-card { padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 11px; line-height: 1.5; }
button.world-card { width: 100%; color: inherit; font: inherit; text-align: left; cursor: pointer; }
button.world-card:hover { border-color: var(--accent); }
.facility-card .btn { margin-top: 7px; width: 100%; }
.facility-card .muted, .world-card .muted { font-size: 10px; }
.officer-traits { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.trait-tag, .hwarang-tag { font-size: 9px; padding: 1px 5px; background: #3a3452; color: #ddd0f5; }
.hwarang-tag { background: #6b4c2c; color: #ffe2b0; }
.officer-table { min-width: 780px; }
.officer-table .loyalty-cell { min-width: 105px; }
.officer-table .loyalty-cell > span { font-weight: 700; color: var(--ok); }
.loyalty-cell .progress-bar { margin: 3px 0; }
.relation-filters, .summary-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.relation-filters .btn.active, .summary-filters .btn.active { background: var(--accent); color: #1a1a1a; }
.modal-table-wrap { max-height: 45vh; overflow: auto; }
.relation-table, .chronicle-table, .summary-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.relation-table td, .chronicle-table td, .summary-table td { vertical-align: top; line-height: 1.5; }
.relation-table .fictional-relation { background: rgba(155,111,209,.1); }
.relation-table .negative, .summary-table .negative { color: var(--danger); }
.relation-table .positive, .summary-table .positive { color: var(--ok); }
.badge.fictional { background: #58406d; color: #e5d0ff; }
.captive-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid #6c2f34; border-radius: 7px; background: rgba(108,47,52,.2); margin-bottom: 6px; }
.diplomacy-summary, .summary-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.diplomacy-summary > div, .summary-totals > div { padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); display: flex; flex-direction: column; font-size: 12px; }
.diplomacy-summary b, .summary-totals b { font-size: 17px; color: var(--accent); }
.trust-row { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; margin-top: 6px; }
.objective-grid, .achievement-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.objective-card, .achievement-card { padding: 10px 12px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; background: var(--panel-2); font-size: 12px; line-height: 1.5; }
.objective-card.done, .achievement-card.unlocked { border-left-color: var(--ok); }
.severity-badge { padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.severity-badge.sev-critical { background: #6c2f34; color: #ffd0cc; box-shadow: 0 0 12px rgba(224,108,108,.25); }
.severity-badge.sev-warning { background: #6b5327; color: #ffe2a6; }
.severity-badge.sev-normal { background: #34405a; color: #d9e4f6; }
.cost-text { color: #ffd0cc; font-size: 12px; }
.event-critical { margin: 10px 0; padding: 9px 12px; border-left: 3px solid var(--danger); border-radius: 6px; background: rgba(224,108,108,.12); color: #ffbdb9; font-size: 12px; }
.special-battle, .battle-narrative { margin: 12px 0; padding: 10px 12px; border: 1px solid #6b5330; border-left: 3px solid var(--accent); border-radius: 8px; background: rgba(240,212,138,.07); line-height: 1.6; font-size: 12px; }
.special-battle b { color: var(--accent); }
.special-battle p { margin: 6px 0; }
.summary-table tr.summary-alert td { color: #ffbdb9; }
@media (max-width: 980px) {
  body { overflow: auto; }
  .login-screen { height: auto; min-height: 100%; padding: 16px 0; place-items: start center; }
  .login-layout { grid-template-columns: 1fr; width: min(760px, 94vw); max-height: none; }
  .login-card, .login-side { max-height: none; overflow: visible; }
  .layout { grid-template-columns: 1fr; }
  .game-screen { height: auto; min-height: 100%; }
  .game-screen .topbar { flex-wrap: wrap; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .map-panel { min-height: 420px; }
  .side-panel { min-height: 520px; }
  .facility-grid, .world-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .info-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .game-screen .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "brand date"
      "you turn"
      "actions actions";
    align-items: center;
    gap: 6px 8px;
    padding: 8px 10px 6px;
    padding-right: 104px;
  }
  .brand { grid-area: brand; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
  .brand > span:first-of-type { display: none; }
  .date-info { grid-area: date; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .you-badge { grid-area: you; padding-right: 0; border-right: 0; min-width: 0; }
  .you-badge .portrait-frame { --portrait-size: 34px !important; }
  .you-meta b { font-size: 11px; }
  .you-meta span { font-size: 9px; }
  .turn-info { grid-area: turn; display: flex; align-items: center; flex-wrap: nowrap; justify-content: flex-end; gap: 6px; min-width: 0; overflow: hidden; font-size: 11px; }
  .turn-copy { display: inline-flex; align-items: center; gap: 4px; min-width: 0; white-space: nowrap; }
  .turn-label, .turn-sep, .mine-label, .turn-mine { display: none; }
  .turn-active { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
  #end-turn-btn { margin-left: 0 !important; padding: 5px 8px; flex: 0 0 auto; }
  .top-actions { grid-area: actions; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding-bottom: 3px; }
  .top-actions > * { flex: 0 0 auto; white-space: nowrap; }
  .audio-controls { flex: 0 0 auto; padding-left: 0; border-left: 0; }
  .audio-volume-value { display: none; }
  .exit-btn { top: 6px; right: 6px; padding: 4px 7px; font-size: 10px; }
  .logout-btn { right: 54px; }
  .objective-mini { display: none; }
  .facility-grid, .world-grid, .objective-grid, .achievement-grid { grid-template-columns: 1fr; }
  .officer-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cmd-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .info-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .officer-row { grid-template-columns: 28px minmax(0, 1fr); }
  .tab { min-width: 48px; padding: 8px 4px; font-size: 11px; }
}
