:root { --paper: #fff6df; --paper2: #f4e6c4; --ink: #3a2a20; --mute: #806a55; --line: #4a3426; --accent: #c8553d; --ok: #5aa469; }
* { box-sizing: border-box; border-radius: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3a6ea0; color: var(--ink); font: 14px/1.45 "DotGothic16", "MS Gothic", monospace; }
canvas#map { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: grab; image-rendering: pixelated; touch-action: none; }
button, select, input { font: inherit; color: inherit; border-radius: 0; }
h1, h2, h3, p { margin: 0; }
small { font-size: 12px; }
.muted { color: var(--mute); }
.gap { flex: 1; min-width: 0; }
img.ico { width: 14px; height: 14px; image-rendering: pixelated; vertical-align: -2px; margin-right: 4px; flex: none; }
img.ico:not([src]), img.ico[src=""] { display: none; }

/* ドット絵RPGのウィンドウ */
#top, #log, #tools, #side, .win, #status, #modes, .toast, #rank, #favs, #challenge-hud {
  background: var(--paper); border: 3px solid var(--line); box-shadow: 0 0 0 2px var(--paper) inset, 3px 3px 0 rgba(30, 20, 10, .45);
}
#top {
  position: fixed; top: 0; left: 0; right: 0; height: 44px;
  display: flex; align-items: center; justify-content: flex-start; gap: 7px; padding: 0 10px;
  border-width: 0 0 3px; z-index: 5;
  box-shadow: 0 3px 0 rgba(30, 20, 10, .3);
  overflow-x: auto; scrollbar-width: none;
}
#top::-webkit-scrollbar { display: none; }
#top .logo, #top #year, #top .btn, #top .seg { flex: none; }
.logo { color: var(--accent); font-size: 18px; letter-spacing: 1px; }
#year { font-size: 18px; min-width: 60px; text-align: right; }
#world { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
#watch { white-space: nowrap; color: var(--accent); }

