:root {
  color-scheme: light;
  --paper: #f3ead8;
  --ink: #2b241c;
  --muted: #8a7b68;
  --line: #d4c4a8;
  --card: #fff8ea;
  --bar: #efe4cc;
  --accent: #8b1e1e;
  --gold: #8a5a10;
  --sel: #f3e0c4;
  --ok: #1f7a34;
}
#app.is-dk {
  color-scheme: dark;
  --paper: #2c241c;
  --ink: #fff8ea;
  --muted: #cbb9a0;
  --line: #5c5248;
  --card: #4c4339;
  --bar: #3a322c;
  --accent: #c45c48;
  --gold: #e4c27a;
  --sel: #5c4e42;
  --ok: #2f9a4a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.phone {
  position: relative;
  width: min(100%, 390px);
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #3a2410;
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
.bg-lock {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("../img/bg.jpg?v=comp1");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
#factions-page,
#chars-page,
#score-page {
  background-color: transparent;
}
#factions-page .top {
  background: rgba(88, 52, 18, 0.32);
  border-bottom-color: rgba(255, 255, 255, 0.22);
  color: #fff8ea;
}
#factions-page .top p { color: rgba(255, 248, 234, 0.82); }
#factions-page .icon-btn { color: #fff8ea; }
.screen {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
#factions-page::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(rgba(8, 3, 0, 0.58), rgba(4, 1, 0, 0.72));
}
#factions-page > *,
#chars-page > *,
#score-page > * {
  position: relative;
  z-index: 2;
}
#factions-page .top,
#chars-page .top,
#score-page .top {
  z-index: 4;
}
#chars-page .top,
#score-page .top {
  background: rgba(255, 248, 232, 0.78);
  border-bottom-color: rgba(255, 255, 255, 0.35);
  color: #2b241c;
}
#chars-page .top p,
#score-page .top p {
  color: #6e5f4e;
}
#chars-page .bar,
#chars-page .special {
  color: #2b241c;
  background: rgba(255, 248, 232, 0.97);
  border-top-color: rgba(255, 255, 255, 0.35);
}
#chars-page .bar .btn-ghost {
  background: #fff8ea;
  color: #2b241c;
  border-color: #d4c4a8;
}
#app.is-dk #chars-page .top,
#app.is-dk #score-page .top {
  background: rgba(42, 32, 24, 0.78);
  border-bottom-color: rgba(255, 255, 255, 0.12);
  color: #fff8ea;
}
#app.is-dk #chars-page .top p,
#app.is-dk #score-page .top p {
  color: rgba(255, 248, 234, 0.75);
}
#app.is-dk #chars-page .bar,
#app.is-dk #chars-page .special {
  background: rgba(42, 32, 24, 0.97);
  border-top-color: rgba(255, 255, 255, 0.12);
  color: #fff8ea;
}
#app.is-dk #chars-page .bar .btn-ghost {
  background: #4c4339;
  color: #fff8ea;
  border-color: #5c5248;
}
.top {
  position: relative;
  z-index: 3;
  padding: 12px 16px 10px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 18px; font-weight: 500; }
