:root {
  --bg0: #0c1a14;
  --bg1: #132820;
  --panel: rgba(18, 40, 30, 0.92);
  --line: rgba(232, 220, 190, 0.16);
  --text: #efe6d4;
  --muted: rgba(239, 230, 212, 0.62);
  --accent: #c4a35a;
  --accent-dim: #8a7340;
  --ok: #6cb38a;
  --danger: #d47a6a;
  --font: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --serif: 'Noto Serif TC', 'Noto Serif', serif;
}

* {
  box-sizing: border-box;
}

/* 作者樣式的 display 會蓋掉原生 [hidden]，必須強制 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(60, 120, 85, 0.28), transparent 50%),
    radial-gradient(ellipse at 90% 100%, rgba(40, 70, 50, 0.35), transparent 45%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 55%, #0a1510);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login__panel {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.login__brand {
  margin: 0;
  font-family: var(--serif);
  font-size: 2rem;
  letter-spacing: 0.1em;
  text-align: center;
}

.login__tag {
  margin: -6px 0 8px;
  text-align: center;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  text-align: left;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input,
.toolbar input,
.toolbar select,
#leaderBy {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent-dim);
}

.btn--primary {
  background: linear-gradient(180deg, #d2b36a, #a8873f);
  color: #1a1408;
  border-color: transparent;
  font-weight: 700;
}

.btn--ghost {
  background: transparent;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* 雙保險：用 body 狀態切畫面（與 WebOnline gate 相同做法） */
body[data-screen='login'] #loginView {
  display: grid !important;
}
body[data-screen='login'] #appView {
  display: none !important;
}
body[data-screen='app'] #loginView {
  display: none !important;
}
body[data-screen='app'] #appView {
  display: grid !important;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 18, 14, 0.75);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__brand {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.topbar__nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-btn.is-active,
.nav-btn:hover {
  color: var(--text);
  background: rgba(196, 163, 90, 0.14);
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main {
  padding: 22px 20px 40px;
  width: min(1100px, 100%);
  margin: 0 auto;
}

.view h2 {
  margin: 0 0 16px;
  font-size: 1.35rem;
}

.view h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 500;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.card__label {
  font-size: 0.82rem;
  color: var(--muted);
}

.card__value {
  margin-top: 6px;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 800px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}

.toolbar input[type='search'] {
  flex: 1;
  min-width: 180px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 500;
  background: rgba(0, 0, 0, 0.18);
}

tr:last-child td {
  border-bottom: 0;
}

tr[data-href] {
  cursor: pointer;
}

tr[data-href]:hover td {
  background: rgba(196, 163, 90, 0.08);
}

.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.linkish {
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chart {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 88px 1fr 40px;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: inherit;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
}

.pill--ok {
  color: var(--ok);
  border-color: rgba(108, 179, 138, 0.4);
}

.pill--dim {
  color: var(--muted);
}

.detail-grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 12px;
  font-size: 0.92rem;
}

.kv dt {
  margin: 0;
  color: var(--muted);
}

.kv dd {
  margin: 0;
  word-break: break-all;
}

pre.json {
  margin: 0;
  padding: 12px;
  overflow: auto;
  max-height: 420px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 0.8rem;
  line-height: 1.45;
}