.btn { padding: 4px 9px; background: var(--paper2); border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #ffe9b0; }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.on { background: #ffd66e; }
.btn.wide { display: block; width: 100%; margin: 6px 0; text-align: center; }
.btn.danger, .mini.danger { color: #fff; background: var(--accent); }
.btn.danger:hover, .mini.danger:hover { background: #dc6a50; }
.mini { padding: 0 6px; background: var(--paper2); border: 2px solid var(--line); cursor: pointer; font-size: 12px; margin-left: 3px; white-space: nowrap; }
.mini.on { background: #ffd66e; }
.mini:disabled { opacity: .45; cursor: default; }
.seg { display: inline-flex; border: 2px solid var(--line); }
.seg button { padding: 3px 8px; border: 0; background: var(--paper2); border-right: 2px solid var(--line); cursor: pointer; white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: #ffd66e; }
.audio-seg button { padding: 3px 7px; }
#b-sound img.ico { margin-right: 0; }
#b-sound.muted-btn { background: #e8d7ae; opacity: .82; }
.link { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; color: #2f5f8a; }

#tools { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); padding: 5px; z-index: 4; max-width: calc(100vw - 20px); }
.groups { display: flex; gap: 3px; }
#subtools { display: none; gap: 3px; padding-bottom: 5px; margin-bottom: 5px; border-bottom: 2px dotted var(--line); justify-content: center; }
#subtools.open { display: flex; }

/* 左HUD縦スタック（順位・ひいき・神の試練） */
#hud-left {
  position: fixed; top: 90px; left: 10px; width: 215px;
  max-height: calc(100vh - 320px);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 3; pointer-events: none;
}
#rank, #favs, #challenge-hud {
  position: static; width: 100%; padding: 5px 7px;
  font-size: 12px; display: none; pointer-events: auto;
  box-shadow: 3px 3px 0 rgba(30, 20, 10, .45);
}
#rank.open, #favs.open, #challenge-hud.open { display: block; }
#rank { max-height: 36vh; overflow-y: auto; }
#favs { max-height: 26vh; overflow-y: auto; }
#favs b { color: #b8860b; font-weight: normal; }
.fav { display: flex; align-items: center; gap: 4px; width: 100%; padding: 2px 3px; border: 0; background: none; cursor: pointer; text-align: left; font-size: 12px; }
.fav:hover { background: #ffe9b0; }
.fav-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav small { margin-left: auto; flex: none; color: var(--mute); white-space: nowrap; }
.fav small.warn { color: var(--accent); }

.rank-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 0 2px 2px; border: 0; background: none;
  cursor: pointer; text-align: left; font: inherit; color: var(--ink);
}
.rank-head:hover { background: #ffe9b0; }
.rank-head b { font-weight: bold; }
.rank-head small { color: var(--mute); font-size: 11px; }
#rank.collapsed #rank-rows, #rank.collapsed #rank-ally-rows { display: none; }

#challenge-hud.cleared { background: #e8f5df; border-color: var(--ok); }
#challenge-hud.failed { background: #fbe2dc; border-color: var(--accent); }
.ch-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.ch-head b { color: var(--accent); font-weight: normal; }
.ch-st { padding: 0 4px; font-size: 11px; background: var(--paper2); border: 1px solid var(--line); white-space: nowrap; }
#challenge-hud.cleared .ch-st { background: var(--ok); color: #fff; }
#challenge-hud.failed .ch-st { background: var(--accent); color: #fff; }
.ch-msg { margin: 3px 0 0; font-size: 11px; line-height: 1.35; }

.tribe-link { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; font-size: 13px; }
.bloc { padding: 3px 6px; margin: 4px 0; font-size: 13px; border-left: 4px solid var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.omen { padding: 2px 6px; margin: 3px 0; font-size: 13px; background: #fbe6c0; border-left: 4px solid #e8a33d; }
.omen.s2 { background: #fbd9b8; border-color: #e8703d; }
.omen.s3 { background: #f8c4b8; border-color: #c8353d; font-weight: bold; }
.hint { font-size: 12px; margin-top: 8px; }
.t-omen { color: #c0601a; } .t-fav { color: #b8860b; }
.btn:disabled { opacity: .55; cursor: default; }
#followbar { display: none; border: 2px solid var(--line); background: #ffd66e; padding: 2px 8px; cursor: pointer; white-space: nowrap; }
#followbar.open { display: inline-block; }
.bio { max-height: 210px; overflow-y: auto; }
.bio li { display: block; font-size: 12px; }
.roster-bar select, .roster-bar input[type=text] { background: var(--paper2); border: 2px solid var(--line); margin-right: 4px; min-width: 0; }
.roster { max-height: 56vh; overflow-y: auto; border: 2px solid var(--line); margin: 6px 0; }
.rrow { display: grid; grid-template-columns: 30px 1.6fr 76px 70px 1fr; align-items: center; gap: 6px; width: 100%; padding: 2px 6px; border: 0; background: none; cursor: pointer; text-align: left; }
.rrow:nth-child(odd) { background: var(--paper2); }
.rrow:hover { background: #ffe9b0; }
.rrow b { font-weight: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rrow small { color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree { height: 56vh; overflow: auto; border: 2px solid var(--line); background: #fbf1d8; margin: 6px 0; }
.tree-in { position: relative; transform-origin: 0 0; }
.tree-size { overflow: hidden; }
.tree-bar { justify-content: space-between; flex-wrap: wrap; }
.tnode.tiny { font-size: 10px; padding: 0 2px; line-height: 1.1; overflow: hidden; white-space: nowrap; }
.tnode.tiny b { font-weight: normal; }
.wide2 { grid-column: 1 / -1; }
.name-form label { display: block; margin: 8px 0; }
.name-form input { width: 100%; background: var(--paper2); border: 2px solid var(--line); padding: 4px 6px; font: inherit; }

/* 画面が狭いときは上の帯を詰めて、全部のボタンが押せるようにする */
@media (max-width: 1000px) {
  #top { gap: 4px; overflow-x: auto; }
  #top .logo, #top #world { display: none; }
  #top .btn { padding-left: 6px; padding-right: 6px; white-space: nowrap; flex: none; }
  #top .seg { flex: none; }
}

/* 人口統計 */
.stats.st6 { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.stats.st3 { grid-template-columns: repeat(3, 1fr); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 10px; margin: 8px 0; }
.chart { position: relative; background: #fbf1d8; border: 2px solid var(--line); padding: 6px 8px; min-width: 0; }
.chart h4 { margin: 0 0 4px; font-size: 13px; font-weight: normal; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chart svg { display: block; width: 100%; height: auto; touch-action: none; }
.chart svg path { fill: none; stroke-width: 2; }
.chart svg .g { stroke: #4a342622; stroke-width: 1; }
.chart svg text { font-size: 10px; fill: #6b5442; }
.chart svg .cross { stroke: #4a3426; stroke-width: 1; stroke-dasharray: 2 2; }
.chart .tip { position: absolute; top: 26px; background: #2b1e15; color: #fff8e7; padding: 2px 6px; font-size: 12px; white-space: nowrap; pointer-events: none; }
.legend { display: inline-flex; gap: 10px; font-size: 12px; color: #6b5442; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 3px; }
.prow { display: grid; grid-template-columns: 26px 1fr 58px 1fr 26px; align-items: center; gap: 3px; height: 15px; }
.prow .pa { text-align: center; color: #6b5442; font-size: 10px; }
.prow .pv { font-size: 10px; text-align: right; }
.prow .pv.r { text-align: left; }
.prow .pl { display: flex; justify-content: flex-end; }
.prow .pl i, .prow .pr i { display: block; height: 11px; }
.crow2 { display: grid; grid-template-columns: 62px 1fr 70px; align-items: center; gap: 4px; height: 18px; font-size: 11px; }
.crow2 div i { display: block; height: 11px; background: #2f6fb0; }
.crow2 small:last-child { text-align: right; }
.st-table { overflow-x: auto; max-height: 300px; overflow-y: auto; border: 2px solid var(--line); }
.st-table table { width: 100%; border-collapse: collapse; font-size: 12px; background: #fbf1d8; }
.st-table th { position: sticky; top: 0; background: #e8d7ae; text-align: right; padding: 2px 6px; font-weight: normal; white-space: nowrap; }
.st-table td { text-align: right; padding: 2px 6px; border-top: 1px solid #4a342622; white-space: nowrap; }
.st-table th:first-child, .st-table td:first-child { text-align: left; }
.st-table tbody tr { cursor: pointer; }
.st-table tbody tr:hover { background: #f2e2b8; }
.tree svg { position: absolute; inset: 0; }
.tree polyline, .tree line { fill: none; stroke: #4a3426; stroke-width: 2; }
.tree line.c { stroke: #c8553d; stroke-width: 3; }
.tnode { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1px; background: var(--paper); border: 3px solid var(--line); cursor: pointer; line-height: 1.15; overflow: hidden; }
.tnode b { font-weight: normal; font-size: 12px; white-space: nowrap; }
.tnode small { font-size: 10px; color: var(--mute); white-space: nowrap; }
.tnode:hover { background: #ffe9b0; }
.tnode.me { background: #ffd66e; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); z-index: 2; }
.tnode.gone .face { filter: grayscale(1); }
.tabs { margin: 4px 0 6px; }
.lineage { max-height: 62vh; overflow-y: auto; }
.ltribe h3 { display: flex; align-items: center; gap: 5px; }
.lrow { display: grid; grid-template-columns: 140px 1fr 72px; align-items: center; gap: 6px; font-size: 12px; }
.lname { text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ltrack { position: relative; height: 12px; background: #eadfc0; }
.lbar { position: absolute; top: 1px; height: 10px; border: 1px solid var(--line); padding: 0; cursor: pointer; }
.lbar.gone { opacity: .6; }
.lrow small { color: var(--mute); white-space: nowrap; }
.tool { width: 56px; padding: 4px 0 2px; background: var(--paper2); border: 2px solid transparent; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; flex: none; }
.tool img { width: 24px; height: 24px; image-rendering: pixelated; }
.tool span { font-size: 12px; }
.tool:hover { background: #ffe9b0; }
.tool.on { background: #ffd66e; border-color: var(--line); }

#log { position: fixed; left: 10px; bottom: 10px; width: 330px; margin: 0; padding: 6px 9px; list-style: none; z-index: 3; font-size: 12px; max-height: 215px; overflow: hidden; }
#log li { padding: 1px 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#log li[data-x], .logs li[data-x] { cursor: pointer; }
#log li[data-x]:hover, .logs li[data-x]:hover { background: #ffe9b0; }
#log small, .logs small { color: var(--mute); }
.mine { font-weight: bold; }
.t-war { color: #a33a26; } .t-fall { color: #7a3a8a; } .t-rise { color: #2d7a4a; } .t-doom { color: #8a5a10; } .t-god { color: #2f5f8a; } .t-tech { color: #2a7a80; }

#modes { position: fixed; top: 54px; left: 10px; z-index: 3; padding: 0; box-shadow: 3px 3px 0 rgba(30, 20, 10, .45); }
#status { position: fixed; right: 10px; bottom: 10px; padding: 3px 9px; font-size: 12px; z-index: 3; max-width: 340px; }
#status:empty { display: none; }

#side { position: fixed; top: 54px; right: 10px; max-height: calc(100vh - 104px); width: 326px; padding: 12px; overflow-y: auto; overflow-x: hidden; z-index: 4; display: none; }
#side.open { display: block; }
#side h2 { font-size: 19px; padding-left: 10px; border-left: 8px solid var(--c, var(--line)); margin-right: 22px; }
h2.plain { border: 0 !important; padding: 0 !important; font-size: 19px; }
#side h3, .win h3 { font-size: 14px; margin: 12px 0 5px; padding-bottom: 2px; border-bottom: 2px dotted var(--line); }
.x { position: absolute; top: 8px; right: 8px; border: 0; background: none; cursor: pointer; font-size: 15px; }
.epithets { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.epithet { display: inline-block; padding: 1px 6px; font-size: 11px; background: #ffd66e; border: 2px solid var(--line); color: var(--ink); cursor: help; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; margin: 8px 0; }
.stats div { display: flex; justify-content: space-between; background: var(--paper2); padding: 1px 7px; }
.row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.row > small:first-child { width: 40px; flex: none; }
.row > small:last-child { width: 24px; text-align: right; flex: none; }
.row select { flex: 1; background: var(--paper2); border: 2px solid var(--line); }
.bar { flex: 1; height: 10px; background: #dccfae; border: 2px solid var(--line); display: block; }
.bar i { display: block; height: 100%; }
.warn { color: var(--accent); }
.face { image-rendering: pixelated; border: 2px solid var(--line); background: #ccc; flex: none; }
.face.dead { filter: grayscale(1); opacity: .8; }
.pchip { display: flex; align-items: center; gap: 6px; width: 100%; padding: 2px 5px 2px 2px; background: var(--paper2); border: 0; cursor: pointer; text-align: left; margin-bottom: 3px; }
.pchip:hover { background: #ffe9b0; }
.pchip span { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.pchip b { font-weight: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip small { color: var(--mute); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 5px; padding: 2px 0; font-size: 13px; }
.list li small { color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sw { width: 11px; height: 11px; border: 2px solid var(--line); flex: none; }
.ptop { display: flex; gap: 10px; margin: 8px 0; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 10px 0; }
.lbl { display: block; color: var(--mute); margin-top: 6px; }

#toasts { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 5px; z-index: 12; pointer-events: none; align-items: center; }
.toast { padding: 4px 12px; max-width: 560px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.toast .toast-btn { pointer-events: auto; padding: 1px 6px; background: #ffd66e; }

#modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(30, 22, 14, .55); z-index: 10; }
#modal.open { display: flex; }
.win { position: relative; width: 430px; max-width: 100%; max-height: 100%; overflow-y: auto; padding: 14px 16px; }
.win.wide { width: 880px; }
.win p { margin: 6px 0; }
.opts { margin-top: 10px; }
.title { text-align: center; margin-bottom: 6px; }
.title h1 { font-size: 28px; line-height: 1.15; color: var(--accent); letter-spacing: 3px; }
.title p { margin: 2px 0 0; font-size: 13px; }
.setup-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; padding-right: 26px; }
.setup-utils { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.demo-tag { padding: 2px 6px; background: #ffd66e; border: 2px solid var(--line); font-size: 12px; }
.setup { display: grid; grid-template-columns: 300px 1fr; gap: 14px; }
.setup h3 { margin: 6px 0 4px; }
#prev { width: 100%; max-height: 152px; object-fit: contain; background: #3f77ac; image-rendering: pixelated; border: 3px solid var(--line); display: block; }
#prev-info { margin: 3px 0; font-size: 12px; }
.setup-cta { position: sticky; bottom: -14px; background: var(--paper); padding: 6px 0 2px; z-index: 2; border-top: 2px dotted var(--line); margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: stretch; }
.setup-cta #start { flex: 1 1 200px; }
.setup-cta #cont { flex: 0 0 auto; margin: 4px 0; padding: 7px 14px; }
.seed { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin: 6px 0; }
.seed input { width: 100px; background: var(--paper2); border: 2px solid var(--line); padding: 1px 4px; }
.setup-tabs { display: flex; flex-wrap: wrap; gap: 3px; margin: 6px 0; padding-bottom: 5px; border-bottom: 2px solid var(--line); }
.setup-tab { padding: 3px 7px; background: var(--paper2); border: 2px solid var(--line); cursor: pointer; font-size: 12px; }
.setup-tab:hover { background: #ffe9b0; }
.setup-tab.on { background: #ffd66e; font-weight: bold; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.preset { background: var(--paper2); border: 2px solid transparent; padding: 3px 6px; cursor: pointer; text-align: left; display: flex; flex-direction: column; line-height: 1.25; }
.preset-head { display: flex; align-items: center; gap: 4px; width: 100%; }
.preset b { font-weight: normal; }
.preset small { color: var(--mute); font-size: 11px; }
.preset:hover { background: #ffe9b0; }
.preset.on { background: #ffd66e; border-color: var(--line); }
.preset.locked { opacity: .9; }
.lock-badge { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; padding: 0 4px; background: #ffd66e; border: 1px solid var(--line); font-size: 10px; color: var(--ink); white-space: nowrap; }
.lock-badge img.ico { width: 11px; height: 11px; margin-right: 1px; vertical-align: -1px; }

.challenge-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-height: 36vh; overflow-y: auto; }
.challenge-card { background: var(--paper2); border: 2px solid var(--line); padding: 6px 8px; }
.challenge-card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.challenge-card-head b { font-weight: normal; color: var(--accent); }
.challenge-card.cleared { background: #e8f5df; border-color: var(--ok); }
.ch-done { display: inline-block; padding: 0 4px; margin-left: 4px; background: var(--ok); color: #fff; font-size: 11px; border: 1px solid var(--line); }
.challenge-stars { color: #b8860b; font-size: 12px; white-space: nowrap; }
.challenge-card p { margin: 0 0 6px; font-size: 12px; }

.search-bar { display: flex; gap: 6px; margin: 6px 0; }
.search-bar input { flex: 1; background: var(--paper2); border: 2px solid var(--line); padding: 5px 8px; min-width: 0; }
.search-list { max-height: 55vh; overflow-y: auto; border: 2px solid var(--line); background: #fbf1d8; }
.search-sec { padding: 3px 8px; background: #e8d7ae; border-bottom: 2px solid var(--line); font-size: 12px; color: var(--ink); position: sticky; top: 0; z-index: 1; }
.search-row { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px dotted var(--line); font-size: 13px; flex-wrap: wrap; }
.search-row:nth-child(even) { background: var(--paper2); }
.search-main { display: flex; align-items: center; gap: 5px; flex: 1; min-width: 170px; flex-wrap: wrap; }
.search-main b { font-weight: normal; }
.search-owner { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--mute); }
.search-acts { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.tag-cap { color: #b8860b; font-size: 11px; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin: 8px 0; max-height: 58vh; overflow-y: auto; }
.ach-card { border: 2px solid var(--line); padding: 8px; background: var(--paper2); display: flex; flex-direction: column; gap: 3px; }
.ach-card.unlocked { background: #ffe9b0; box-shadow: 0 0 0 2px #ffd66e inset; }
.ach-card.locked { opacity: .68; }
.ach-top { display: flex; align-items: center; gap: 4px; }
.ach-top b { font-weight: normal; }
.ach-card small { font-size: 11px; color: var(--mute); }

.upgrade-box { background: #ffe9b0; border: 2px solid var(--line); padding: 10px 12px; margin: 8px 0; }
.upgrade-box ul, .about-box ul { margin: 6px 0 0 18px; padding: 0; font-size: 13px; }
.about-box { border: 2px solid var(--line); background: var(--paper2); padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.key-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.key-table th, .key-table td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; }
.key-table th { background: #e8d7ae; font-weight: normal; }

.start { width: 100%; margin: 4px 0; padding: 7px; font-size: 17px; background: var(--ok); color: #fff; }
.start:hover { background: #6cb87b; }
fieldset { border: 2px solid var(--line); margin: 0 0 8px; padding: 4px 8px 6px; }
legend { padding: 0 5px; }
.rule { display: grid; grid-template-columns: 1fr 112px 36px; align-items: center; gap: 6px; padding: 1px 0; font-size: 13px; }
.rule select { grid-column: 2 / span 2; background: var(--paper2); border: 2px solid var(--line); min-width: 0; }
.rule input[type=checkbox] { grid-column: 2 / span 2; justify-self: start; width: 16px; height: 16px; accent-color: var(--accent); }
.rule input[type=range] { width: 100%; accent-color: var(--accent); }
.rule output { text-align: right; font-size: 12px; }
details { border: 2px solid var(--line); padding: 4px 8px; }
summary { cursor: pointer; }
.crow { display: grid; grid-template-columns: 30px 1fr 1fr 96px; gap: 4px; margin: 3px 0; }
.crow input[type=color] { width: 30px; height: 24px; padding: 0; border: 2px solid var(--line); }
.crow input[type=text], .crow select { background: var(--paper2); border: 2px solid var(--line); min-width: 0; }
#hist { width: 100%; height: auto; border: 3px solid var(--line); cursor: pointer; display: block; }
.rewind { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 34px; margin: 4px 0; flex-wrap: wrap; }
.filter { display: flex; align-items: center; gap: 3px; margin: 4px 0; flex-wrap: wrap; }
.filter label { margin-right: 8px; }
.logs { max-height: 220px; overflow-y: auto; border: 2px solid var(--line); padding: 3px 6px; }
.logs li { display: block; }

.btn.super { background: linear-gradient(#ffe27a, #f0b429); font-weight: bold; }
.btn.super:hover { background: #ffe9a0; }
.ctable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ctable th, .ctable td { padding: 2px 6px; text-align: right; border-bottom: 1px dotted var(--line); }
.ctable th:first-child, .ctable td:first-child { text-align: left; }
.ctable tbody tr { cursor: pointer; }
.ctable tbody tr:hover { background: #ffe9b0; }
#side .acts .btn { white-space: normal; min-width: 0; padding: 4px 5px; font-size: 12px; line-height: 1.25; }

/* 順位表と同盟の一覧 */
#rank-rows { position: relative; margin-top: 3px; overflow: hidden; transition: height .4s; }
.rank-row { position: absolute; left: 0; right: 0; top: 0; height: 22px; display: flex; align-items: center; gap: 4px; padding: 0 3px; border: 0; background: none; cursor: pointer; text-align: left; font-size: 12px; transition: transform .55s cubic-bezier(.3, .9, .3, 1); overflow: hidden; }
.rank-row:hover { background: #ffe9b0; }
.rank-row em { font-style: normal; width: 12px; text-align: right; color: var(--mute); }
.rank-row span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row small { color: var(--mute); }
.rank-row u { position: absolute; left: 0; bottom: 0; height: 2px; text-decoration: none; transition: width .5s; opacity: .85; }
.rank-row.up { animation: rankUp 1s; } .rank-row.down { animation: rankDown 1s; }
#rank.replaying #rank-rows, #rank.replaying .rank-row, #rank.replaying .rank-row u { transition: none !important; animation: none !important; }
@keyframes rankUp { 0% { background: #bfe8a8; } 100% { background: transparent; } }
@keyframes rankDown { 0% { background: #f4c3b4; } 100% { background: transparent; } }
.ally-row { display: flex; align-items: center; gap: 4px; width: 100%; padding: 2px 3px; border: 0; background: none; cursor: pointer; text-align: left; font-size: 12px; }
.ally-row:hover { background: #ffe9b0; }
.ally-row span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ally-row small { color: var(--mute); }
.ally-row.target { padding-left: 14px; color: #8a1a2a; }

/* タイムラプスの操作 */
#replay { position: fixed; bottom: 98px; left: 50%; transform: translateX(-50%); display: none; align-items: center; gap: 8px; padding: 6px 10px; background: var(--paper); border: 3px solid var(--line); box-shadow: 3px 3px 0 rgba(30, 20, 10, .45); z-index: 6; }
#replay.open { display: flex; }
body.subtools-open #replay { bottom: 150px; }
#rp-pos { width: min(46vw, 420px); accent-color: var(--accent); }
#rp-year { min-width: 60px; text-align: right; }

/* シネマ（観戦・壁紙）モード */
#cinema-hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 7; }
body.cinema #cinema-hud { display: block; }
body.cinema #top,
body.cinema #log,
body.cinema #modes,
body.cinema #hud-left,
body.cinema #tools,
body.cinema #side,
body.cinema #status,
body.cinema #replay { display: none !important; }
#cinema-year {
  position: fixed; top: 12px; left: 12px; padding: 4px 10px;
  background: rgba(255, 246, 223, .92); border: 3px solid var(--line);
  box-shadow: 3px 3px 0 rgba(30, 20, 10, .45); font-size: 16px; color: var(--ink);
}
#cinema-exit { position: fixed; top: 12px; right: 12px; pointer-events: auto; }
#cinema-sub {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  max-width: min(92vw, 680px); padding: 5px 12px;
  background: rgba(255, 246, 223, .92); border: 3px solid var(--line);
  box-shadow: 3px 3px 0 rgba(30, 20, 10, .45); font-size: 13px; color: var(--ink); text-align: center;
}
#cinema-sub:empty { display: none; }

@media (max-width: 1100px) { #world { display: none; } #log { width: 240px; } .tool { width: 44px; } .tool span { font-size: 11px; } }
@media (max-width: 1000px) {
  #hud-left { max-height: calc(100vh - 360px); }
  #log { bottom: 162px; width: 220px; max-height: 92px; }
  #status { right: 10px; bottom: 10px; max-width: 195px; }
  #side { max-height: calc(100vh - 224px); }
}
@media (max-width: 768px) {
  #top {
    gap: 4px; padding: 0 18px 0 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 14px), rgba(0,0,0,.35) 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 14px), rgba(0,0,0,.35) 100%);
  }
  #top .gap { display: none; }
  #top #year { font-size: 15px; min-width: 48px; }
  #top .btn { padding: 3px 6px; font-size: 12px; }
  #top .seg button { padding: 3px 6px; font-size: 12px; }
  #modes { top: 50px; left: 6px; max-width: calc(100vw - 12px); overflow-x: auto; }
  #modes button { padding: 2px 7px; font-size: 12px; }
  #hud-left { top: 84px; left: 6px; width: 174px; max-height: calc(100vh - 168px); gap: 4px; }
  #rank, #favs, #challenge-hud { padding: 4px 5px; font-size: 11px; }
  #rank { max-height: 28vh; }
  #favs { max-height: 22vh; }
  #challenge-hud { max-height: 20vh; overflow-y: auto; }
  #log, #status { display: none; }
  #side {
    top: auto; left: 6px; right: 6px;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    width: auto; max-height: 44vh; padding: 10px;
  }
  body.subtools-open #side {
    bottom: calc(156px + env(safe-area-inset-bottom, 0px));
    max-height: 34vh;
  }
  #tools {
    bottom: max(6px, env(safe-area-inset-bottom, 6px));
    left: 50%; transform: translateX(-50%);
    max-width: calc(100vw - 12px); overflow-x: auto; padding: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .groups { width: max-content; }
  #subtools { justify-content: flex-start; width: max-content; min-width: 100%; }
  #replay {
    width: calc(100vw - 12px); flex-wrap: wrap; justify-content: center;
    gap: 5px; padding: 6px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }
  body.subtools-open #replay {
    bottom: calc(156px + env(safe-area-inset-bottom, 0px));
  }
  #rp-pos { width: 100%; order: 10; }
  #toasts { width: calc(100vw - 16px); top: 84px; }
  .toast { max-width: 100%; font-size: 12px; }
  #modal { padding: 8px; }
  .win { padding: 12px; }
  .setup { grid-template-columns: 1fr; }
  #prev { max-height: 128px; }
  .setup-cta { bottom: -12px; }
  .setup-cta .btn { font-size: 15px; }
  .stats.st3 { grid-template-columns: 1fr; }
}
