:root {
  --ink: #f3e9d2;
  --muted: #b5a689;
  --gold: #e0b95c;
  --gold-hi: #ffe3a1;
  --blood: #b3261e;
  --panel: rgba(16, 12, 9, 0.84);
  --panel-hi: rgba(32, 24, 17, 0.92);
  --edge: rgba(224, 185, 92, 0.32);
  --edge-hi: rgba(224, 185, 92, 0.7);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0f14; color: var(--ink); font-family: 'Crimson Text', Georgia, serif; font-size: 16px; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.hidden { display: none !important; }
h1, h2, h3, button, kbd { font-family: 'Cinzel', serif; }
body:not(.touch) .touch-only { display: none !important; }
body.touch .desk-only { display: none !important; }

input, select { background: rgba(10, 8, 6, .75); color: var(--ink); border: 1px solid var(--edge); border-radius: 8px; padding: 11px 12px; font: inherit; font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224, 185, 92, .18); }
button { background: linear-gradient(#2c2117, #1d160f); color: var(--ink); border: 1px solid var(--edge); border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; letter-spacing: .4px; touch-action: manipulation; transition: border-color .12s, transform .08s, background .12s; }
button:hover:not(:disabled) { border-color: var(--gold); }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .42; cursor: not-allowed; }
button.primary { width: 100%; padding: 12px; background: linear-gradient(#8e2219, #5a120c); border-color: #d06a4f; font-size: 15px; font-weight: 700; color: #fff4e0; box-shadow: 0 6px 18px rgba(140, 30, 20, .35), inset 0 1px 0 rgba(255, 200, 160, .25); }
button.primary.big { padding: 14px; font-size: 16px; margin-top: 6px; }
button.primary:hover:not(:disabled) { background: linear-gradient(#a3281f, #6a160e); }
button.link { background: none; border: none; color: var(--gold); font-family: 'Crimson Text', serif; font-size: 15px; padding: 8px 4px; text-decoration: underline; text-underline-offset: 3px; }
button.danger { border-color: #a3281f; color: #f4b0a5; }
kbd { font-size: 9px; }

/* ---------- Auth ---------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 30; padding: 16px; overflow-y: auto; }
.overlay.auth { background: radial-gradient(ellipse at 50% 30%, #3a1d10 0%, #170c07 45%, #050302 100%); }
.embers { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.embers::before, .embers::after { content: ''; position: absolute; inset: -50% 0 0 0; background-image: radial-gradient(2px 2px at 20% 30%, #ff9a4a, transparent), radial-gradient(1.5px 1.5px at 70% 60%, #ffb36b, transparent), radial-gradient(2px 2px at 40% 80%, #ff7a2a, transparent), radial-gradient(1px 1px at 85% 20%, #ffd08a, transparent), radial-gradient(1.5px 1.5px at 10% 70%, #ff8a3a, transparent), radial-gradient(1px 1px at 55% 15%, #ffc070, transparent); background-size: 340px 340px; animation: rise 14s linear infinite; opacity: .7; }
.embers::after { background-size: 520px 520px; animation-duration: 22s; opacity: .45; }
@keyframes rise { from { transform: translateY(0); } to { transform: translateY(-340px); } }
.auth-card { position: relative; width: min(430px, 100%); background: linear-gradient(180deg, rgba(30, 21, 14, .94), rgba(14, 10, 7, .96)); border: 1px solid var(--edge); border-radius: 16px; padding: 28px 26px 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 220, 160, .08); }
.auth-card::before { content: ''; position: absolute; inset: 6px; border: 1px solid rgba(224, 185, 92, .12); border-radius: 12px; pointer-events: none; }
.crest { width: 64px; height: 64px; margin: -60px auto 8px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; background: radial-gradient(circle at 35% 30%, #5a2a14, #1e0f07); border: 2px solid var(--gold); box-shadow: 0 0 24px rgba(224, 120, 50, .45); }
.auth-card h1 { margin: 0; text-align: center; font-weight: 900; font-size: clamp(25px, 7.4vw, 32px); letter-spacing: 1.5px; background: linear-gradient(#ffe7a8, #c9932f); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-card .sub { margin: 4px 0 18px; text-align: center; color: var(--muted); font-style: italic; }
.view label { display: block; margin: 12px 0; color: var(--muted); font-size: 14px; }
.view input { display: block; width: 100%; margin-top: 5px; }
.pw { position: relative; display: block; }
.pw input { padding-right: 46px; }
.pw button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 18px; padding: 6px 8px; margin-top: 2.5px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: rgba(0, 0, 0, .35); border: 1px solid var(--edge); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: none; padding: 10px; color: var(--muted); border-radius: 8px; font-size: 14px; }
.seg button.on { background: linear-gradient(#3b2a1b, #2a1e13); color: var(--gold-hi); box-shadow: inset 0 0 0 1px var(--edge); }
.view .link { display: block; margin: 8px auto 0; }
.hint { color: var(--muted); text-align: center; margin: 0 0 6px; }
.msg { min-height: 22px; margin-top: 10px; text-align: center; font-size: 15px; }
.msg.err { color: #ff9b8a; } .msg.ok { color: #9fe0a8; }
.welcome-name { text-align: center; font-family: 'Cinzel', serif; font-size: 24px; font-weight: 700; color: var(--gold-hi); }
.welcome-email { text-align: center; color: var(--muted); margin-bottom: 14px; }
.claim { text-align: center; border: 1px dashed var(--edge); border-radius: 10px; padding: 10px 12px 4px; margin-bottom: 8px; }
.claim p { margin: 0 0 8px; }
.or { text-align: center; color: var(--muted); font-size: 13px; margin: 10px 0 2px; font-style: italic; }
.origins { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 210px; overflow-y: auto; padding: 2px; margin-bottom: 8px; }
.origin { text-align: left; padding: 8px 10px; font-family: 'Crimson Text', serif; font-size: 14px; line-height: 1.15; }
.origin b { display: block; font-family: 'Cinzel', serif; font-size: 12px; color: var(--ink); }
.origin i { color: var(--muted); font-size: 12px; }
.origin.sel { border-color: var(--gold); background: linear-gradient(#4a3420, #2c1f13); box-shadow: 0 0 0 1px var(--gold); }
.howto { margin-top: 12px; color: var(--muted); font-size: 14px; }
.howto summary { cursor: pointer; color: var(--gold); text-align: center; }
.howto ul { padding-left: 18px; margin: 6px 0; }
.spinner { width: 34px; height: 34px; margin: 14px auto; border-radius: 50%; border: 3px solid rgba(224, 185, 92, .2); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading { background: radial-gradient(ellipse at center, rgba(30, 16, 8, .9), #050302); }
.card { background: var(--panel-hi); border: 1px solid var(--edge); border-radius: 14px; padding: 24px; width: min(460px, 100%); box-shadow: var(--shadow); text-align: center; }
.card h2 { color: var(--gold); margin: 0 0 6px; }
.card .sub { color: var(--muted); font-style: italic; }

/* ---------- HUD frames ---------- */
.panel { position: fixed; background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; z-index: 5; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); box-shadow: var(--shadow); }
#frames { position: fixed; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); display: flex; gap: 8px; align-items: flex-start; z-index: 6; }
.frame { position: relative; display: flex; gap: 10px; align-items: flex-start; background: linear-gradient(180deg, rgba(26, 19, 13, .9), rgba(12, 9, 6, .88)); border: 1px solid var(--edge); border-radius: 12px; padding: 9px 12px 9px 9px; box-shadow: var(--shadow); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
#unit { width: 290px; }
.portrait { flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-family: 'Cinzel', serif; font-weight: 700; color: #fff; border: 2px solid var(--gold); box-shadow: 0 0 0 3px rgba(0, 0, 0, .4), inset 0 -8px 16px rgba(0, 0, 0, .35); background: #6d5a42; text-shadow: 0 2px 4px rgba(0, 0, 0, .6); }
.fbody { flex: 1; min-width: 0; }
.fname { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; }
.badge { margin-left: 6px; font-size: 13px; }
.ftitle { color: var(--gold); font-family: 'Cinzel', serif; font-size: 11px; letter-spacing: .6px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { position: relative; height: 14px; background: rgba(0, 0, 0, .55); border-radius: 7px; overflow: hidden; margin: 3px 0; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6); }
.bar > div { height: 100%; border-radius: 7px; transition: width .18s ease-out; }
.bar.hp > div { background: linear-gradient(180deg, #e2523f, #9a1d14); box-shadow: inset 0 1px 0 rgba(255, 170, 150, .4); }
.bar.st > div { background: linear-gradient(180deg, #6cc2e6, #2a6e90); }
.bar.fd > div { background: linear-gradient(180deg, #f0c968, #9a7520); }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 14px; font-weight: 600; text-shadow: 0 1px 2px #000; }
.bars2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bars2 .bar { height: 6px; margin: 2px 0 4px; }
.chips { display: flex; gap: 12px; font-size: 14px; }
.chips b { font-weight: 600; }
.flags { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 0; }
.flags span { display: inline-block; margin-right: 8px; }
.frame.target { width: 250px; border-color: rgba(220, 90, 70, .55); }
.frame.target .portrait { border-color: #d0624a; width: 46px; height: 46px; font-size: 22px; }
.frame.target.friendly { border-color: rgba(110, 200, 130, .55); }
.frame.target.friendly .portrait { border-color: #6ec882; }
.tnote { font-size: 12px; color: var(--muted); font-style: italic; }
.tbtn { position: absolute; top: 4px; padding: 0; width: 26px; height: 26px; border-radius: 6px; font-size: 13px; background: rgba(0, 0, 0, .35); }
#tMore { right: 32px; } #tClear { right: 4px; }

#topCenter { position: fixed; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 5; max-width: calc(100vw - 640px); }
.pill { background: var(--panel); border: 1px solid var(--edge); border-radius: 999px; padding: 5px 14px; font-size: 14px; text-align: center; box-shadow: var(--shadow); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill .bush { color: #e8b077; } .pill .road { color: #9fd8a9; }
.pill.bg { border-color: rgba(220, 90, 70, .6); background: linear-gradient(180deg, rgba(70, 18, 12, .92), rgba(30, 8, 6, .92)); white-space: normal; border-radius: 12px; padding: 7px 14px; }
.pill.bg .bgt { font-family: 'Cinzel', serif; font-weight: 700; color: var(--gold-hi); }
.pill.bg .bgtop { font-size: 12px; color: var(--muted); }
.pill.bg .bgtop b { color: var(--ink); }
.pill.bg button { margin-left: 8px; padding: 4px 10px; font-size: 11px; }

#topRight { position: fixed; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; gap: 6px; z-index: 7; }
.iconbtn { width: 44px; height: 44px; padding: 0; font-size: 19px; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
#feed { position: fixed; top: calc(62px + var(--safe-t)); right: calc(12px + var(--safe-r)); z-index: 4; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; }
#feed div { background: rgba(10, 6, 4, .75); border-right: 3px solid var(--blood); padding: 3px 10px; font-size: 14px; border-radius: 4px; animation: fade 6s forwards; }
#feed .k { color: var(--gold-hi); font-weight: 600; } #feed .v { color: #f0a99f; }

/* ---------- side panel ---------- */
#side { top: calc(64px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: 320px; max-height: calc(100vh - 300px); overflow-y: auto; }
body:not(.touch) #side:not(.open) { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--edge); position: sticky; top: 0; background: #17110b; z-index: 1; border-radius: 10px 10px 0 0; }
.tabs button { flex: 1; border: none; border-radius: 0; background: transparent; padding: 11px 0; color: var(--muted); }
.tabs button.active { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
.tabs button.close { flex: 0 0 44px; }
.tab { padding: 12px 14px; }
.tab h3 { margin: 0 0 2px; color: var(--gold); font-size: 17px; }
.tab .real { color: var(--muted); font-style: italic; font-size: 13px; margin-bottom: 6px; }
.tab .lore { font-size: 14px; margin: 6px 0 10px; }
.tab .row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin: 3px 0; }
.tab .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.tab .actions button { padding: 10px 6px; }
.tab .actions button.wide { grid-column: span 2; }
.tab label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 2px; }
.tab input, .tab select { width: 100%; padding: 8px 10px; }
.sigils, .colors { display: flex; flex-wrap: wrap; gap: 4px; }
.sigils button { padding: 4px 6px; font-size: 20px; }
.colors button { width: 32px; height: 32px; padding: 0; }
.sigils button.sel, .colors button.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.member { font-size: 14px; display: flex; justify-content: space-between; }
.member .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; background: #555; }
.member .dot.on { background: #5fd27a; }
.note { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 8px; }
.cap { height: 6px; background: #2a2016; border-radius: 3px; overflow: hidden; margin: 4px 0 8px; }
.cap > div { height: 100%; background: var(--gold); }
.realm-house { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid rgba(224, 185, 92, .12); font-size: 14px; }
.realm-house .sw { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.realm-house .nm { flex: 1; }
.tollrow { display: flex; gap: 6px; align-items: center; }
.tollrow input { width: 90px; }
.account { margin-top: 16px; padding-top: 10px; border-top: 1px solid rgba(224, 185, 92, .15); font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- chat ---------- */
#chat { left: calc(10px + var(--safe-l)); bottom: calc(10px + var(--safe-b)); width: 380px; height: 190px; display: flex; flex-direction: column; }
#log { flex: 1; overflow-y: auto; padding: 8px 10px; font-size: 14px; line-height: 1.35; -webkit-user-select: text; user-select: text; }
#log .ev { color: var(--gold); font-style: italic; }
#log .ev.war { color: #ff9b7d; }
#log .ev.throne { color: #ffd76a; font-weight: 600; font-style: normal; }
#log .ev.quiet { color: #8a7d66; }
#log .ch b { color: #ecdcb2; }
#log .ch.house { color: #9fd3a8; }
#chatForm { display: flex; gap: 4px; padding: 6px; border-top: 1px solid var(--edge); }
#chatForm select { width: 82px; padding: 6px; }
#chatForm input { flex: 1; padding: 6px 8px; min-width: 0; }
#ticker { position: fixed; left: calc(12px + var(--safe-l)); bottom: calc(190px + var(--safe-b)); width: min(58vw, 340px); font-size: 13px; line-height: 1.3; z-index: 4; pointer-events: none; text-shadow: 0 1px 3px #000, 0 0 2px #000; }
#ticker div { animation: fade 8s forwards; }

#minimap { position: fixed; right: calc(12px + var(--safe-r)); bottom: calc(12px + var(--safe-b)); width: 200px; height: 162px; border-radius: 10px; border: 1px solid var(--edge); box-shadow: var(--shadow); cursor: pointer; z-index: 5; }

/* ---------- abilities ---------- */
#abilities { position: fixed; z-index: 6; display: flex; gap: 14px; align-items: flex-end; }
.group { display: flex; gap: 7px; }
.ab { position: relative; width: 58px; height: 58px; padding: 0; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(180deg, rgba(44, 32, 22, .92), rgba(18, 13, 9, .92)); border: 1px solid var(--edge); box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 220, 160, .1); overflow: hidden; }
.ab i { font-style: normal; font-size: 24px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .6)); }
.ab small { font-size: 8px; margin-top: 3px; color: var(--muted); letter-spacing: .3px; }
.ab kbd { position: absolute; top: 3px; left: 5px; color: var(--gold); opacity: .8; }
.ab .cd { position: absolute; inset: 0; pointer-events: none; background: conic-gradient(rgba(0, 0, 0, .68) calc(var(--p, 0) * 360deg), transparent 0); }
.ab.ready { border-color: var(--edge-hi); }
.ab.on { border-color: var(--gold); background: linear-gradient(180deg, rgba(110, 76, 30, .95), rgba(50, 34, 14, .95)); box-shadow: 0 0 16px rgba(224, 185, 92, .45); }
.ab.flash { animation: abflash .25s; }
@keyframes abflash { from { box-shadow: 0 0 0 3px var(--gold-hi), 0 0 24px rgba(255, 220, 140, .8); } }
.ab.main { border-color: rgba(220, 100, 70, .7); }
.ab.sm { width: 50px; height: 50px; }
.ab.sm i { font-size: 20px; }
body:not(.touch) #abilities { left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); }
body:not(.touch) .ab.sm small, body:not(.touch) .ab small { display: block; }

/* Touch layout: a fight cluster for the right thumb */
body.touch #abilities { right: calc(10px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); width: 214px; height: 250px; display: block; }
body.touch .ab kbd { display: none; }
body.touch .group.fight .ab { position: absolute; border-radius: 50%; width: 64px; height: 64px; }
body.touch .group.fight .ab i { font-size: 26px; }
body.touch #abLight { right: 0; bottom: 0; width: 92px; height: 92px; }
body.touch #abLight i { font-size: 38px; }
body.touch #abHeavy { right: 104px; bottom: 6px; }
body.touch #abBlock { right: 16px; bottom: 104px; }
body.touch #abDodge { right: 92px; bottom: 80px; width: 58px; height: 58px; }
body.touch .group.util { position: absolute; right: 0; top: 0; flex-direction: row; gap: 6px; }
body.touch .group.util .ab { border-radius: 50%; width: 46px; height: 46px; }
body.touch .group.util .ab small { font-size: 7px; }

/* Joystick */
#joy { position: fixed; left: calc(22px + var(--safe-l)); bottom: calc(26px + var(--safe-b)); width: 136px; height: 136px; border-radius: 50%; background: radial-gradient(circle, rgba(243, 233, 210, .1), rgba(243, 233, 210, .03)); border: 2px solid rgba(224, 185, 92, .35); z-index: 6; touch-action: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, rgba(255, 230, 160, .85), rgba(190, 140, 60, .7)); border: 2px solid rgba(255, 233, 168, .85); box-shadow: 0 4px 12px rgba(0, 0, 0, .4); }

/* ---------- world labels ---------- */
#plates { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.plate { position: absolute; left: 0; top: 0; text-align: center; white-space: nowrap; text-shadow: 0 1px 3px #000, 0 0 2px #000; will-change: transform; }
.plate .nm { font-weight: 600; font-size: 14px; }
.plate .ti { font-family: 'Cinzel', serif; font-size: 10px; color: var(--gold); }
.plate .hpb { width: 46px; height: 5px; background: rgba(0, 0, 0, .65); margin: 2px auto 0; border-radius: 3px; overflow: hidden; }
.plate .hpb > div { height: 100%; }
.plate.bandit .nm { color: #ffb4a3; }
.plate.me .nm { color: var(--gold-hi); }
.plate.targeted .nm { color: #ff8a70; }
.plate.targeted::after { content: '▼'; display: block; color: #ff6a4a; font-size: 12px; line-height: 1; animation: bob .8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
.plate.city .nm { font-family: 'Cinzel', serif; font-size: 20px; font-weight: 700; color: #f8eed6; }
.plate.city .ti { font-family: 'Crimson Text', serif; font-style: italic; font-size: 13px; color: #e6dcc0; }
.plate.arena .nm { font-family: 'Cinzel', serif; font-size: 20px; font-weight: 900; color: #ffb39b; }
.plate.post .nm { font-size: 12px; color: #ecd096; font-family: 'Cinzel', serif; }
.plate.fx { font-family: 'Cinzel', serif; font-weight: 900; font-size: 19px; }
.plate.fx.crit { font-size: 26px; color: #ffd34d !important; }
.plate.fx.small { font-size: 14px; }

#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 3; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 0, 0, .55) 100%); transition: opacity .25s; }

/* ---------- toasts, menus ---------- */
#toasts { position: fixed; top: calc(118px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 15; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: min(92vw, 520px); }
.toast { background: var(--panel-hi); border: 1px solid var(--edge); padding: 7px 16px; border-radius: 10px; font-size: 15px; animation: toastIn .2s ease-out, fade 4s forwards; pointer-events: auto; text-align: center; box-shadow: var(--shadow); }
.toast button { margin: 6px 4px 0; padding: 8px 12px; }
@keyframes toastIn { from { transform: translateY(-6px); opacity: 0; } }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.toast.sticky { animation: toastIn .2s ease-out; }
#ctx { padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 200px; z-index: 12; }
#ctx .hd { font-family: 'Cinzel', serif; color: var(--gold); font-size: 13px; padding: 2px 4px 4px; }
#ctx button { padding: 10px 12px; text-align: left; }

/* ---------- map ---------- */
#mapOverlay { position: fixed; inset: 0; z-index: 20; background: rgba(5, 7, 10, .9); display: grid; place-items: center; padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); }
.mapwrap { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
#bigmap { max-width: 100%; max-height: 100%; border: 1px solid var(--edge); border-radius: 10px; touch-action: none; cursor: pointer; box-shadow: var(--shadow); }
#mapClose { position: absolute; top: 0; right: 0; }
#mapInfo { position: absolute; left: 0; top: 0; width: 290px; padding: 14px; }
#mapInfo:empty { display: none; }
#mapInfo h3 { margin: 0; color: var(--gold); font-size: 17px; }
#mapInfo .real { color: var(--muted); font-style: italic; font-size: 13px; }
#mapInfo .row { display: flex; justify-content: space-between; font-size: 14px; margin: 3px 0; }
#mapInfo button { width: 100%; margin-top: 8px; padding: 10px; }
.maplegend { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); font-size: 13px; color: var(--muted); background: var(--panel); padding: 4px 12px; border-radius: 999px; white-space: nowrap; }

/* ---------- results & death ---------- */
#bgResults { background: rgba(10, 4, 2, .7); z-index: 22; }
.card.results .crest { margin: -56px auto 6px; }
#bgTable table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 15px; }
#bgTable th { font-family: 'Cinzel', serif; font-size: 11px; color: var(--muted); font-weight: 500; text-align: right; padding: 4px; }
#bgTable th:nth-child(2), #bgTable td:nth-child(2) { text-align: left; }
#bgTable td { padding: 6px 4px; text-align: right; border-top: 1px solid rgba(224, 185, 92, .12); }
#bgTable tr.first td { color: var(--gold-hi); font-weight: 600; }
#deathScreen { position: fixed; inset: 0; z-index: 9; display: grid; place-content: center; text-align: center; background: radial-gradient(ellipse at center, rgba(60, 0, 0, .25), rgba(40, 0, 0, .75)); pointer-events: none; }
#deathScreen h2 { font-size: clamp(28px, 8vw, 46px); color: #ff8a7a; margin: 0; letter-spacing: 2px; text-shadow: 0 4px 20px #000; }
#deathScreen p { font-size: 18px; }

/* ---------- phones ---------- */
body.touch #frames { flex-direction: column; gap: 6px; }
body.touch #unit { width: min(60vw, 236px); padding: 6px 8px 6px 6px; gap: 7px; }
body.touch .portrait { width: 40px; height: 40px; font-size: 19px; }
body.touch .fname { font-size: 14px; }
body.touch .chips { font-size: 12px; gap: 8px; }
body.touch .flags { font-size: 11px; }
body.touch .frame.target { width: min(60vw, 236px); padding: 6px 8px 6px 6px; }
body.touch .frame.target .portrait { width: 36px; height: 36px; font-size: 16px; }
body.touch #topCenter { top: auto; bottom: calc(176px + var(--safe-b)); max-width: 62vw; left: calc(12px + var(--safe-l)); transform: none; align-items: flex-start; }
body.touch .pill { font-size: 12px; padding: 4px 10px; }
body.touch #topRight { flex-direction: column; }
body.touch #feed { top: auto; bottom: calc(280px + var(--safe-b)); }
body.touch #side { inset: 0; width: auto; max-height: none; border-radius: 0; z-index: 25; padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
body.touch #side:not(.open) { display: none; }
body.touch #chat { inset: auto 0 0 0; width: auto; height: 50vh; border-radius: 14px 14px 0 0; z-index: 25; padding-bottom: var(--safe-b); }
body.touch #chat:not(.open) { display: none; }
body.touch .toast { font-size: 13px; }
body.touch #toasts { top: calc(150px + var(--safe-t)); width: min(70vw, 360px); left: auto; right: calc(64px + var(--safe-r)); transform: none; align-items: flex-end; }
body.touch #mapInfo { top: auto; bottom: 30px; left: 50%; transform: translateX(-50%); width: min(92%, 320px); }
body.touch #ticker { bottom: calc(300px + var(--safe-b)); }

@media (max-width: 1150px) { body:not(.touch) #topCenter { max-width: calc(100vw - 660px); } }
@media (orientation: landscape) and (max-height: 500px) {
  body.touch #frames { flex-direction: row; }
  body.touch #unit, body.touch .frame.target { width: 200px; }
  body.touch #topCenter { bottom: auto; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); align-items: center; max-width: 30vw; }
  body.touch #toasts { top: calc(56px + var(--safe-t)); right: calc(56px + var(--safe-r)); width: 38vw; }
  body.touch #topRight { flex-direction: row; }
  body.touch #feed { bottom: auto; top: calc(60px + var(--safe-t)); }
  body.touch #abilities { transform: scale(.82); transform-origin: bottom right; }
  body.touch #joy { width: 120px; height: 120px; bottom: calc(16px + var(--safe-b)); }
  body.touch #ticker { bottom: calc(150px + var(--safe-b)); width: 30vw; }
}

/* lands & empires */
.land { border: 1px solid rgba(224, 185, 92, .18); border-radius: 8px; padding: 6px 8px 8px; margin: 6px 0; background: rgba(0, 0, 0, .2); }
.land label { margin-top: 6px; }
.land .tollrow { margin-top: 6px; }
.land select { flex: 1; padding: 6px; }
.tab .actions button.on { border-color: var(--gold); color: var(--gold-hi); opacity: 1; }
.empire { border-bottom: 1px solid rgba(224, 185, 92, .1); padding-top: 4px; }
