:root {
  --bg: #12151f; --panel: #1d2233; --panel-2: #262d44; --line: #3a4466; --text: #e8ecf8; --dim: #8d97b8;
  --gold: #f2c744; --accent: #4f9bff; --bad: #e05555; --good: #6fd36f;
  --font: 'Galmuri11', 'DotGothic16', 'Malgun Gothic', monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; overflow: hidden; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
img { image-rendering: pixelated; }
button { font-family: var(--font); }
kbd { font: inherit; font-size: 10px; color: var(--dim); border: 1px solid var(--line); padding: 0 3px; margin-left: 4px; }
.dim { color: var(--dim); } .sm { font-size: 11px; }

#app { display: flex; flex-direction: column; height: 100%; }

/* HUD */
#hud { display: flex; align-items: center; gap: 14px; padding: 6px 12px; background: var(--panel); border-bottom: 3px solid #0b0d14; box-shadow: 0 2px 0 var(--line); z-index: 5; }
.logo { font-size: 20px; letter-spacing: 3px; color: var(--gold); text-shadow: 2px 2px 0 #6b4a00; }
#nation-tag { display: flex; align-items: center; gap: 6px; padding: 3px 8px; background: #0e111a; border: 2px solid var(--line); }
#nation-tag i { width: 10px; height: 10px; border: 1px solid #000; }
#res { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.chip { display: flex; align-items: center; gap: 6px; background: #0e111a; padding: 3px 8px; border: 2px solid var(--line); min-width: 92px; }
.chip img { width: 16px; height: 16px; }
.chip small { color: var(--dim); margin-left: auto; font-size: 10px; }
.chip small.pos { color: var(--good); } .chip small.neg { color: var(--bad); }
#tabs { display: flex; gap: 6px; }
.btn, #tabs button { font-size: 13px; color: var(--text); background: var(--panel-2); border: 2px solid var(--line); border-bottom-width: 4px; padding: 6px 12px; cursor: pointer; position: relative; }
.btn:hover, #tabs button:hover { background: #313a5a; }
.btn:active, #tabs button:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn:disabled, #tabs button:disabled { opacity: .4; cursor: not-allowed; transform: none; border-bottom-width: 4px; }
#tabs button.active { background: var(--accent); border-color: #9fcaff; color: #06101f; }
#tabs button.active kbd { color: #06101f; border-color: #06101f; }
.btn.big { font-size: 17px; padding: 11px 30px; background: var(--gold); color: #2a1c00; border-color: #fff0b0; }
.btn.big:hover { background: #ffd95e; }
.btn.big:disabled { background: #6a6240; color: #333; border-color: #8a8460; }
.btn.ghost { background: transparent; border-color: transparent; font-size: 11px; color: var(--dim); }
.btn.sm { padding: 2px 10px; font-size: 12px; }
.btn.danger { background: #6a2a2a; border-color: #e07070; margin-top: 8px; }
.badge { position: absolute; top: -8px; right: -6px; background: var(--bad); color: #fff; font-size: 10px; min-width: 16px; padding: 1px 4px; border: 2px solid #0b0d14; display: none; }
.badge.on { display: block; animation: pulse 1s steps(2) infinite; }
@keyframes pulse { 50% { transform: scale(1.2); } }

/* Stage */
#stage { position: relative; flex: 1; min-height: 0; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, rgba(8,10,24,.55) 100%); }

/* World */
#world-canvas { width: 100%; height: 100%; cursor: grab; background: #12325c; }
#world-canvas.drag { cursor: grabbing; }
.hint { position: absolute; left: 12px; bottom: 10px; color: var(--dim); background: rgba(10,12,20,.75); padding: 4px 8px; pointer-events: none; }
#panel { position: absolute; top: 12px; right: 12px; width: 252px; max-height: calc(100% - 24px); overflow: auto; background: rgba(29,34,51,.96); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--line); padding: 12px; }
#panel h2 { font-size: 16px; font-weight: normal; margin-bottom: 4px; }
#panel h3 { font-size: 12px; font-weight: normal; color: var(--dim); margin: 14px 0 6px; border-top: 1px solid var(--line); padding-top: 8px; }
.owner { display: flex; align-items: center; gap: 6px; color: var(--dim); margin-bottom: 8px; }
.owner i { width: 10px; height: 10px; display: inline-block; border: 1px solid #000; }
#p-stats { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin-bottom: 10px; }
#p-stats dt { color: var(--dim); } #p-stats dd { text-align: right; } #p-stats dd.star { color: var(--gold); letter-spacing: 1px; }
#p-attack { width: 100%; background: #8c2f2f; border-color: #e07070; }
#p-attack:hover { background: #a63a3a; }
#p-attack:disabled { background: var(--panel-2); border-color: var(--line); }
#p-rank { list-style: none; display: grid; gap: 3px; }
#p-rank li { display: flex; align-items: center; gap: 6px; }
#p-rank li.me { color: var(--gold); }
#p-rank i { width: 10px; height: 10px; border: 1px solid #000; }
#p-rank span { margin-left: auto; color: var(--dim); }
#tribe-bar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; background: rgba(29,34,51,.96); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--gold); padding: 8px 14px; max-width: calc(100% - 300px); }
#tribe-text { line-height: 1.6; }
#found-why { font-size: 11px; position: absolute; bottom: -22px; left: 0; right: 0; text-align: center; background: rgba(10,12,20,.8); padding: 2px; }

/* Realm */
#screen-realm { background: radial-gradient(ellipse at center, #1c2a1a 0%, #090c10 80%); }
#realm-wrap { position: absolute; inset: 0 250px 128px 0; display: flex; align-items: center; justify-content: center; }
#realm-canvas { border: 4px solid #0b0d14; box-shadow: 0 0 0 3px var(--line), 0 10px 40px rgba(0,0,0,.6); }
#realm-side { position: absolute; top: 0; right: 0; bottom: 128px; width: 250px; overflow: auto; background: var(--panel); border-left: 3px solid #0b0d14; box-shadow: -2px 0 0 var(--line); padding: 12px; }
#realm-side h3 { font-size: 12px; font-weight: normal; color: var(--dim); margin: 14px 0 6px; border-top: 1px solid var(--line); padding-top: 8px; }
#realm-side h3:first-child { margin-top: 0; border: 0; padding: 0; }
.popline { font-size: 16px; } .popline em { color: var(--bad); font-size: 11px; font-style: normal; }
.bar, .mbar { height: 8px; background: #0e111a; border: 1px solid #000; margin: 4px 0; }
.bar i, .mbar i { display: block; height: 100%; background: var(--good); }
.idle { color: var(--dim); font-size: 12px; margin-bottom: 4px; } .idle.warn { color: var(--gold); }
.jobs, .rates { list-style: none; display: grid; gap: 3px; margin-bottom: 8px; }
.jobs li, .rates li { display: flex; align-items: center; gap: 6px; }
.jobs li.off { opacity: .35; }
.jobs li b { margin-left: auto; } .jobs li small { color: var(--dim); width: 28px; }
.rates img { width: 14px; height: 14px; } .rates b { margin-left: auto; } .rates b.pos { color: var(--good); } .rates b.neg { color: var(--bad); }
.wk { display: flex; align-items: center; gap: 10px; justify-content: center; margin: 8px 0; font-size: 15px; }
.tip { margin-top: 14px; line-height: 1.6; }
#buildbar { position: absolute; left: 0; right: 0; bottom: 0; height: 98px; display: flex; gap: 8px; justify-content: center; align-items: center; padding: 8px; background: var(--panel); border-top: 3px solid #0b0d14; box-shadow: 0 -2px 0 var(--line); }
.bcard { width: 100px; height: 82px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; padding: 4px; background: var(--panel-2); border: 2px solid var(--line); cursor: pointer; color: var(--text); font-size: 12px; }
.bcard img { max-width: 80px; max-height: 46px; }
.bcard small { font-size: 10px; color: var(--dim); display: flex; gap: 4px; }
.bcard small span::after { content: ''; }
.c-gold { color: #f2c744; } .c-wood { color: #d09a60; } .c-stone { color: #b0b0c0; } .c-food { color: #e86a5a; }
.bcard:hover { background: #313a5a; }
.bcard.sel { border-color: var(--gold); background: #3a3520; }
.bcard.poor { opacity: .5; }
.bcard.del .x { font-size: 26px; color: var(--bad); }
.bcard.del.sel { border-color: var(--bad); background: #3a2020; }

/* Diplomacy */
#screen-diplo { background: radial-gradient(ellipse at center, #1a2038 0%, #090b12 85%); }
#screen-diplo.active { display: grid; grid-template-columns: 300px 1fr 330px; gap: 12px; padding: 12px; }
.dcol { background: rgba(29,34,51,.95); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--line); padding: 12px; overflow: auto; }
.dcol h3 { font-size: 12px; font-weight: normal; color: var(--dim); margin: 12px 0 6px; }
.dcol h3:first-child { margin-top: 0; }
.inf { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; } .inf .mbar { flex: 1; }
.nlist { display: grid; gap: 6px; }
.ncard { display: flex; align-items: center; gap: 8px; text-align: left; background: var(--panel-2); border: 2px solid var(--line); color: var(--text); padding: 6px 8px; cursor: pointer; }
.ncard.sel { border-color: var(--gold); background: #3a3520; }
.ncard.tribe { opacity: .55; }
.ncard > i { width: 14px; height: 30px; border: 1px solid #000; flex: none; }
.ncard div { flex: 1; min-width: 0; } .ncard small { display: block; color: var(--dim); font-size: 10px; }
.chips { display: flex; flex-direction: column; gap: 2px; }
.chip-s { font-size: 9px; padding: 1px 4px; border: 1px solid #000; background: #345; }
.chip-s.alliance { background: #2f6b3a; } .chip-s.nap { background: #55598a; } .chip-s.trade { background: #7a6a2a; } .chip-s.war { background: #8c2f2f; }
.dhead { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; } .dhead i { width: 16px; height: 34px; border: 1px solid #000; } .dhead h2 { font-size: 20px; font-weight: normal; margin-right: auto; }
.trow { display: flex; align-items: center; gap: 10px; } .trow .mbar { flex: 1; }
.traits { margin: 14px 0; } .traits h4, .rel h4 { font-size: 12px; font-weight: normal; color: var(--dim); margin-bottom: 6px; }
.trait { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; } .trait span { width: 40px; } .trait .mbar { flex: 1; } .trait em { width: 40px; font-style: normal; }
.plan { padding: 8px 10px; margin: 8px 0; border-left: 4px solid; background: rgba(0,0,0,.25); } .plan.danger { border-color: var(--bad); color: #ffb0a0; } .plan.ok { border-color: var(--good); }
.rel { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; } .rel h4 { width: 100%; margin: 0; } .rel span { background: #0e111a; border: 1px solid var(--line); padding: 2px 6px; font-size: 11px; }
.speech { margin: 12px 0; padding: 10px 14px; background: #0e111a; border-left: 4px solid var(--line); font-size: 14px; } .speech.yes { border-color: var(--good); } .speech.no { border-color: var(--bad); }
.acts, .acts2 { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; align-items: center; }
.act { font-size: 12px; color: var(--text); background: var(--panel-2); border: 2px solid var(--line); border-bottom-width: 4px; padding: 5px 10px; cursor: pointer; }
.act:hover { background: #313a5a; } .act.war { background: #6a2a2a; border-color: #e07070; } .act.betray { background: #4a1f3a; border-color: #d060a0; } .act:disabled { opacity: .35; cursor: not-allowed; } .act.sm { padding: 2px 8px; }
.acts2 label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); } select { font-family: var(--font); background: #0e111a; color: var(--text); border: 2px solid var(--line); padding: 3px; }
.offer { display: flex; align-items: center; gap: 8px; background: #0e111a; border: 2px solid var(--gold); padding: 6px 8px; margin-bottom: 6px; } .offer > i { width: 10px; height: 28px; border: 1px solid #000; } .offer div { flex: 1; } .offer small { display: block; color: var(--dim); font-size: 10px; }
.feed { list-style: none; display: grid; gap: 5px; font-size: 12px; } .feed li { padding: 4px 6px; background: #0e111a; border-left: 3px solid var(--line); line-height: 1.5; } .feed li.war { border-color: var(--bad); } .feed li.rumor { border-color: #b08ae8; color: #cdb8f0; font-style: italic; } .feed li.secret { border-color: #7a7a7a; color: #aaa; } .feed time { color: var(--dim); margin-right: 6px; font-size: 10px; }

/* Log */
#log { position: absolute; left: 12px; top: 64px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; z-index: 4; max-width: 420px; }
#log div { background: rgba(10,12,20,.88); border-left: 4px solid var(--accent); padding: 5px 10px; animation: fadein .2s steps(3); }
#log div.war { border-color: var(--bad); } #log div.good { border-color: var(--good); }

/* panel additions */
#p-status { background: #0e111a; border: 2px solid var(--line); padding: 8px 10px; margin-bottom: 10px; line-height: 1.7; }
#p-status small { color: var(--dim); }
#p-note { margin-top: 8px; line-height: 1.7; } #p-note em { color: #ffb09a; font-style: normal; }
.btn.go { background: #2f6b3a; border-color: #8fe29a; } .btn.go:hover { background: #3a8048; }
.btn.war { background: #8c2f2f; border-color: #e07070; } .btn.war:hover { background: #a63a3a; }
#p-attack { width: 100%; }

/* tooltip */
#tip { position: fixed; z-index: 30; display: none; width: 300px; pointer-events: none; background: rgba(14,17,26,.98); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--gold), 0 8px 24px rgba(0,0,0,.6); padding: 10px 12px; line-height: 1.6; }
#tip h4 { font-weight: normal; font-size: 15px; color: var(--gold); margin-bottom: 4px; } #tip h4 em { font-style: normal; }
#tip p { color: #cfd6ee; margin-bottom: 6px; } #tip dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; }
#tip dt { color: var(--dim); } #tip .pos { color: var(--good); } #tip .neg { color: var(--bad); } #tip .short { text-decoration: underline wavy #e05555; }
#tip .tipline { color: #9fc8ff; font-size: 12px; margin-top: 6px; } #tip .lock { color: #ffb09a; font-size: 12px; }
.bcard.locked { filter: grayscale(.9) brightness(.6); cursor: not-allowed; }
.dev { background: #0e111a; border: 2px solid var(--line); padding: 8px; margin: 8px 0; }
.dev .dh { display: flex; justify-content: space-between; margin-bottom: 4px; } .dev .dh span { color: var(--gold); }
.dnext { margin: 6px 0; font-size: 12px; } .dnext small { color: var(--dim); }
.dev .btn { width: 100%; margin-top: 4px; font-size: 11px; }
.tier { font-size: 15px; color: var(--gold); } .tier small { color: var(--dim); font-size: 11px; }
.tipline { color: #9fc8ff; font-size: 12px; margin: 6px 0; } .sm { font-size: 12px; line-height: 1.6; }
.c-gold { color: #f2c744; } .c-wood { color: #d09a60; } .c-stone { color: #b0b0c0; } .c-food { color: #e86a5a; }

/* ============ Title screen ============ */
#title { position: absolute; inset: 0; z-index: 10; background: #070918; overflow: hidden; }
#title.hidden { display: none; }
#title-canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.title-ui { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 5vh; gap: 2.5vh; }
.logo-wrap { text-align: center; }
#title h1 { font-weight: normal; line-height: 0; }
#logo-canvas { width: min(70vw, 640px); height: auto; image-rendering: pixelated; filter: drop-shadow(0 0 24px rgba(255,170,60,.5)); }
.sub { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 8px; color: #e8dcc0; letter-spacing: .5em; font-size: clamp(11px, 1.4vw, 16px); text-shadow: 0 2px 0 #000; }
.sub i { width: 8vw; max-width: 90px; height: 3px; background: linear-gradient(90deg, transparent, #f2c744, transparent); }
#menu { display: flex; flex-direction: column; gap: 14px; align-items: stretch; width: min(360px, 80vw); margin-top: 3vh; }
.menu-btn { position: relative; text-align: center; font-family: var(--font); color: #f4ecd4; cursor: pointer; padding: 14px 20px;
  background: linear-gradient(#3a3a5a, #232440); border: 3px solid #0a0b18; box-shadow: inset 0 0 0 2px #6a6a98, inset 0 -6px 0 rgba(0,0,0,.35), 0 6px 0 #0a0b18, 0 10px 24px rgba(0,0,0,.5); transition: transform .08s steps(2); }
.menu-btn b { display: block; font-weight: normal; font-size: 22px; letter-spacing: .3em; text-shadow: 0 2px 0 #000; }
.menu-btn small { display: block; margin-top: 4px; font-size: 11px; color: #a8a8d0; letter-spacing: .05em; }
.menu-btn:hover { transform: translateY(-3px); background: linear-gradient(#5a4a2a, #3a2e1a); box-shadow: inset 0 0 0 2px #f2c744, inset 0 -6px 0 rgba(0,0,0,.35), 0 9px 0 #0a0b18, 0 14px 28px rgba(0,0,0,.5), 0 0 24px rgba(242,199,68,.3); }
.menu-btn:hover b { color: #ffe680; }
.menu-btn:active { transform: translateY(3px); }
.menu-btn:disabled { display: none; }
.setup-card { width: min(560px, 92vw); display: flex; flex-direction: column; gap: 12px; padding: 20px 24px; margin-top: 1vh;
  background: linear-gradient(rgba(30,30,54,.94), rgba(18,18,34,.96)); border: 3px solid #0a0b18; box-shadow: inset 0 0 0 2px #6a6a98, 0 10px 40px rgba(0,0,0,.7); }
.setup-card h2 { font-weight: normal; text-align: center; font-size: 20px; letter-spacing: .4em; color: var(--gold); text-shadow: 0 2px 0 #000; }
.srow { display: flex; gap: 18px; align-items: center; } .srow.btns { justify-content: space-between; margin-top: 6px; }
.banner-box { width: 96px; height: 140px; flex: none; background: radial-gradient(#2a3050, #12162a); border: 3px solid #0a0b18; display: grid; place-items: center; box-shadow: inset 0 0 0 2px #4a4a78; }
#banner-prev { width: 80px; height: 128px; animation: sway 2.4s ease-in-out infinite; transform-origin: top center; }
@keyframes sway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
.sfields { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.setup-card label, .lbl { color: var(--dim); font-size: 12px; } .setup-card label { display: flex; flex-direction: column; gap: 6px; }
.setup-card input { font-family: var(--font); font-size: 18px; background: #0a0c16; color: var(--text); border: 2px solid #4a4a78; padding: 8px; text-align: center; outline: none; } .setup-card input:focus { border-color: var(--gold); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; } .swatches button { width: 28px; height: 28px; border: 3px solid #0a0b18; cursor: pointer; } .swatches button.sel { box-shadow: 0 0 0 3px var(--gold); }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; } .chips-row button { font-family: var(--font); font-size: 12px; padding: 6px 10px; color: var(--text); background: #1c2038; border: 2px solid #3a4066; cursor: pointer; } .chips-row button.sel { background: #4a3a1a; border-color: var(--gold); color: #ffe680; }
.title-foot { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: rgba(232,220,192,.65); font-size: 12px; letter-spacing: .2em; text-shadow: 0 2px 0 #000; pointer-events: none; }
#loading { position: absolute; bottom: 12vh; }

/* ===== round 3 additions ===== */
#war-flag { display: none; background: #5a1a1a; border: 2px solid #e05555; padding: 3px 10px; color: #ffb0a0; animation: pulse 1.2s steps(2) infinite; }
#war-flag.on { display: block; }
#res { gap: 6px; } .chip { min-width: 84px; padding: 3px 6px; }
#tabs button { padding: 6px 10px; }
.btn.scout { width: 100%; margin-bottom: 4px; text-align: left; } .btn.scout small { color: var(--dim); margin-left: 6px; } .btn.scout.on { background: #4a3a1a; border-color: var(--gold); }
#p-scout-hint { margin-bottom: 10px; line-height: 1.5; }
.c-science { color: #8ab0ff; } .c-faith { color: #ffe27a; } .c-troops { color: #d8d8e8; }
.warbanner { background: #3a1616; border: 2px solid #e05555; padding: 8px 10px; margin-bottom: 10px; line-height: 1.6; color: #ffb0a0; }
.consume { background: #0e111a; border: 2px solid var(--line); padding: 6px 8px; margin: 6px 0; line-height: 1.7; font-size: 12px; }
small.gold, .gold { color: var(--gold); }
.neg { color: var(--bad); } .pos { color: var(--good); }
.bcard { width: 80px; height: 78px; font-size: 11px; padding: 3px; } #buildbar { gap: 5px; overflow-x: auto; justify-content: center; }
.bcard .bn { white-space: nowrap; }

/* nation screen */
#screen-nation { background: radial-gradient(ellipse at center, #1c2238 0%, #090b12 85%); }
#screen-nation.active { display: grid; grid-template-columns: 430px 1fr; gap: 12px; padding: 12px; }
.ncol { background: rgba(29,34,51,.95); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--line); padding: 12px; overflow: auto; }
.ncol h3 { font-size: 14px; font-weight: normal; color: var(--gold); margin: 4px 0 10px; } .ncol h3 small { color: var(--dim); font-size: 11px; }
.ncol h4 { font-size: 12px; font-weight: normal; color: var(--dim); margin: 10px 0 6px; }
.focus-grid { display: grid; gap: 8px; margin-bottom: 18px; }
.fcard { background: #0e111a; border: 2px solid var(--line); padding: 8px 10px; } .fcard.cur { border-color: var(--gold); background: #2a2616; }
.fcard .fh { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; } .ficon { font-size: 18px; width: 22px; text-align: center; }
.fcard p { color: #cfd6ee; font-size: 12px; line-height: 1.5; } .ftext { color: #9fc8ff; font-size: 11px; margin: 4px 0 6px; }
.fcard .btn { width: 100%; font-size: 11px; }
.tfilter { display: flex; gap: 6px; align-items: center; margin: 4px 0 8px; flex-wrap: wrap; } .tfilter span { color: var(--gold); margin-right: 6px; } .era { font-size: 10px; letter-spacing: 1px; color: #7f8ab4; border-bottom: 1px dashed #343c60; margin-top: 4px; padding-bottom: 1px; }
.tech-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; align-items: start; }
.tcol { display: grid; gap: 6px; } .tcol-h { text-align: center; color: var(--gold); border-bottom: 2px solid var(--line); padding-bottom: 4px; margin-bottom: 2px; }
.tnode { text-align: left; font-family: var(--font); color: var(--text); background: #12162a; border: 2px solid var(--line); padding: 6px 8px; cursor: pointer; line-height: 1.45; }
.tnode .tn { display: flex; justify-content: space-between; gap: 6px; } .tnode .tc { color: #8ab0ff; font-size: 11px; }
.tnode .tt { font-size: 11px; color: #cfd6ee; margin-top: 2px; } .tnode .tw { font-size: 10px; color: #ffb09a; margin-top: 3px; } .tnode .tu { font-size: 10px; color: #9fe8a8; margin-top: 2px; }
.tnode.done { background: #1c3a24; border-color: #5fbf6f; } .tnode.ready { background: #2a2f4a; border-color: #8ab0ff; box-shadow: 0 0 10px rgba(138,176,255,.3); } .tnode.ready:hover { background: #38406a; }
.tnode.poor { border-color: #6a6a98; } .tnode.locked { opacity: .5; cursor: not-allowed; }
.relbox { background: #0e111a; border: 2px solid var(--line); padding: 10px; display: grid; gap: 8px; }
.checks { list-style: none; display: grid; gap: 2px; font-size: 12px; color: var(--dim); } .checks li::before { content: '○ '; } .checks li.ok { color: var(--good); } .checks li.ok::before { content: '● '; }
.fl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); } .fl input { font-family: var(--font); font-size: 15px; background: #0a0c16; color: var(--text); border: 2px solid #4a4a78; padding: 6px; }
.symrow { display: flex; gap: 6px; } .symb { background: #12162a; border: 2px solid var(--line); padding: 6px; cursor: pointer; } .symb.sel { border-color: var(--gold); background: #2a2616; }
.sym { position: relative; display: inline-block; } .sym i { position: absolute; display: block; }
.doctrines { display: grid; gap: 6px; } .doc { text-align: left; font-family: var(--font); color: var(--text); background: #12162a; border: 2px solid var(--line); padding: 6px 8px; cursor: pointer; display: grid; gap: 2px; } .doc.sel { border-color: var(--gold); background: #2a2616; } .doc small { color: var(--dim); font-size: 11px; } .doc em { color: #9fc8ff; font-style: normal; font-size: 11px; }
.relhead { display: flex; gap: 12px; align-items: center; }
.fol { list-style: none; display: grid; gap: 4px; font-size: 12px; } .fol li { display: flex; align-items: center; gap: 6px; } .fol i { width: 8px; height: 8px; border: 1px solid #000; } .fol span { margin-left: auto; color: var(--dim); }

/* diplomacy additions */
#screen-diplo.active { grid-template-columns: 310px 1fr 340px; }
.filters { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; } .filters button { font-family: var(--font); font-size: 11px; background: #12162a; color: var(--text); border: 2px solid var(--line); padding: 3px 8px; cursor: pointer; } .filters button.sel { border-color: var(--gold); background: #2a2616; }
.cnt { margin-bottom: 6px; } .nlist { max-height: calc(100% - 110px); overflow: auto; }
.chip-s.marriage { background: #8a3a6a; } .chip-s.vassal { background: #5a4a2a; } .chip-s.faith { background: #7a6a1a; }
.dhead > div { flex: 1; } .chips-h { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }
.twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
.factors h4, .traits h4, .hist h4, .rel h4 { font-size: 12px; font-weight: normal; color: var(--dim); margin-bottom: 6px; }
.fac { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 6px; background: #0e111a; margin-bottom: 2px; border-left: 3px solid var(--line); } .fac.pos { border-color: var(--good); } .fac.neg { border-color: var(--bad); } .fac.pos b { color: var(--good); } .fac.neg b { color: var(--bad); }
.agroup { background: #0e111a; border: 2px solid var(--line); padding: 8px 10px; margin: 10px 0; } .agroup h5 { font-weight: normal; font-size: 12px; color: var(--gold); margin-bottom: 6px; }
.sweet, .barter { margin-top: 6px; font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; } .barter input { width: 70px; font-family: var(--font); background: #0e111a; color: var(--text); border: 2px solid var(--line); padding: 3px; }
.act.pressure { background: #4a3a1a; border-color: #d8a040; } .act.faith { background: #4a4018; border-color: #e8d060; }
.lockt { font-size: 11px; color: #ffb09a; padding: 4px 6px; }
.hist ul { list-style: none; display: grid; gap: 3px; font-size: 12px; } .hist li { padding: 3px 6px; background: #0e111a; border-left: 3px solid var(--line); } .hist time { color: var(--dim); margin-right: 6px; font-size: 10px; }
.offer.ult { border-color: var(--bad); background: #2a1212; }
.dcol.mid { overflow: auto; }

/* ===== round 4: cities, armies ===== */
#city-tabs { position: absolute; top: 6px; left: 12px; right: 262px; z-index: 3; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ctab { font-family: var(--font); font-size: 12px; color: var(--text); background: var(--panel-2); border: 2px solid var(--line); border-bottom-width: 3px; padding: 4px 10px; cursor: pointer; }
.ctab small { color: var(--dim); margin-left: 4px; } .ctab.on { background: #3a3520; border-color: var(--gold); }
.cinfo { margin-left: 8px; }
#realm-wrap { inset: 40px 250px 128px 0 !important; }
#p-extra { display: grid; gap: 6px; margin-top: 8px; }
#p-extra h3 { font-size: 12px; font-weight: normal; color: var(--dim); margin: 8px 0 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.armies { list-style: none; display: grid; gap: 4px; }
.armies li { display: flex; gap: 4px; } .armies li button:first-child { flex: 1; text-align: left; font-family: var(--font); color: var(--text); background: #12162a; border: 2px solid var(--line); padding: 4px 8px; cursor: pointer; font-size: 12px; }
.armies li.sel button:first-child { border-color: var(--gold); background: #2a2616; } .armies li small { display: block; color: var(--dim); font-size: 10px; }
.armies li .x { background: #3a1616; border: 2px solid #8c2f2f; color: #ffb0a0; cursor: pointer; font-family: var(--font); }
.recruit { display: flex; gap: 4px; } .recruit select { flex: 1; min-width: 0; } .recruit input { width: 58px; font-family: var(--font); background: #0e111a; color: var(--text); border: 2px solid var(--line); padding: 3px; }
.recruit { flex-wrap: wrap; } .recruit .btn { flex: 1; }

#city-tabs { max-height: 74px; overflow-y: auto; }

/* ---- account box (title) ---- */
.acct-box { margin-top: 14px; width: min(420px, 92vw); display: flex; flex-direction: column; gap: 6px; align-items: center; padding: 10px 12px; background: rgba(14,16,30,.78); border: 2px solid #3a4066; box-shadow: 0 4px 0 #0a0b18; font-family: var(--font); }
.acct-box #acct-out { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.acct-box input { font-family: var(--font); font-size: 12px; width: 120px; background: #0a0c16; color: var(--text); border: 2px solid #4a4a78; padding: 5px; outline: none; }
.acct-box input:focus { border-color: var(--gold); }
.acct-box .btn { font-size: 12px; padding: 5px 10px; }
.acct-box #acct-in { display: flex; gap: 10px; align-items: center; color: var(--gold); }
.acct-box #acct-msg:empty, .acct-box #cloud-status:empty { display: none; }
#rank-box { width: 100%; text-align: left; border-top: 1px dashed #3a4066; padding-top: 6px; }
#rank-box ol { margin: 4px 0 0; padding-left: 20px; max-height: 120px; overflow-y: auto; }
#rank-box li small { color: var(--dim); }

#lab-badge { position: fixed; top: 82px; left: 50%; transform: translateX(-50%); z-index: 40; background: rgba(40,24,80,.92); border: 2px solid #b48cff; color: #e8dcff; padding: 4px 10px; font-size: 12px; display: flex; gap: 8px; align-items: center; pointer-events: auto; }
/* setup card taller than the window: let the title UI scroll and keep the start button reachable */
.title-ui { overflow-y: auto; padding-bottom: 4vh; justify-content: flex-start; }
.setup-card { margin-bottom: 2vh; }
@media (max-height: 820px) { .logo-wrap { transform: scale(.7); transform-origin: top center; margin-bottom: -6vh; } .setup-card { gap: 8px; padding: 14px 20px; } }
.title-ui.in-setup { padding-top: 2vh; gap: 1vh; } .title-ui.in-setup .logo-wrap { transform: scale(.45); transform-origin: top center; margin-bottom: -27vh; } .title-ui.in-setup .setup-card { margin-top: 0; }
.title-ui.in-setup #mode-msg:empty { display: none; } .title-ui.in-setup .setup-card { gap: 8px; }

.stages { display: grid; gap: 4px; margin-bottom: 14px; }
.stg { background: #12162a; border: 2px solid var(--line); padding: 5px 8px; font-size: 12px; line-height: 1.45; }
.stg .sh { display: flex; justify-content: space-between; gap: 8px; } .stg .sh span { color: var(--dim); font-size: 11px; }
.stg .sd { color: #cfd6ee; font-size: 11px; } .stg .sb { color: #9fe8a8; font-size: 11px; }
.stg.done { background: #1c3a24; border-color: #5fbf6f; opacity: .8; } .stg.cur { border-color: var(--gold); background: #2e2a18; box-shadow: 0 0 10px rgba(255,214,74,.25); } .stg.cur .sh span { color: var(--gold); }
.stg.todo { opacity: .75; }

#buildcats { position: absolute; left: 0; right: 0; bottom: 98px; height: 30px; display: flex; gap: 4px; align-items: center; padding: 2px 8px; background: #14182c; border-top: 2px solid var(--line); overflow-x: auto; z-index: 3; }
#buildcats button { font-family: var(--font); font-size: 11px; color: var(--dim); background: #1a1f38; border: 2px solid var(--line); padding: 2px 8px; cursor: pointer; white-space: nowrap; }
#buildcats button.sel { color: #1a1408; background: var(--gold); border-color: var(--gold); }
#buildcats button:hover:not(.sel) { background: #2a3050; color: var(--text); }
.bcard { position: relative; flex: 0 0 auto; }
.bcard.new::after { content: 'NEW'; position: absolute; top: 1px; right: 2px; font-size: 9px; color: #1a1408; background: #9fe8a8; padding: 0 3px; }
#buildbar { justify-content: flex-start !important; }

/* ================= touch & small-screen layout ================= */
html, body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
#app, #hud, #tabs, #buildbar, #buildcats, #panel, .screen button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
#world-canvas, #realm-canvas { touch-action: none; }
button, .btn { touch-action: manipulation; }
#realm-wrap { justify-content: flex-start; align-items: flex-start; overflow: auto; }
#realm-canvas { margin: auto; flex: 0 0 auto; }
#wm-btns, #realm-btns, #realm-info, #panel-toggle { display: none; }

@media (pointer: coarse) {
  .btn, #tabs button { min-height: 42px; }
  .btn.sm { min-height: 38px; padding: 6px 12px; }
  #buildcats { height: 40px; } #buildcats button { padding: 8px 12px; font-size: 12px; }
  .bcard { width: 92px; }
  .tnode, .ncard, .fcard button { min-height: 44px; }
  input, select { font-size: 16px; }
  .hint { display: none; }
  #wm-btns { display: flex; }
  #realm-btns { display: flex; }
}
#wm-btns { position: absolute; left: 10px; bottom: 10px; flex-direction: column; gap: 8px; z-index: 4; }
#realm-btns { position: absolute; left: 10px; bottom: 174px; flex-direction: column; gap: 8px; z-index: 4; }
#wm-btns button, #realm-btns button { width: 46px; height: 46px; font-size: 22px; color: var(--text); background: rgba(29,34,51,.92); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
#wm-btns button:active, #realm-btns button:active { background: #3a4466; }
#realm-info { position: absolute; top: 6px; right: 8px; z-index: 9; padding: 8px 12px; font-size: 13px; color: var(--text); background: rgba(29,34,51,.95); border: 3px solid #0b0d14; box-shadow: 0 0 0 2px var(--line); }
#panel-toggle { width: 100%; text-align: left; padding: 8px 4px; font-size: 13px; color: var(--gold); background: none; border: 0; border-bottom: 1px solid var(--line); margin-bottom: 8px; }

/* tablets / narrow laptops */
@media (max-width: 1100px) {
  #hud { gap: 8px; padding: 5px 8px; }
  .logo { font-size: 16px; letter-spacing: 1px; }
  .chip { min-width: 76px; font-size: 12px; }
  #panel { width: 232px; }
  #screen-diplo.active { grid-template-columns: 250px 1fr 290px; gap: 8px; padding: 8px; }
  #screen-nation.active { grid-template-columns: 360px 1fr; gap: 8px; padding: 8px; }
  #realm-wrap { inset: 40px 220px 128px 0 !important; } #realm-side { width: 220px; }
  #city-tabs { right: 230px; }
}

/* phones and small tablets in portrait: bottom tab bar, bottom sheets, stacked screens */
@media (max-width: 820px) {
  #app { padding-bottom: calc(54px + env(safe-area-inset-bottom)); }
  #hud { flex-wrap: wrap; gap: 4px 6px; padding: calc(4px + env(safe-area-inset-top)) 8px 4px; }
  .logo { display: none; }
  #nation-tag { padding: 2px 6px; font-size: 12px; max-width: 46vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #war-flag { padding: 2px 6px; font-size: 11px; }
  #res { order: 5; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; gap: 5px; padding-bottom: 2px; scrollbar-width: none; }
  #res::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; min-width: 0; padding: 2px 6px; font-size: 11px; gap: 4px; }
  .chip small { margin-left: 4px; }
  #tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; gap: 0; background: var(--panel); border-top: 3px solid #0b0d14; box-shadow: 0 -2px 0 var(--line); padding-bottom: env(safe-area-inset-bottom); margin: 0; }
  #tabs button { flex: 1; min-height: 52px; font-size: 14px; padding: 6px 2px; border-width: 0 2px 0 0; border-color: var(--line); }
  #tabs button:last-child { border-right: 0; }
  #tabs button:active { transform: none; }
  #tabs kbd { display: none; }
  .badge { top: 4px; right: 18%; }

  /* world map: info panel becomes a bottom sheet */
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 38%; padding: 6px 12px 10px; border-width: 3px 0 0; box-shadow: 0 -2px 0 var(--line); z-index: 6; }
  #panel.collapsed { max-height: 42px; overflow: hidden; }
  #panel-toggle { display: block; position: sticky; top: 0; background: rgba(29,34,51,.98); z-index: 1; }
  #wm-btns { display: flex; bottom: calc(38% + 10px); }
  body.panel-collapsed #wm-btns { bottom: 56px; }
  .hint { display: none; }
  #tribe-bar { top: 6px; left: 6px; right: 6px; transform: none; max-width: none; flex-wrap: wrap; gap: 6px; padding: 6px 10px; justify-content: center; }
  #found-why { position: static; background: none; }
  #log { left: 6px; top: 4px; max-width: 72vw; font-size: 11px; } #log div:nth-child(n+4) { display: none; }

  /* realm */
  #city-tabs { top: 4px; left: 6px; right: 96px; max-height: 40px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
  #realm-wrap { inset: 46px 0 128px 0 !important; }
  #realm-info { display: block; }
  #realm-btns { display: flex; left: 8px; bottom: 138px; }
  #realm-side { top: 46px; bottom: 128px; width: min(88vw, 340px); transform: translateX(105%); transition: transform .18s steps(4); z-index: 8; box-shadow: -6px 0 24px rgba(0,0,0,.6), -2px 0 0 var(--line); }
  #realm-side.open { transform: none; }
  #buildbar { overflow-x: auto; padding: 6px; }

  /* diplomacy & nation: one scrolling column */
  #screen-diplo.active, #screen-nation.active { display: flex; flex-direction: column; overflow-y: auto; gap: 8px; padding: 8px; -webkit-overflow-scrolling: touch; }
  .dcol, .ncol { overflow: visible; flex: 0 0 auto; }
  .tech-grid { grid-template-columns: 1fr 1fr; }
  .nlist { max-height: none; }

  /* title & setup */
  .setup-card { width: 94vw; padding: 12px; }
  .srow { gap: 10px; }
  #menu { width: min(360px, 88vw); }
  .menu-btn { padding: 14px 16px; }
}
@media (max-width: 480px) {
  .tech-grid { grid-template-columns: 1fr; }
  .chips-row button { padding: 8px 10px; }
}
/* landscape phones: very little height */
@media (max-height: 460px) and (orientation: landscape) {
  #hud { padding-top: 2px; padding-bottom: 2px; }
  #realm-btns { bottom: 130px; }
}
@media (max-width: 820px) { .title-ui.in-setup .logo-wrap { display: none; } .title-ui.in-setup { padding-top: calc(10px + env(safe-area-inset-top)); } }
#lab-badge { white-space: nowrap; }
@media (max-width: 1100px) { #lab-badge { top: auto; bottom: calc(60px + env(safe-area-inset-bottom)); left: 8px; right: auto; transform: none; font-size: 10px; padding: 2px 6px; opacity: .9; } .lab-long { display: none; } }

/* co-op */
#coop-tag { display: flex; align-items: center; gap: 6px; padding: 3px 8px; background: #1a2a1a; border: 2px solid #5fbf6f; font-size: 12px; white-space: nowrap; }
#coop-tag.off { background: #3a1a1a; border-color: #e05555; }
#coop-text { cursor: default; } #coop-text[data-invite="1"] { cursor: pointer; text-decoration: underline dotted; }
#coop-exit { font-family: var(--font); font-size: 11px; color: var(--dim); background: none; border: 1px solid var(--line); padding: 1px 6px; cursor: pointer; }
#coop { gap: 8px; max-height: calc(100% - 20px); overflow-y: auto; }
.croom { background: #12162a; border: 2px solid var(--line); padding: 8px 10px; display: grid; gap: 6px; }
.croom .ch { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; } .croom .ch small { color: var(--dim); }
.croom .cm { font-size: 12px; } .croom .ca { display: flex; gap: 6px; flex-wrap: wrap; }
.croom .ci { display: flex; gap: 6px; } .croom .ci input { flex: 1; text-align: left; font-size: 14px; padding: 6px; }
.cform { display: grid; gap: 6px; } .cform input, .cform select { text-align: left; font-size: 14px; padding: 8px; font-family: var(--font); background: #0a0c16; color: var(--text); border: 2px solid #4a4a78; }
.cmsg { color: var(--gold); font-size: 12px; min-height: 1em; } .center { text-align: center; }
.btn.go { background: #2f6a3a; border-color: #6fd36f; } .btn.danger2 { background: #4a2020; border-color: #a05050; }
@media (max-width: 820px) { #coop-tag { font-size: 11px; padding: 2px 6px; max-width: 54vw; overflow: hidden; text-overflow: ellipsis; } .title-ui.in-setup #coop { width: 94vw; } }

/* ---- iPhone / Safari polish ---- */
html, body { position: fixed; inset: 0; width: 100%; }
#app { height: 100%; height: 100dvh; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
@supports (height: 100dvh) { html, body { height: 100dvh; } }
#title { padding-top: env(safe-area-inset-top); }
input, select, textarea { font-size: 16px; border-radius: 0; -webkit-appearance: none; appearance: none; }
select { background-image: linear-gradient(45deg, transparent 50%, #8d97b8 50%), linear-gradient(135deg, #8d97b8 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
button { -webkit-appearance: none; appearance: none; border-radius: 0; }
#tabs, #buildcats { -webkit-overflow-scrolling: touch; }

/* phone in landscape: little height, so slim bars and a side panel */
@media (max-height: 520px) and (orientation: landscape) {
  #app { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  #hud { flex-wrap: nowrap; gap: 6px; padding-top: 2px; padding-bottom: 2px; }
  #res { order: 0; flex: 1 1 auto; flex-wrap: nowrap; overflow-x: auto; }
  #nation-tag { max-width: 22vw; } #coop-tag { max-width: 28vw; }
  #tabs { position: fixed; left: env(safe-area-inset-left); right: env(safe-area-inset-right); bottom: 0; z-index: 40; background: var(--panel); border-top: 3px solid #0b0d14; gap: 0; padding-bottom: env(safe-area-inset-bottom); }
  #tabs button { flex: 1; min-height: 40px; padding: 2px; font-size: 13px; border-width: 0 2px 0 0; }
  #panel { top: 6px; right: 6px; bottom: 6px; left: auto; width: min(300px, 40vw); max-height: none; border-width: 3px; }
  #panel.collapsed { max-height: 42px; bottom: auto; }
  #wm-btns { bottom: 10px !important; left: calc(10px + env(safe-area-inset-left)); flex-direction: row; }
  #wm-btns button { width: 40px; height: 40px; }
  #realm-wrap { inset: 36px 0 112px 0 !important; }
  #buildbar { height: 78px; } #buildcats { bottom: 78px; height: 32px; }
  .bcard { height: 66px; width: 84px; } .bcard img { max-height: 32px; }
  #realm-side { top: 36px; bottom: 110px; }
  #realm-btns { bottom: 118px; flex-direction: row; }
  #realm-btns button { width: 40px; height: 40px; }
  .title-ui.in-setup { padding-top: 6px; }
  .setup-card { padding: 10px 16px; gap: 6px; max-height: calc(100% - 12px); overflow-y: auto; }
  #screen-diplo.active, #screen-nation.active { flex-direction: row; overflow-x: auto; }
  .dcol, .ncol { flex: 0 0 min(420px, 80vw); overflow-y: auto; max-height: 100%; }
}
@media (max-width: 820px) { #hud-sync { display: none; } }
@media (pointer: coarse) { #tabs kbd { display: none; } }
#nation-tag { white-space: nowrap; flex: 0 0 auto; }
@media (max-height: 520px) and (orientation: landscape) {
  #lab-badge { bottom: auto !important; top: 46px; left: 50% !important; transform: translateX(-50%) !important; }
  #log { max-width: 46vw; font-size: 11px; top: 44px; }
  #region-desc, #mode-msg:empty { display: none; }
  .setup-card .srow.btns { position: sticky; bottom: -10px; background: linear-gradient(transparent, #14142a 35%); padding-top: 8px; }
  .chip { font-size: 10px; padding: 1px 4px; }
}
.croom .cm .x { font-family: var(--font); font-size: 10px; color: var(--dim); background: none; border: 1px solid var(--line); padding: 0 4px; cursor: pointer; margin-left: 2px; } .croom .cm .x:hover { color: var(--bad); border-color: var(--bad); }
