:root {
  --bg: #0b1118; --panel: rgba(14, 20, 28, .82); --edge: #3b3220; --gold: #e9c46a; --gold-d: #a8873e;
  --text: #ece4d2; --muted: #a59c8a; --danger: #ff5a3c;
  --display: "Cinzel", "Trajan Pro", "Palatino Linotype", Palatino, Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 13px/1.4 var(--ui); }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
a { color: var(--gold); text-decoration: none; } a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: var(--text); background: #1a2230; border: 1px solid #3a4558; border-radius: 6px; padding: 6px 10px; }
button { cursor: pointer; } button:hover { border-color: var(--gold-d); }
button.primary { background: linear-gradient(#b8892e, #7d5a18); border-color: #e9c46a; color: #fff8e4; font-weight: 600; letter-spacing: .5px; }
#top, #settings, #factions, #log, #bottom { background: var(--panel); border: 1px solid var(--edge); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

#top { position: fixed; top: 34px; left: 50%; transform: translateX(-50%); width: min(980px, calc(100% - 20px)); border-radius: 10px; padding: 8px 10px; z-index: 5; }
#pageForm { display: flex; gap: 6px; align-items: center; }
.logo { position: absolute; left: 12px; top: -26px; font: 700 18px var(--display); letter-spacing: 3px; color: var(--gold); text-shadow: 0 2px 6px #000; }
.logo span { color: #e05a3a; }
.home { position: absolute; right: 12px; top: -22px; font: 600 12px var(--display); letter-spacing: 1px; color: var(--muted); text-shadow: 0 2px 6px #000; }
.home:hover { color: var(--gold); text-decoration: none; }
#pageInput { flex: 1; min-width: 0; }
#hostInput { width: 150px; }
#suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--muted); }
#suggest:empty { display: none; }
.chip { border: 1px solid #4b5568; border-radius: 12px; padding: 1px 8px; background: #1a2230; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--gold); }

#welcome { position: fixed; top: 96px; left: 50%; transform: translateX(-50%); width: min(620px, calc(100% - 20px)); border-radius: 12px; padding: 16px 18px; z-index: 5; text-align: center; background: var(--panel); border: 1px solid var(--edge); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 10px 40px #0008; }
#welcome[hidden] { display: none; }
#welcome h2 { margin: 0 0 4px; font: 700 20px var(--display); color: var(--gold); letter-spacing: 1px; }
#welcome p { margin: 0 0 12px; color: var(--muted); }
#welcome .close { position: absolute; top: 6px; right: 6px; width: 30px; padding: 2px 0; background: none; border: none; font-size: 20px; color: var(--muted); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.example { display: flex; flex-direction: column; border: 1px solid #3a4558; border-radius: 8px; background: #1a2230; overflow: hidden; max-width: 190px; }
.example:hover { border-color: var(--gold); }
.example button { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 6px 10px 4px; border: 0; border-radius: 0; background: none; flex: 1; }
.example button:hover { background: #222b3a; }
.example b { font-family: var(--display); }
.example small { color: var(--muted); font-size: 11px; }
.example a { font-size: 10.5px; padding: 0 10px 5px; }
#welcome p.more { margin: 10px 0 0; font-size: 11.5px; }
#settings { position: fixed; top: 88px; right: max(10px, calc(50% - 490px)); width: 320px; border-radius: 10px; padding: 10px 14px; z-index: 6; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
#settings[hidden] { display: none; }
#settings h3 { grid-column: 1 / -1; margin: 0 0 4px; font: 600 14px var(--display); color: var(--gold); }
#settings label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
#settings label.check { flex-direction: row; align-items: center; gap: 6px; grid-column: 1 / -1; color: var(--text); font-size: 12px; }
#settings select { padding: 4px 6px; }
.hint { grid-column: 1 / -1; font-size: 11px; color: var(--muted); margin: 4px 0 0; }
code { background: #222b38; padding: 0 4px; border-radius: 3px; }

#factions { position: fixed; left: 10px; top: 104px; width: 290px; max-height: calc(100% - 224px); overflow-y: auto; border-radius: 10px; padding: 8px; z-index: 4; display: flex; flex-direction: column; gap: 8px; }
#factions:empty { display: none; }
.fcard { border: 1px solid #333; border-left: 4px solid var(--fc); border-radius: 8px; padding: 7px 8px; background: linear-gradient(90deg, color-mix(in srgb, var(--fc) 16%, transparent), transparent 70%); cursor: pointer; }
.fcard.fallen { opacity: .5; filter: grayscale(.7); }
.fhead { display: flex; gap: 8px; align-items: center; }
.fhead svg { flex: none; filter: drop-shadow(0 1px 2px #000); }
.fname { font: 700 14px var(--display); line-height: 1.15; }
.fgoal { font-size: 11px; color: var(--muted); font-style: italic; }
.fbar { height: 6px; border-radius: 3px; background: #222; margin: 6px 0 3px; overflow: hidden; }
.fbar i { display: block; height: 100%; background: var(--fc); width: 0; transition: width .4s; box-shadow: 0 0 8px var(--fc); }
.fstats { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.fmore { display: none; font-size: 11px; margin-top: 6px; border-top: 1px solid #333; padding-top: 5px; }
.fcard.open .fmore { display: block; }
.fmore ul { margin: 3px 0 0; padding-left: 16px; columns: 2; }
.traits { color: var(--text); }

#log { position: fixed; right: 10px; top: 104px; width: 280px; max-height: calc(100% - 224px); border-radius: 10px; padding: 8px 10px; z-index: 4; display: flex; flex-direction: column; }
#log h3 { margin: 0 0 6px; font: 600 13px var(--display); color: var(--gold); }
#logList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column-reverse; gap: 4px; }
#logList li { display: flex; gap: 6px; font-size: 11.5px; border-left: 3px solid var(--fc, #555); padding: 2px 0 2px 6px; animation: slidein .35s ease-out; }
#logList li svg { flex: none; margin-top: 1px; }
#logList li.sev3 { background: color-mix(in srgb, var(--fc) 14%, transparent); }
#logList li b { font-family: var(--display); }
#logList .when { color: var(--muted); font-size: 10.5px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

#bottom { position: fixed; bottom: 10px; left: 10px; right: 10px; border-radius: 10px; padding: 6px 10px 8px; z-index: 5; }
#ticker { display: flex; gap: 12px; white-space: nowrap; overflow: hidden; font-size: 12px; margin-bottom: 5px; min-height: 17px; }
#tDate { color: var(--gold); font-weight: 600; font-variant-numeric: tabular-nums; }
#tUser a { font-weight: 600; }
#tDelta.pos { color: #6fdc8c; } #tDelta.neg { color: #ff7a6a; }
#tComment { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; gap: 6px; align-items: center; }
.controls button { width: 36px; padding: 6px 0; }
#muteBtn.waiting { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: var(--gold); box-shadow: 0 0 10px var(--gold-d); } }
#tlWrap { position: relative; flex: 1; height: 44px; }
#timeline { width: 100%; height: 100%; display: block; border-radius: 4px; cursor: pointer; }
#tlTip { position: absolute; bottom: 48px; transform: translateX(-50%); background: #111a; border: 1px solid var(--edge); padding: 3px 6px; border-radius: 4px; white-space: nowrap; font-size: 11px; pointer-events: none; display: none; }
#revCount { color: var(--muted); font-size: 11px; min-width: 88px; text-align: right; font-variant-numeric: tabular-nums; }

.hero-label { position: absolute; left: 0; top: 0; font: 600 11px var(--ui); color: #fff; padding: 1px 6px; border-radius: 9px; background: rgba(0,0,0,.55); border: 1px solid var(--fc); white-space: nowrap; will-change: transform; }
.hero-label::before { content: "♛ "; color: var(--gold); }
.hero-label.active { background: color-mix(in srgb, var(--fc) 70%, #000); box-shadow: 0 0 12px var(--fc); }
.prov-label { position: absolute; left: 0; top: 0; font: 600 12px var(--display); color: #f6edd6; letter-spacing: 1.5px; text-transform: uppercase; text-shadow: 0 0 4px #000, 0 2px 6px #000; white-space: nowrap; will-change: transform; }
.callout { position: absolute; left: 0; top: 0; max-width: 260px; padding: 6px 10px; border-radius: 8px; background: rgba(10,12,16,.88); border: 1px solid var(--fc); box-shadow: 0 0 18px color-mix(in srgb, var(--fc) 50%, transparent); will-change: transform, opacity; transform-origin: 50% 100%; }
.callout::after { content: ""; position: absolute; left: 50%; bottom: -18px; width: 2px; height: 18px; background: linear-gradient(var(--fc), transparent); }
.co-title { font: 700 13px var(--display); color: var(--fc); text-shadow: 0 0 6px #000; filter: brightness(1.3); }
.co-text { font-size: 11.5px; }
.callout.sev1 { padding: 3px 8px; } .callout.sev1 .co-text { display: none; }

#banner { position: fixed; top: 20%; left: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; opacity: 0; z-index: 3; }
#banner.show { animation: banner 3.2s ease-out forwards; }
.b-title { font: 900 clamp(28px, 6vw, 64px) var(--display); letter-spacing: 4px; color: var(--fc, var(--gold)); text-shadow: 0 0 24px var(--fc, #000), 0 4px 0 #000, 0 0 2px #000; filter: brightness(1.25); }
.b-text { font: 600 clamp(13px, 1.8vw, 18px) var(--display); color: #fff; text-shadow: 0 2px 6px #000; margin-top: 4px; }
.b-icon svg { filter: drop-shadow(0 0 12px var(--fc)); }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); } 8% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(.98); } }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(5,8,12,.6); z-index: 10; }
#loading[hidden] { display: none; }
.ld-box { width: min(420px, 90%); padding: 18px; border-radius: 10px; background: var(--panel); border: 1px solid var(--edge); text-align: center; }
.ld-title { font: 700 18px var(--display); color: var(--gold); margin-bottom: 10px; }
.ld-bar { height: 6px; background: #222; border-radius: 3px; overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 5%; background: linear-gradient(90deg, #e05a3a, var(--gold)); transition: width .25s; }
.ld-text { margin-top: 8px; color: var(--muted); font-size: 12px; }
#toast { position: fixed; top: 100px; left: 50%; transform: translateX(-50%); padding: 8px 14px; background: #3a1410ee; border: 1px solid var(--danger); border-radius: 8px; z-index: 11; max-width: 90%; }
#toast[hidden] { display: none; }

@media (max-width: 900px) {
  #log { display: none; }
  #factions { width: 220px; }
}
@media (max-width: 600px) {
  #top { top: 30px; padding: 6px; }
  #welcome { top: 80px; padding: 10px; max-height: 52vh; overflow-y: auto; }
  #welcome h2 { font-size: 16px; }
  #welcome p { display: none; }
  .examples { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .example { max-width: none; }
  .example small { display: none; }
  .example b { font-size: 12px; }
  #toast { top: 84px; }
  #hostInput, #demoBtn { display: none; }
  #factions { top: auto; bottom: 110px; left: 8px; right: 8px; width: auto; max-height: 30%; flex-direction: row; overflow-x: auto; }
  .fcard { min-width: 200px; }
  #settings { right: 8px; left: 8px; width: auto; top: 76px; }
  #bottom { left: 6px; right: 6px; }
  #revCount { display: none; }
}
