:root {
  color-scheme: dark;
  --bg: #0d0918;
  --panel: #1a1229;
  --glass: #1b122cef;
  --line: #4c3a65;
  --text: #faf4ff;
  --muted: #c3b4d7;
  --dim: #a39ab7;
  --accent: #d4baff;
  --secondary: #a9aaff;
  --violet: #e5aeff;
  --success: #a9efca;
  --danger: #ff929d;
  --mono: 'Cascadia Mono', Consolas, monospace;
  --topbar-height: 58px;
  font: 16px/1.5 'Segoe UI', 'Microsoft YaHei UI', 'PingFang SC', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, select, input[type='checkbox'], input[type='range'] { cursor: pointer; }
button { min-height: 42px; border: 1px solid #594478; border-radius: 8px; padding: .45rem .82rem; white-space: nowrap; color: var(--text); background: #2a1e42; font-size: .875rem; font-weight: 650; transition: background .16s, border-color .16s, box-shadow .16s; }
button:hover { border-color: #a788d9; background: #3a2857; }
button:disabled { opacity: .48; cursor: default; }
button.primary { border-color: #dfc8ff; color: #180b2a; background: #c9abff; box-shadow: 0 0 18px #ad7dff26; }
button.primary:hover { background: #e3cfff; box-shadow: 0 0 22px #b289ff4a; }
button.violet { border-color: #8156a5; color: #eed3ff; background: #38214c; }
button.violet:hover { background: #4b2d65; }
button.flat { border-color: transparent; background: transparent; color: var(--muted); }
button.flat:hover { border-color: #5c4777; color: var(--text); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input:not([type='checkbox'], [type='range']), select { min-width: 0; min-height: 40px; padding: .45rem .65rem; border: 1px solid #594478; border-radius: 7px; background: #130c22; color: var(--text); }
input::placeholder { color: var(--dim); }
input[type='checkbox'], input[type='range'] { accent-color: var(--accent); }
input[type='checkbox'] { width: 1.05rem; height: 1.05rem; margin: 0; }
input[type='range'] { width: 100%; margin: .4rem 0 .7rem; }
label { display: block; color: var(--muted); font-size: .86rem; }
.check { display: flex; gap: .5rem; align-items: center; min-height: 27px; }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
.muted { color: var(--muted); font-size: .875rem; }
.panel { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }

.topbar { position: relative; z-index: 8; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; min-height: var(--topbar-height); padding: 0 clamp(.85rem, 2.5vw, 2rem); border-bottom: 1px solid #49375f; background: #130c20; }
.brand { display: flex; align-items: center; gap: .68rem; color: var(--text); font: 800 1.04rem/1.1 var(--mono); letter-spacing: .18em; }
.brand-icon { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid #72559b; border-radius: 8px; background: #2a1d41; color: var(--accent); font: 1.25rem/1 sans-serif; box-shadow: 0 0 16px #b886ff26 inset; }
.brand small { margin-left: .55rem; color: var(--muted); font: 650 .78rem/1.2 'Microsoft YaHei UI', system-ui, sans-serif; letter-spacing: .08em; }
.topbar-version { color: var(--muted); font: 600 .76rem var(--mono); letter-spacing: .13em; white-space: nowrap; }
.topbar-version span { margin-left: .45rem; color: var(--accent); }
.connection { justify-self: end; display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .82rem; white-space: nowrap; }
.connection i, .eyebrow span { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--dim); }
.connection[data-connection='online'] i { background: var(--success); box-shadow: 0 0 10px #a9efca80; }
.connection[data-connection='connecting'] i { background: #ffd486; }
.connection[data-connection='offline'] i { background: var(--danger); }

.landing { position: relative; isolation: isolate; min-height: calc(100svh - var(--topbar-height)); overflow: hidden; }
#preview-canvas { position: absolute; inset: 0; z-index: -2; height: 100%; width: 100%; }
.landing::after { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, #0d0918ee 0%, #0d0918a5 36%, #14091c35 70%, #0d091880 100%), linear-gradient(0deg, var(--bg) 2%, transparent 65%); pointer-events: none; }
.landing-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 390px); align-items: center; column-gap: clamp(2rem, 6vw, 6rem); row-gap: 2.1rem; width: min(100% - 3rem, 1120px); padding: clamp(3rem, 11vh, 7.5rem) 0 3rem; margin: auto; }
.hero { padding-block: 1.5rem; }
.eyebrow { display: flex; align-items: center; gap: .55rem; font: 650 .76rem/1.4 var(--mono); color: var(--accent); letter-spacing: .14em; }
.eyebrow span { width: 6px; height: 6px; border-radius: 1px; transform: rotate(45deg); background: var(--accent); box-shadow: 0 0 12px #bc9aff99; }
.hero h1 { margin: .8rem 0 1.25rem; color: var(--text); font-size: clamp(3.6rem, 8vw, 6.5rem); line-height: .98; font-weight: 800; letter-spacing: -.07em; text-shadow: 0 0 45px #b982f64a; }
.hero h1 span { display: block; margin: .7rem 0 0 .05em; color: var(--accent); font: 750 clamp(1.5rem, 3.4vw, 2.85rem)/1 var(--mono); letter-spacing: .22em; }
.hero p { max-width: 26em; color: #e0d5ed; font-size: clamp(1rem, 1.7vw, 1.19rem); text-wrap: balance; }
.hero-meta { display: flex; flex-wrap: wrap; gap: .55rem 1.15rem; margin-top: 1.35rem; color: var(--muted); font-size: .85rem; }
.hero-meta span { display: flex; align-items: center; gap: .4rem; }
.hero-meta span::before { width: .3rem; height: .3rem; border-radius: 50%; background: var(--secondary); content: ''; }
.entry-card, .public-card { padding: 1.35rem; border: 1px solid #594477; border-radius: 12px; background: var(--glass); box-shadow: 0 16px 48px #0005, 0 0 24px #9f6bdf12 inset; }
.entry-card header { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.05rem; }
.section-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 9px; border: 1px solid #705296; color: var(--accent); background: #2e1e45; font-size: 1.65rem; line-height: 1; }
.entry-card h2 { font-size: 1.25rem; }
.entry-card header p { margin-top: .08rem; color: var(--muted); font-size: .84rem; }
.entry-card > input { width: 100%; margin-top: .35rem; }
.entry-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin: .8rem 0 1rem; }
.join-form { display: grid; gap: .4rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.join-form > div { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
#join-code { font-family: var(--mono); text-transform: uppercase; }
.resume-list { display: grid; gap: .35rem; margin-top: .8rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.resume-list button { min-width: 0; white-space: normal; text-align: left; }
.public-card { grid-column: 1 / -1; background: #160e23d9; box-shadow: none; }
.public-card header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .55rem; }
.public-card h2 { font-size: 1rem; }
.public-card button { min-height: 34px; }
#room-list { max-height: 210px; overflow: auto; }
#room-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 0; color: var(--muted); font-size: .875rem; }
#room-list li + li { border-top: 1px solid var(--line); }
#room-list strong { color: var(--text); font-family: var(--mono); }

.waiting { display: grid; min-height: calc(100svh - var(--topbar-height)); align-content: start; justify-content: center; padding: clamp(2rem, 8vh, 5.5rem) 1rem; background: radial-gradient(ellipse at 50% 4%, #34204f 0%, #170f2b 36%, var(--bg) 75%); }
.waiting-card { width: min(550px, calc(100vw - 2rem)); padding: clamp(1.25rem, 4vw, 2rem); box-shadow: 0 24px 70px #0005; }
.waiting h1 { margin: .45rem 0 .35rem; font-size: 2rem; }
.room-state { color: var(--muted); font-size: .9rem; }
.invite-card { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin: 1.1rem 0 .75rem; padding: .75rem .9rem; border: 1px solid #5e467f; border-radius: 8px; background: #2b1b43; }
.invite-card span { display: block; color: var(--muted); font-size: .8rem; }
.invite-card strong { color: var(--accent); font: 750 1.2rem var(--mono); letter-spacing: .12em; }
#room-players { margin-bottom: .8rem; }
#room-players li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .65rem .2rem; border-bottom: 1px solid var(--line); }
.presence { flex: none; color: var(--muted); font-size: .8rem; }
.presence[data-presence='connected'] { color: var(--success); }
.presence[data-presence='ai'] { color: var(--violet); }
.waiting-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.game { --hud-gap: clamp(.7rem, 1.45vw, 1.35rem); }
.game-grid { position: relative; height: calc(100dvh - var(--topbar-height)); min-height: 515px; isolation: isolate; overflow: hidden; }
.map-shell { position: absolute; inset: 0; background: var(--bg); }
#map-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map-canvas.dragging { cursor: grabbing; }
.map-tools { position: absolute; z-index: 1; bottom: var(--hud-gap); left: 50%; transform: translateX(-50%); display: flex; gap: 3px; padding: 4px; border: 1px solid #554272; border-radius: 10px; background: #1b122be8; }
.map-tools button { width: 40px; min-height: 36px; padding: 0; border-color: transparent; background: transparent; font-size: 1.15rem; line-height: 1; }
.map-tools button:hover { border-color: #654e87; background: #2d1e4a; }
.map-staging { position: absolute; z-index: 2; left: 50%; bottom: calc(var(--hud-gap) + 55px); display: none; align-items: center; gap: .35rem; max-width: min(43%, 340px); transform: translateX(-50%); padding: .21rem .25rem .21rem .52rem; border: 1px solid #69538c; border-radius: 8px; background: #1f1637eb; color: var(--accent); font-size: .82rem; }
.map-staging:has(> :not([hidden])) { display: flex; }
#map-source { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#action-cancel { min-height: 30px; padding: .18rem .36rem; font-size: .75rem; }

.hud { position: absolute; z-index: 2; min-width: 0; background: linear-gradient(160deg, #271a3bed, #130d24e6); border-color: #594477; border-radius: 12px; box-shadow: 0 8px 28px #05021065, inset 0 1px #dfc7ff20; }
.hud-player { top: var(--hud-gap); left: var(--hud-gap); width: min(244px, 30%); padding: .8rem .9rem .55rem; }
.player-identity { display: grid; gap: .19rem; color: var(--accent); font-size: 1.14rem; line-height: 1.21; overflow-wrap: anywhere; }
.player-identity > strong::before { content: ''; display: inline-block; width: .45rem; height: .45rem; margin: 0 .44rem .13rem .09rem; border: 1px solid #cdb3ff; transform: rotate(45deg); background: #9772d8; box-shadow: 0 0 12px #aa7dff79; }
.player-identity > span { color: var(--muted); font-size: .78rem; }
.player-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .34rem; margin-top: .5rem; color: var(--text); font-variant-numeric: tabular-nums; }
.player-facts span { display: flex; align-items: baseline; flex-wrap: wrap; gap: .03rem .34rem; border: 1px solid #594277; border-radius: 6px; padding: .19rem .36rem; background: #261a3c; }
.player-facts strong { color: var(--text); font: 700 .98rem/1.35 var(--mono); }
.player-facts small { color: var(--muted); font-size: .72rem; }
.player-map-meta { display: flex; justify-content: space-between; align-items: center; gap: .23rem; margin-top: .26rem; color: var(--muted); font-size: .75rem; }
.player-map-meta button { min-height: 28px; padding: .1rem .38rem; font-size: .75rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: .35rem .6rem; color: var(--muted); font-size: .75rem; }
.map-legend span { display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; }
.map-legend i { flex: none; width: .72rem; height: .72rem; border: 1px solid #bda4ff; border-radius: 50%; }
.map-legend .neutral-key { border: 1px dotted #a6acc4; }
.map-legend .rival-key { border: 1px dashed var(--danger); }

.hud-room { top: var(--hud-gap); right: var(--hud-gap); width: min(244px, 34%); padding: .6rem .72rem; }
.hud-room-line { display: flex; justify-content: space-between; align-items: baseline; gap: .32rem; }
.room-ident { display: flex; align-items: baseline; gap: .4rem; }
.room-ident > span { color: var(--muted); font-size: .76rem; }
#game-room-code, #game-clock { font-family: var(--mono); font-variant-numeric: tabular-nums; }
#game-room-code { color: var(--accent); font-size: .94rem; font-weight: 750; letter-spacing: .08em; }
#game-clock { color: var(--muted); font-size: .77rem; white-space: nowrap; }
.hud summary { cursor: pointer; width: max-content; max-width: 100%; color: var(--text); }
.roster { margin: .29rem 0 .38rem; }
#game-players { color: var(--muted); font-size: .78rem; }
#room-roster { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem .35rem; margin-top: .28rem; }
#room-roster li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .3rem; min-width: 0; color: var(--text); font-size: .74rem; }
#room-roster li > :first-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#room-roster .presence { font-size: .71rem; }
.room-actions { display: flex; justify-content: space-between; gap: .22rem; }
.room-actions button { min-height: 31px; padding: .14rem .38rem; font-size: .76rem; }
#sound-toggle[aria-pressed='true'] { border-color: #bc98ed; color: var(--accent); background: #3c2859; }

.planet-context { position: absolute; z-index: 4; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; width: min(282px, calc(100% - 14px)); padding: 6px; border: 1px solid #a885db; border-radius: 11px; background: #211433f5; box-shadow: 0 6px 24px #10021cb0, 0 0 21px #a775ff3d; transform: translate(-50%, calc(-100% - 19px)); }
.planet-context[data-side='bottom'] { transform: translate(-50%, 19px); }
.planet-context::after { content: ''; position: absolute; z-index: -1; left: clamp(8px, var(--notch, 50%), calc(100% - 8px)); bottom: -6px; width: 10px; height: 10px; background: #26173c; border-right: 1px solid #a885db; border-bottom: 1px solid #a885db; transform: translateX(-50%) rotate(45deg); pointer-events: none; }
.planet-context[data-side='bottom']::after { top: -6px; bottom: auto; transform: translateX(-50%) rotate(225deg); }
.context-action { display: flex; align-items: center; justify-content: center; gap: .32rem; min-width: 0; min-height: 35px; padding: .18rem .24rem; font-size: .78rem; }
.context-action[data-action='fleet']:not(:disabled), .context-action[data-action='confirm']:not(:disabled) { border-color: #d0b2ff; background: #c4a2fc; color: #1d0e30; }
.context-action[data-action='fleet']:hover, .context-action[data-action='confirm']:hover { background: #e0c8ff; }
.context-action[data-action='culture']:not(:disabled) { color: var(--violet); }
.context-action[data-tutorial='true'] { outline: 2px solid #ebdcff; outline-offset: 2px; box-shadow: 0 0 16px #b48afa7d; }
.context-action:only-child { grid-column: 1 / -1; }

.tutorial-card { position: absolute; z-index: 5; top: var(--hud-gap); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: .62rem; width: min(430px, calc(44% - 2rem)); padding: .58rem .62rem; background: #2a1746f5; border: 1px solid #ae8ada; border-radius: 10px; box-shadow: 0 0 28px #a87cff3a, 0 8px 26px #08020f75; }
.tutorial-card[data-stage='done'] { border-color: #91d3b2; }
.tutorial-mark { display: grid; place-items: center; flex: 0 0 1.8rem; aspect-ratio: 1; border: 1px solid #815bad; border-radius: 7px; background: #3a245a; color: var(--accent); }
.tutorial-card[data-stage='done'] .tutorial-mark { color: var(--success); }
.tutorial-words { flex: 1; min-width: 0; }
.tutorial-words strong { color: var(--accent); font-size: .78rem; }
.tutorial-words p { color: var(--text); font-size: .88rem; line-height: 1.38; text-wrap: pretty; }
#tutorial-skip { min-height: 34px; padding: .23rem .38rem; color: var(--muted); font-size: .77rem; }

.side { right: var(--hud-gap); bottom: var(--hud-gap); display: flex; flex-direction: column; width: min(330px, 37%); max-height: min(50vh, 410px); }
.side[data-mode='summary'] { width: min(252px, 34%); }
.side-select { display: flex; align-items: center; justify-content: space-between; gap: .45rem; padding: .5rem .63rem; border-bottom: 1px solid #543e70; }
.side-select select { width: 100%; min-height: 34px; padding-block: .24rem; font-size: .84rem; text-overflow: ellipsis; }
#close-details { width: 32px; min-height: 32px; padding: 0; color: var(--muted); font-size: 1.25rem; line-height: 1; }
.side[data-mode='summary'] #close-details, .side[data-mode='summary'] #planet-stats, .side[data-mode='summary'] #planet-effects, .side:not([data-mode='inspect']) #governance, .side[data-mode='send'] .planet-info, .side:not([data-mode='send']) #comms { display: none; }
.side-scroll { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #664d86 #180f27; }
.planet-info, .side-section { padding: .65rem .7rem; }
.planet-heading { display: flex; align-items: center; gap: .55rem; }
.side[data-mode='inspect'] .planet-heading { margin-bottom: .55rem; }
.planet-heading > div { min-width: 0; }
.planet-heading h2 { font-size: 1.02rem; line-height: 1.27; overflow-wrap: anywhere; }
.planet-emblem { flex: none; width: 33px; aspect-ratio: 1; border: 1px solid var(--planet-tint, #bda4ff); border-radius: 50%; background: radial-gradient(circle at 32% 28%, var(--planet-tint, #bda4ff), #412b63 55%, #160f29 82%); box-shadow: 0 0 14px color-mix(in srgb, var(--planet-tint, #bda4ff) 35%, transparent); }
#planet-owner { margin-top: .12rem; color: var(--muted); font-size: .77rem; overflow-wrap: anywhere; }
#planet-stats { display: grid; grid-template-columns: 1fr 1fr; gap: .36rem; }
.stat { min-width: 0; padding: .25rem .42rem; border: 1px solid #46335d; border-radius: 6px; background: #1a1029; }
.stat span { display: block; color: var(--muted); font-size: .75rem; }
.stat strong { display: block; color: var(--text); font: 700 .9rem/1.3 var(--mono); }
.planet-effects { display: grid; gap: .22rem; margin-top: .48rem; color: var(--muted); font-size: .81rem; }
.planet-effects:empty { margin-top: 0; }
.planet-effects .pressure { color: var(--danger); }
.planet-effects .research { color: var(--violet); }
.side-section { border-top: 1px solid var(--line); }
.side-section h3 { margin-bottom: .32rem; font-size: .94rem; }
.side[data-mode='send'] #comms { border-top: 0; }
.transmit-actions { display: flex; gap: .35rem; }
.transmit-actions button { flex: 1; min-height: 37px; padding: .28rem .3rem; }
.policy-label { display: flex; align-items: center; justify-content: space-between; gap: .4rem; }
.policy-label select { min-height: 33px; font-size: .8rem; }
.source-actions { display: flex; align-items: center; gap: .35rem; }
.source-actions button { margin-top: .32rem; min-height: 32px; }
.fleet-slider { display: flex; justify-content: space-between; gap: .5rem; margin-top: .32rem; }
.fleet-slider output { color: var(--accent); font-family: var(--mono); text-align: right; }
.culture-preview { margin-bottom: .38rem; color: var(--violet); font-size: .82rem; }
.command-feedback:not(:empty) { margin-top: .42rem; color: var(--success); font-size: .83rem; }
.command-feedback[data-error='true'] { color: var(--danger); }

.feed { left: var(--hud-gap); bottom: var(--hud-gap); width: min(336px, 36%); }
.feed-log, .feed-transit { position: relative; padding: .35rem .63rem; }
.feed-log summary, .feed-transit summary { font-size: .85rem; font-weight: 700; }
.feed-transit { padding-top: .27rem; border-top: 1px solid #493563; }
.feed-transit summary span { margin-left: .35rem; color: var(--muted); font: .75rem var(--mono); }
.feed-heading { position: absolute; top: .22rem; right: .5rem; }
.event-filter select { max-width: 110px; min-height: 25px; padding: .12rem .28rem; font-size: .72rem; }
#active-transmissions, #event-list { max-height: 112px; margin-top: .25rem; padding-right: .2rem; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #634b81 #180e27; }
#active-transmissions li, #event-list li { display: flex; align-items: baseline; gap: .38rem; padding: .22rem 0; color: var(--muted); font-size: .78rem; line-height: 1.33; }
#active-transmissions li + li, #event-list li + li { border-top: 1px solid #412e56; }
#active-transmissions li span:nth-child(2), #event-list li span:last-child { flex: 1; }
#active-transmissions button { min-height: 28px; padding: .14rem .33rem; }
.transmission-type { flex: none; color: var(--secondary); }
.transmission-type[data-type='culture'] { color: var(--violet); }
.event-badge { flex: none; color: var(--secondary); }
.event-badge[data-type='Failed'], .event-badge[data-type='Rejected'], .event-badge[data-type='rebellion'], .event-badge[data-type='battle'] { color: var(--danger); }
.event-badge[data-type='culture'] { color: var(--violet); }
.event-badge[data-type='conquest'], .event-badge[data-type='colonization'] { color: var(--success); }
.event-time { flex: none; color: var(--dim); font: .71rem var(--mono); }
#event-list li:first-child { animation: log-in .32s ease-out both; }
@keyframes log-in { from { background: #7451a85c; } to { background: transparent; } }

dialog { width: min(450px, calc(100vw - 2rem)); padding: 0; border: 1px solid #735791; border-radius: 12px; color: var(--text); background: var(--panel); box-shadow: 0 24px 80px #000a; }
dialog::backdrop { background: #090411bd; backdrop-filter: blur(3px); }
#create-form { padding: 1.3rem; }
#create-form header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
#create-form h2 { font-size: 1.25rem; }
.close-dialog { min-width: 40px; padding: 0; font-size: 1.3rem; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: .8rem; }
.fields select { display: block; width: 100%; margin-top: .25rem; }
#create-submit { width: 100%; margin-top: .75rem; }
.invite-form { display: grid; gap: .65rem; padding: 1.3rem; }
.invite-form h2 { font-size: 1.25rem; }
.invite-form input { width: 100%; }
.toast { z-index: 9; position: fixed; bottom: max(1rem, env(safe-area-inset-bottom)); right: 1rem; width: max-content; max-width: calc(100vw - 2rem); padding: .6rem .85rem; border: 1px solid #8066a9; border-radius: 8px; background: #2e2045; color: var(--text); box-shadow: 0 12px 28px #0007; font-size: .9rem; pointer-events: none; }
.toast[data-error='true'] { border-color: #a75870; color: #ffdae0; background: #452434; }
body[data-stage='game'] .toast { right: 50%; bottom: 4.75rem; transform: translateX(50%); text-align: center; }

@media (max-width: 900px) {
  .landing-content { grid-template-columns: minmax(0, 1fr) minmax(275px, 340px); column-gap: 1.5rem; }
  .tutorial-card { top: 147px; width: min(410px, calc(100% - 2 * var(--hud-gap))); }
}
@media (max-width: 680px) {
  :root { --topbar-height: 49px; }
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-version { display: none; }
  .landing::after { background: linear-gradient(135deg, #0d0918cc, #0d091849 58%, var(--bg)), linear-gradient(0deg, var(--bg) 5%, transparent 74%); }
  .landing-content { grid-template-columns: 1fr; width: min(100% - 2rem, 490px); gap: 1rem; padding: 1.75rem 0 1.5rem; }
  .hero { padding: .45rem 0 .7rem; }
  .hero h1 { font-size: clamp(3rem, 15vw, 4.5rem); margin: .6rem 0 .85rem; }
  .hero h1 span { margin-top: .42rem; }
  .hero-meta { margin-top: .7rem; }
  .entry-card, .public-card { padding: .95rem; }
  .game { --hud-gap: .5rem; }
  .game-grid { min-height: 460px; }
  .hud-player { width: min(44%, 206px); padding: .58rem .53rem .43rem; }
  .hud-room { width: min(48.5%, 206px); padding: .42rem .47rem; }
  .player-identity { font-size: .98rem; }
  .player-facts { gap: .24rem; }
  .player-facts span { padding-inline: .25rem; }
  .player-facts small, .player-identity > span { font-size: .7rem; }
  .player-map-meta, .map-legend { font-size: .69rem; }
  .player-map-meta button { min-height: 32px; padding-inline: .23rem; }
  .map-legend { gap: .18rem .33rem; }
  .map-legend i { width: .55rem; height: .55rem; }
  #room-roster { max-height: 3rem; overflow-y: auto; }
  .room-actions button { flex: 1; min-height: 35px; padding-inline: .16rem; }
  .tutorial-card { top: max(168px, 21%); padding: .45rem .53rem; }
  .tutorial-words p { font-size: .84rem; }
  #tutorial-skip { min-height: 38px; }
  .planet-context { width: min(239px, calc(100% - 14px)); gap: 4px; padding: 5px; }
  .context-action { min-height: 41px; font-size: .76rem; }
  .map-tools { top: 50%; left: auto; right: var(--hud-gap); bottom: auto; transform: translateY(-50%); flex-direction: column; }
  .map-tools button { width: 37px; min-height: 39px; }
  .map-staging { top: 138px; bottom: auto; max-width: 80%; }
  #action-cancel { min-height: 37px; }
  .game-grid:has(.tutorial-card:not([hidden])) .map-staging { top: calc(max(168px, 21%) + 67px); }
  .side { z-index: 3; right: var(--hud-gap); width: min(354px, calc(100% - 2 * var(--hud-gap))); max-height: min(42dvh, 320px); }
  .side[data-mode='summary'] { width: min(51%, 250px); }
  .side-select { padding: .35rem .42rem; }
  .side-select select { min-height: 36px; font-size: .78rem; }
  .planet-info { padding: .42rem .5rem; }
  .planet-heading h2 { font-size: .92rem; }
  .planet-emblem { width: 28px; }
  .feed { width: min(44%, 222px); }
  .feed-log, .feed-transit { padding: .34rem .38rem; }
  .feed-log summary, .feed-transit summary { font-size: .77rem; }
  .feed-heading { right: .29rem; }
  .event-filter select { max-width: 70px; min-height: 25px; padding-inline: .1rem; }
  #event-list, #active-transmissions { max-height: 61px; }
  #event-list li, #active-transmissions li { font-size: .72rem; gap: .22rem; }
  #event-list .event-time { display: none; }
  body[data-stage='game'] .toast { bottom: 8.25rem; }
}
@media (max-height: 515px) and (orientation: landscape) {
  .game-grid { min-height: 300px; }
  .tutorial-card { top: var(--hud-gap); width: min(345px, 42%); }
  #room-roster { max-height: 2.1rem; overflow: auto; }
  #event-list, #active-transmissions { max-height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
