:root {
  --ink: #221d17; --ink2: #5b5145; --paper: #efe6d0; --paper2: #e4d9bd; --line: #c9bb98;
  --ox: #7c2b22; --gold: #a9812c; --good: #3e6b3a; --bad: #9a3324; --frame: #2b251e; --sea: #a9bcbb;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #231e18; color: var(--ink); font-family: 'Spectral', Georgia, serif; font-size: 15px; line-height: 1.35; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.drag { cursor: grabbing; }
h1, h2, h3, h4 { font-family: 'Spectral SC', 'Spectral', serif; font-weight: 700; letter-spacing: .04em; margin: 0; }

#top { position: fixed; top: 0; left: 0; right: 0; height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 10px; background: var(--frame); color: #eadfc6; border-bottom: 2px solid var(--gold); z-index: 5; }
#top[hidden], #side[hidden], #right[hidden], #modes[hidden], #armyBar[hidden], #toast[hidden], #modal[hidden], [hidden] { display: none !important; }
#top button { background: none; border: 1px solid transparent; border-radius: 3px; padding: 4px 9px; color: #eadfc6; }
#top button:hover { border-color: #6d6048; background: #3a3228; }
#top .who { display: flex; align-items: center; gap: 8px; font-family: 'Spectral SC', serif; font-size: 15px; max-width: 260px; white-space: nowrap; overflow: hidden; flex: none; }
#top .who svg { flex: none; }
#res { display: flex; gap: 14px; flex: none; font-variant-numeric: tabular-nums; white-space: nowrap; }
#res b { font-weight: 600; color: #fff3d3; }
#res span { cursor: default; }
#res small { color: #a99a7c; }
#tabs { display: flex; gap: 2px; margin-left: 6px; }
#tabs button.on { border-color: var(--gold); background: #3a3228; }
#clock { margin-left: auto; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#date { font-family: 'Spectral SC', serif; min-width: 148px; text-align: right; }
#speeds button { padding: 4px 6px; min-width: 22px; color: #8d7f65; }
#speeds button.on { color: #ffd98a; }
#pauseBtn.on { background: var(--ox); border-color: #b4574b; }

#side { position: fixed; top: 54px; left: 8px; width: 372px; max-height: calc(100% - 64px); overflow-y: auto; background: var(--paper); border: 1px solid #8a7a58; box-shadow: 0 3px 14px rgba(30, 20, 5, .35), inset 0 0 0 3px var(--paper), inset 0 0 0 4px var(--line); padding: 14px 16px 16px; z-index: 4; -webkit-user-select: text; user-select: text; }
#side h2 { font-size: 20px; line-height: 1.15; }
#side h3 { font-size: 14px; color: var(--ox); margin: 14px 0 5px; border-bottom: 1px solid var(--line); padding-bottom: 2px; }
#side p { margin: 5px 0; }
.x { position: absolute; top: 6px; right: 8px; border: none; background: none; font-size: 20px; color: var(--ink2); padding: 2px 6px; }
.back { border: none; background: none; color: var(--ox); padding: 0; margin-bottom: 4px; font-size: 13px; }
.head { display: flex; gap: 12px; align-items: flex-start; }
.head .meta { min-width: 0; }
.muted { color: var(--ink2); }
.small { font-size: 13px; }
a.l, .l { color: var(--ox); text-decoration: none; cursor: pointer; border-bottom: 1px dotted #b79a8f; }
a.l:hover { border-bottom-style: solid; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 2px; }
.chip { font-size: 12.5px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper2); cursor: help; }
.chip.g { border-color: #9db08f; background: #dfe6cc; } .chip.b { border-color: #cfa093; background: #ecd6c8; } .chip.e { border-color: #b9a56a; background: #ecdfae; }
.skills { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 8px 0; text-align: center; }
.skills div { background: var(--paper2); border: 1px solid var(--line); padding: 3px 0 2px; }
.skills b { display: block; font-size: 18px; font-weight: 600; line-height: 1.1; }
.skills small { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 6px 0; }
.kv dt { color: var(--ink2); } .kv dd { margin: 0; text-align: right; }
.pos { color: var(--good); font-weight: 600; } .neg { color: var(--bad); font-weight: 600; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btn { background: var(--paper2); border: 1px solid #8a7a58; border-radius: 3px; padding: 4px 10px; font-size: 14px; }
.btn:hover { background: #d9cba6; }
.btn.pri { background: var(--ox); color: #f6ead2; border-color: #5a1d17; }
.btn.pri:hover { background: #8e342a; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { padding: 1px 7px; font-size: 13px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t td, table.t th { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.t th { font-weight: 400; color: var(--ink2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.row .g { flex: 1; min-width: 0; }
.bar { height: 10px; background: #cfc3a3; border: 1px solid #8a7a58; position: relative; margin: 4px 0; }
.bar i { position: absolute; top: 0; bottom: 0; background: var(--ox); }
.bar.mid::after { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--ink); }
.note { background: var(--paper2); border-left: 3px solid var(--gold); padding: 6px 9px; margin: 8px 0; font-size: 13.5px; }

#right { position: fixed; top: 54px; right: 8px; width: 270px; z-index: 3; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-height: calc(100% - 110px); }
#alerts { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
#alerts button { pointer-events: auto; background: #f3e3b4; border: 1px solid var(--gold); border-left: 4px solid var(--ox); padding: 3px 9px; font-size: 13.5px; text-align: right; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
#logWrap { pointer-events: auto; background: rgba(239, 230, 208, .93); border: 1px solid #8a7a58; padding: 8px 10px; min-height: 0; display: flex; flex-direction: column; }
#logWrap h4 { font-size: 12.5px; color: var(--ox); margin-bottom: 4px; }
#log { overflow-y: auto; max-height: 34vh; font-size: 13px; }
#log div { padding: 3px 0; border-bottom: 1px solid var(--line); cursor: default; }
#log div[data-a] { cursor: pointer; }
#log .d { color: var(--ink2); font-size: 11.5px; display: block; }
#log .good { color: var(--good); } #log .bad { color: var(--bad); } #log .war { color: var(--ox); font-weight: 600; } #log .world { color: var(--ink2); }

#modes { position: fixed; bottom: 10px; right: 8px; display: flex; z-index: 3; border: 1px solid #8a7a58; background: var(--paper); }
#modes button { border: none; background: none; padding: 5px 11px; font-size: 13.5px; }
#modes button.on { background: var(--frame); color: #eadfc6; }
#armyBar { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); background: var(--paper); border: 1px solid #8a7a58; padding: 7px 12px; z-index: 4; display: flex; gap: 10px; align-items: center; box-shadow: 0 2px 10px rgba(0, 0, 0, .3); font-size: 14px; }
#toast { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); background: var(--frame); color: #f3e7cc; padding: 7px 16px; border: 1px solid var(--gold); z-index: 9; max-width: 80vw; text-align: center; }

#modal { position: fixed; inset: 0; background: rgba(25, 18, 8, .45); z-index: 8; display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal .card { width: 460px; max-width: 100%; background: var(--paper); border: 1px solid #6d5d3d; box-shadow: 0 8px 40px rgba(0, 0, 0, .5), inset 0 0 0 4px var(--paper), inset 0 0 0 5px var(--line); padding: 22px 24px 18px; text-align: center; }
#modal h2 { font-size: 23px; color: var(--ox); margin-bottom: 8px; }
#modal p { margin: 0 0 14px; font-size: 16px; }
#modalPic { display: flex; justify-content: center; margin-bottom: 8px; }
#modalOpts { display: flex; flex-direction: column; gap: 6px; }
#modalOpts button { background: var(--paper2); border: 1px solid #8a7a58; padding: 8px 12px; font-size: 15px; }
#modalOpts button:hover { background: var(--ox); color: #f6ead2; }

#start { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 46%, rgba(24, 17, 9, .5) 0%, rgba(24, 17, 9, .62) 38%, rgba(12, 8, 4, .9) 100%); padding: 16px; }
.startCard { text-align: center; color: #efe3c6; max-width: 640px; }
.startCard .year { font-family: 'Spectral SC', serif; letter-spacing: .5em; font-size: 14px; color: #c9a54a; opacity: 0; transition: opacity 1.6s ease .2s; padding-left: .5em; }
.startCard h1 { font-size: clamp(52px, 10.5vw, 104px); letter-spacing: .08em; line-height: 1.02; color: #f6ead0; text-shadow: 0 3px 0 #000, 0 0 40px rgba(0, 0, 0, .8); margin-top: 10px; }
.startCard h1 span { display: inline-block; opacity: 0; transform: translateY(14px); transition: opacity 1.4s ease, transform 1.4s ease; }
.startCard h1 .amp { color: var(--gold); font-style: italic; font-family: 'Spectral', serif; font-weight: 400; transition-delay: .55s; }
.startCard h1 .k { transition-delay: .25s; } .startCard h1 .c { transition-delay: .85s; }
.startCard .rule { height: 1px; width: 0; margin: 18px auto 0; background: linear-gradient(90deg, transparent, #c9a54a, transparent); transition: width 1.6s ease 1.2s; }
.startCard .sub { font-size: 18px; margin: 18px auto 10px; color: #dccfae; max-width: 500px; opacity: 0; transition: opacity 1.4s ease 1.6s; }
.ticker { min-height: 24px; font-style: italic; color: #b9a877; margin: 0 0 26px; opacity: 0; transition: opacity .5s; }
.ticker.in { opacity: 1; }
#startBtns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; opacity: 0; transition: opacity 1.2s ease 2.2s; }
#start.ready .year, #start.ready .sub, #start.ready #startBtns { opacity: 1; }
#start.ready h1 span { opacity: 1; transform: none; }
#start.ready .rule { width: 340px; max-width: 80%; }
.big { font-family: 'Spectral SC', serif; font-size: 19px; letter-spacing: .1em; padding: 11px 34px; background: var(--ox); color: #f6ead2; border: 1px solid var(--gold); box-shadow: 0 4px 18px rgba(0, 0, 0, .5); }
.big:hover { background: #93382d; }
.big.ghost { background: rgba(20, 14, 8, .5); }
.big:disabled { opacity: .4; }
.fine { font-size: 13px; color: #a2946f; margin-top: 22px; min-height: 18px; }
#cine { position: fixed; inset: 0; z-index: 9; cursor: pointer; }
#cine .barT, #cine .barB { position: absolute; left: 0; right: 0; background: #0d0905; }
#cine .barT { top: 0; height: 9vh; box-shadow: 0 10px 40px 20px rgba(13, 9, 5, .55); }
#cine .barB { bottom: 0; min-height: 24vh; padding: 3.2vh 24px 2vh; box-shadow: 0 -10px 40px 20px rgba(13, 9, 5, .55); display: flex; flex-direction: column; align-items: center; justify-content: space-between; }
#cineText { max-width: 760px; text-align: center; color: #efe3c6; font-size: clamp(18px, 2.3vw, 26px); line-height: 1.4; margin: 0; opacity: 0; }
#cineText.in { animation: cineIn 1.3s ease forwards; }
@keyframes cineIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.cineRow { display: flex; gap: 18px; align-items: center; margin-top: 12px; }
#cineDots i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 3px; background: #4a3f2c; }
#cineDots i.on { background: #c9a54a; }
#cine button { background: none; border: 1px solid #5d5038; color: #b9a877; padding: 3px 14px; font-family: 'Spectral SC', serif; letter-spacing: .1em; }
#tip { position: fixed; z-index: 6; pointer-events: none; background: rgba(34, 27, 19, .94); color: #f1e6cb; border: 1px solid #8a7446; padding: 5px 10px; font-size: 13.5px; line-height: 1.3; max-width: 260px; box-shadow: 0 2px 10px rgba(0, 0, 0, .4); }
#tip span { color: #b9a877; } #tip i { color: #e2a08f; }
#side.wide { width: 470px; }
#bf { width: 100%; display: block; margin: 9px 0; border: 1px solid #6d5d3d; box-shadow: inset 0 0 30px rgba(40, 25, 5, .35); }
.bgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bside { background: var(--paper2); border: 1px solid var(--line); padding: 7px 9px; }
.bside:last-child { text-align: right; }
.bside .bn { font-family: 'Spectral SC', serif; font-size: 14px; line-height: 1.2; margin-bottom: 3px; }
.tacs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tacs .btn { padding: 7px 4px; font-family: 'Spectral SC', serif; letter-spacing: .04em; }
.row.pick { align-items: flex-start; padding: 7px 4px; }
.diff { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; padding: 0 6px; border-radius: 8px; border: 1px solid; vertical-align: 2px; }
.diff.d1 { color: var(--good); } .diff.d2 { color: var(--gold); } .diff.d3 { color: var(--bad); }
.pickList .row { cursor: pointer; }
.pickList .row:hover { background: var(--paper2); }
.tag { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink2); }

@media (max-width: 1500px) { #res small { display: none; } #res span::before { content: attr(data-s); color: #a99a7c; font-size: 12px; margin-right: 3px; } }
@media (max-width: 900px) {
  #tabs button { padding: 4px 5px; font-size: 13px; }
  #res small { display: none; }
  #right { width: 210px; }
  #logWrap { display: none; }
}
@media (max-width: 760px) {
  /* three rows: who and clock, the four numbers, the tabs */
  #top { height: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "who clock" "res res" "tabs tabs"; gap: 2px 6px; padding: 4px 6px 3px; align-items: center; }
  #top button { padding: 4px 6px; }
  #top .who { grid-area: who; max-width: none; min-width: 0; font-size: 14px; gap: 6px; }
  #meName { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  #clock { grid-area: clock; margin-left: 0; gap: 2px; }
  #date { min-width: 0; font-size: 13px; }
  #speeds { display: flex; }
  #speeds button { padding: 4px 2px; min-width: 13px; }
  #res { grid-area: res; justify-content: space-between; gap: 6px; font-size: 14px; min-width: 0; overflow: hidden; padding: 0 2px; }
  #tabs { grid-area: tabs; margin-left: 0; gap: 0; min-width: 0; overflow-x: auto; scrollbar-width: none; justify-content: space-between; }
  #tabs::-webkit-scrollbar { display: none; }
  #tabs button { flex: 0 0 auto; padding: 5px 5px; font-size: 13px; }
  #side, #side.wide { top: auto; bottom: 0; left: 0; width: 100%; max-height: 58%; }
  #right { top: calc(var(--topH, 100px) + 6px); width: 200px; }
  #modes { bottom: auto; top: calc(var(--topH, 100px) + 6px); left: 6px; right: auto; flex-direction: column; }
  #toast { top: auto; bottom: 12px; z-index: 7; }
}
@media (max-width: 470px) {
  /* phones: the name gets its own row */
  #top { grid-template-columns: minmax(0, 1fr); grid-template-areas: "who" "clock" "res" "tabs"; }
  #clock { justify-content: space-between; }
  #date { text-align: left; }
  #tabs button { padding: 5px 3px; font-size: 12.5px; }
  #res { font-size: 13.5px; }
}
@media (max-width: 350px) {
  #tabs button { padding: 5px 1px; font-size: 11.5px; }
  #top .who { font-size: 13px; }
  #date { font-size: 12px; }
}
/* the field: the player's own battle */
#side.field { --fw: max(300px, min(100%, calc((100vh - 215px) * 1.652))); top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; max-height: none; z-index: 6; border: none; box-shadow: none; padding: 10px 14px 16px; display: flex; flex-direction: column; align-items: center; }
#side.field > :not(.x):not(.back) { width: var(--fw); flex: 0 0 auto; }
#side.field .fhead { font-family: 'Spectral SC', serif; font-size: 17px; padding-right: 26px; }
#side.field #bf { margin: 6px 0 8px; }
#bf.fld { touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.flegend { margin-top: -4px; }
@media (max-width: 760px) { #side.field { top: 0; bottom: 0; width: 100%; max-height: none; padding: 8px 8px 14px; } }
.fchips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 0 8px; }
.fchips .chip { padding: 7px 14px; font-family: 'Spectral SC', serif; font-size: 15px; letter-spacing: .04em; min-height: 36px; }
.fchips .chip .n { opacity: .7; font-size: 12px; }
.fchips .fwho { flex: 1 1 180px; color: #5a4a2e; }