.top p, .note, .err { font-size: 12px; color: var(--muted); }
.top-row, .score-head, .factions-head { display: flex; align-items: center; gap: 4px; }
.factions-head { justify-content: space-between; }
.page-title { flex: 1; min-width: 0; }
.icon-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn svg { display: block; }
.more-btn .tri-up { display: none; }
.more-btn[aria-expanded="true"] .tri-down { display: none; }
.more-btn[aria-expanded="true"] .tri-up { display: block; }
.scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 8px 12px 12px;
  position: relative;
  z-index: 2;
}
.faction-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 14px;
  container-type: inline-size;
}
.faction-btn {
  appearance: none;
  display: block;
  width: 100%;
  aspect-ratio: 709 / 118;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background-color: transparent;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  color: transparent;
  font-size: 0;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 224, 150, 0.22), 0 2px 8px rgba(0, 0, 0, 0.42);
  filter: brightness(1.08) saturate(1.06);
}
.faction-btn.has-pick {
  box-shadow: 0 0 0 3px #c45c48, 0 1px 4px rgba(0, 0, 0, 0.35);
}
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.block {
  margin-bottom: 12px;
  container-type: inline-size;
}
.block h2 {
  font-size: 13px;
  font-weight: 500;
  color: var(--gold);
  margin-bottom: 8px;
  padding-left: 8px;
  border-left: 3px solid var(--accent);
}
#score-page .block h2 {
  color: #fff8ea;
  text-shadow: 0 1px 3px rgba(40, 18, 0, 0.55);
}
.card {
  appearance: none;
  position: relative;
  min-height: 52px;
  padding: 16px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.card[aria-pressed="true"] {
  background: var(--sel);
  border-color: var(--accent);
}
.check {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 14px;
  height: 14px;
  border: 1px solid var(--muted);
  border-radius: 3px;
  background: var(--paper);
  color: #fff8ea;
  font-size: 11px;
  line-height: 12px;
  text-align: center;
}
.card[aria-pressed="true"] .check {
  border-color: var(--accent);
  background: var(--accent);
}
.card[aria-pressed="true"] .check::after { content: "✓"; }
#chars-page .char-stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#chars-page #char-host {
  flex: 1 1 auto;
  min-height: 0;
}
#chars-page .special {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  height: auto;
  max-height: 66.666%;
  overflow: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--line);
}
#chars-page .special::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.err { padding: 4px 16px 0; color: var(--accent); }
.bar {
  display: grid;
  grid-template-columns: 10% 55% 5% 20% 10%;
  align-items: center;
  min-height: 64px;
  padding-bottom: 8px;
  background: var(--bar);
  border-top: 1px solid var(--line);
}
#chars-page .bar {
  flex: 0 0 auto;
}
.btn {
  appearance: none;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost[aria-expanded="true"] {
  border-color: var(--gold);
  color: var(--gold);
}
.btn-go {
  background: var(--accent);
  color: #fff8ea;
}
.more { position: relative; flex-shrink: 0; margin-left: auto; z-index: 7; }
.more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 8;
  min-width: 148px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(43, 36, 28, 0.22);
}
.more-menu button {
  appearance: none;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.more-menu button:active { background: var(--sel); }
.unit {
  display: flex;
  flex-direction: column;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  overflow: hidden;
}
.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  container-type: inline-size;
}
.score-grid .unit {
  aspect-ratio: 1;
  width: 100%;
  min-height: 0;
  height: auto;
  justify-content: flex-end;
  padding: 4cqi 5cqi 5cqi;
}
.score-grid .cname {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  font-size: clamp(16px, 6.5cqi, 34px);
  padding: 0;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.score-grid .score-fields {
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  margin: 0;
  gap: 2.5cqi;
  justify-content: flex-end;
}
.score-grid .val {
  min-height: 10cqi;
  margin: 0;
  padding: 0 2cqi;
  font-size: clamp(14px, 5.5cqi, 24px);
  border-radius: 2.5cqi;
}
.score-grid .sp {
  gap: 2cqi;
}
.score-grid .sp button {
  width: 7.5cqi;
  height: 7.5cqi;
  font-size: clamp(13px, 4.5cqi, 18px);
  border-radius: 2cqi;
}
.score-grid .sp output {
  min-width: 1.2em;
  font-size: clamp(13px, 4.5cqi, 20px);
}
.cname {
  padding: 8px 6px 0;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}
.score-fields {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: fit-content;
  min-width: 104px;
  margin: 4px auto 6px;
}
.sp {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.sp button {
  appearance: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  cursor: pointer;
}
.sp output {
  min-width: 1.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.val {
  appearance: none;
  min-height: 28px;
  margin: 0 0 4px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.builds-wrap {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  background: transparent;
  border-top: 0;
}
.builds-toggle {
  appearance: none;
  position: absolute;
  top: 4px;
  right: 2px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  cursor: pointer;
}
.builds-toggle svg { display: block; }
.builds-toggle .tri-up { display: none; }
.builds-toggle[aria-expanded="false"] .tri-down { display: none; }
.builds-toggle[aria-expanded="false"] .tri-up { display: block; }
.builds {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 6px 36px 10px 8px;
}
.builds-wrap.is-collapsed .build:nth-child(n + 4) { display: none; }
.build {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.build p { font-size: 12px; font-weight: 500; text-align: center; }
.build .val { margin: 0; min-height: 28px; font-size: 13px; }

#app.is-lg .grid,
#app.is-lg .score-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  container-type: inline-size;
}
#app.is-lg .card {
  min-height: 0;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 6.5cqi, 34px);
  padding: 10px 8px;
}
#app.is-lg .builds { container-type: inline-size; }
#app.is-lg .build p {
  font-size: clamp(16px, 6.5cqi, 34px);
  line-height: 1.15;
}
#app.is-lg .block h2 {
  font-size: clamp(16px, 6.5cqi, 34px);
  line-height: 1.15;
}

#app.is-sm .grid,
#app.is-sm .score-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  container-type: inline-size;
}
#app.is-sm .card {
  min-height: 52px;
  font-size: 13px;
}
#app.is-sm .score-grid .cname { font-size: 13px; }
#app.is-sm .score-grid .val {
  min-height: 28px;
  font-size: 13px;
}
#app.is-sm .score-grid .sp button {
  width: 28px;
  height: 28px;
  font-size: 13px;
}
#app.is-sm .score-grid .sp output { font-size: 13px; }
#app.is-sm .build p { font-size: 12px; }
#app.is-sm .block h2 { font-size: 13px; }

.modal {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(43, 36, 28, 0.45);
  padding: 20px;
}
.dialog {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 16px 16px;
  border-radius: 16px;
  background: var(--card);
}
.dialog h2 { font-size: 16px; font-weight: 500; text-align: center; }
.score-display {
  appearance: none;
  width: 100%;
  min-height: 72px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-size: 40px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  cursor: pointer;
}
.score-display.is-ph { color: var(--muted); }
.keys {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.key {
  appearance: none;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.key:active { background: var(--sel); }
.ops {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  width: 100%;
}
.op {
  appearance: none;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-size: 22px;
  cursor: pointer;
}
.op[aria-pressed="true"] {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff8ea;
}
.modal .err { padding: 0; text-align: center; }
.install-pic {
  width: 100%;
  max-height: calc(100dvh - 32px);
  object-fit: contain;
  border-radius: 12px;
  display: block;
}

.admin {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-inline: 1px solid var(--line);
}
.lock {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--paper);
}
.lock h1 { font-size: 18px; font-weight: 500; }
.lock p { font-size: 13px; color: var(--muted); }
.lock-pass { width: 100%; }
.lock-pass input { flex: 1; min-width: 0; }
.lock .err { padding: 0; }
.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.admin-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-tools .btn-go {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
}
.admin-tools .btn-go:disabled { opacity: 0.45; cursor: not-allowed; }
.save-status { padding-top: 0; }
.save-status.is-dirty { color: var(--gold); }
.save-status.is-err { color: var(--accent); }
.pick {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.pick select, .pick input, .setup-btn {
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 13px;
}
.setup-btn { cursor: pointer; font-weight: 500; }
.help {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--ink);
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.table-wrap { flex: 1; overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
}
th {
  position: sticky;
  top: 0;
  padding: 8px;
  background: var(--bar);
  font-weight: 500;
  font-size: 13px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.pair { display: flex; align-items: center; gap: 6px; }
.code { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 500; }
table input {
  width: 100%;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  font-size: 13px;
}
table input::placeholder { color: var(--muted); opacity: 1; }
.num { width: 4.8rem; font-variant-numeric: tabular-nums; }
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px 12px;
  background: var(--bar);
  border-top: 1px solid var(--line);
}
.pager button {
  appearance: none;
  min-height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  font-size: 12px;
  cursor: pointer;
}
.pager button[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff8ea;
}
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.setup {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(43, 36, 28, 0.45);
  padding: 20px;
}
.setup-box {
  width: min(100%, 280px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 12px;
  background: var(--card);
}
.setup-box h2 { font-size: 16px; font-weight: 500; }
.admin-export {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bar);
  border-top: 1px solid var(--line);
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
