@font-face {
  font-family: Evolventa;
  src: url('/assets/Evolventa-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Evolventa;
  src: url('/assets/Evolventa-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #f0f3f5;
  --surface: #fff;
  --ink: #172330;
  --muted: #546372;
  --line: #dce3e8;
  --control: #f6f8fa;
  --accent: #205ac2;
  --accent-ink: #fff;
  --good: #087343;
  --bad: #a42836;
  --mono: 'Cascadia Code', 'SFMono-Regular', Consolas, monospace;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 290px; color: var(--ink); background: var(--page); }
a { color: inherit; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { opacity: .53; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(29px, 4vw, 42px); line-height: 1.12; letter-spacing: -.032em; }
h2 { font-size: 17px; line-height: 1.25; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; font-size: 14px; font-weight: 700; }
label { min-width: 0; display: grid; gap: 7px; font-size: 14px; font-weight: 650; }
label small { font-size: 12px; font-weight: 400; }
input, select {
  background: var(--control);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  min-height: 43px;
  font-size: 16px;
}
input::placeholder { color: var(--muted); }
select { padding-right: 26px; }
.primary, .secondary, .text-button, .icon-button {
  min-height: 38px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 8px 13px;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 650;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover:enabled { filter: brightness(1.09); }
.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.secondary:hover, .text-button:hover, .icon-button:hover { background: var(--control); }
.text-button, .icon-button { background: transparent; color: var(--muted); }
.icon-button { font-size: 24px; width: 38px; padding: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }
.positive { color: var(--good); }
.negative { color: var(--bad); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.form-stack { display: grid; gap: 17px; }
.message { font-size: 14px; line-height: 1.45; border-radius: 8px; padding: 11px 13px; overflow-wrap: anywhere; }
.message.error { color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.message.success { color: var(--good); background: color-mix(in srgb, var(--good) 9%, var(--surface)); }

.topbar {
  min-height: 68px;
  padding: 10px clamp(15px, 3.2vw, 45px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #111a24;
  color: #edf4fa;
}
.brand { display: inline-flex; gap: 11px; align-items: center; text-decoration: none; font-weight: 700; line-height: 1.35; }
.brand small { display: block; color: #a9bacb; font-size: 11px; font-weight: 500; }
.brand-icon {
  display: grid;
  place-items: center;
  min-width: 35px;
  height: 35px;
  padding: 0 5px;
  border: 1px solid #53677d;
  border-radius: 5px;
  color: #c6ddfc;
  font: 700 14px var(--mono);
}
.topbar nav { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 5px 16px; }
.topbar nav a, .topbar nav button { color: #d0dbe7; text-decoration: none; font-size: 13px; }
.topbar nav a:hover { color: #fff; text-decoration: underline; }
.topbar nav button:hover { color: #fff; background: #263648; }
.admin-shell { display: grid; grid-template-columns: 196px minmax(0, 1fr); min-height: calc(100dvh - 68px); }
.admin-sidebar { background: #e8edf1; border-right: 1px solid #d5dee6; padding: 28px 13px; }
.sidebar-title { margin: 0 10px 12px; color: var(--muted); font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: .065em; }
.admin-sidebar nav { display: grid; gap: 5px; }
.admin-sidebar a { display: flex; align-items: center; gap: 9px; color: #3a4b5c; border-radius: 7px; padding: 10px 10px; text-decoration: none; font-size: 14px; }
.admin-sidebar a:hover { background: #dee6ed; }
.admin-sidebar a[aria-current] { color: #144794; background: #d7e4f7; font-weight: 700; }
.tab-icon { font: 17px var(--mono); width: 20px; text-align: center; }
.admin-main, .live-shell { width: 100%; max-width: 1500px; margin: 0 auto; padding: 40px clamp(15px, 3.7vw, 56px) 65px; min-width: 0; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 26px; }
.page-heading p { color: var(--muted); font-size: 14px; margin-top: 9px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; min-width: 0; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 15px 19px; border-bottom: 1px solid var(--line); }
.inline-label { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.inline-label select { min-height: 37px; width: clamp(135px, 25vw, 250px); font-size: 14px; padding-block: 6px; }
.admin-main > .message, .live-shell > .message { margin-bottom: 12px; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
th { font-size: 12px; color: var(--muted); background: #f6f8fa; font-weight: 650; white-space: nowrap; }
td, th { padding: 12px 15px; border-bottom: 1px solid var(--line); }
td:first-child, th:first-child { padding-left: 19px; }
td:last-child, th:last-child { padding-right: 19px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
thead:first-child tr th:first-child { border-top-left-radius: 9px; }
thead:first-child tr th:last-child { border-top-right-radius: 9px; }
.operations { min-width: 795px; }
.amount { text-align: right; white-space: nowrap; }
.index { color: var(--muted); font-size: 12px; white-space: nowrap; margin-right: 5px; }
.tag { display: inline-block; padding: 3px 7px; color: var(--muted); border-radius: 5px; background: var(--control); font-size: 12px; font-weight: 700; }
.tag.positive { color: var(--good); background: #e6f4eb; }
.tag.negative { color: var(--bad); background: #faebed; }
.revision-label { margin-left: 4px; white-space: nowrap; }
.operation-note { display: block; margin-top: 4px; max-width: 180px; overflow-wrap: anywhere; }
.empty { padding: 38px 21px; text-align: center; color: var(--muted); font-size: 14px; }
.paging { border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; padding: 11px 16px; }
.auth-shell { padding: 60px 16px; }
.auth-card { max-width: 440px; padding: 28px; margin: 0 auto; }
.auth-card h1 { font-size: 30px; }
.auth-card p { margin-top: 10px; }
.auth-card form { margin-top: 23px; }
.live-journal { margin-top: 22px; }
.ranking th:first-child { width: 95px; }
.ranking td { height: 56px; }
.total { font-weight: 700; font-size: 19px; }
.live-status { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; border: 1px solid #d3dce4; color: var(--muted); font: 600 12px var(--mono); white-space: nowrap; }
.live-status i, .station-label i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.live-status.online { color: #17613e; background: #eaf5ee; border-color: #cee3d7; }
dialog { width: min(94vw, 500px); max-height: 88dvh; padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 28px 90px #111a2450; }
dialog::backdrop { background: #17233080; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 20px; }
dialog form { padding: 19px 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 3px; }
.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.dialog-context { font-size: 14px; }
.revision-history { border-top: 1px solid var(--line); padding: 13px 20px; font-size: 13px; }
.revision-history summary { cursor: pointer; }
.revision-history ol { margin: 8px 0 0; padding: 0; list-style: none; }
.revision-history li { display: grid; gap: 4px; padding: 8px 0; border-top: 1px solid var(--line); }

.station-body {
  --ink: #211b29;
  --muted: #5f5467;
  --accent: #bb4618;
  --surface: #fff;
  --control: #f3f0f6;
  --line: #e7dfea;
  font-family: Evolventa, system-ui, sans-serif;
  background: #ff9f70;
}
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, #f7e08b 0%, #ffa05a 55%, #ff8aad 100%);
}
.ground {
  position: absolute;
  left: 50%;
  bottom: -4vh;
  width: max(110%, 760px);
  height: clamp(180px, 46vh, 540px);
  transform: translateX(-50%);
}
.cloud { position: absolute; opacity: .79; }
.cloud-a { left: -3%; top: 10%; width: clamp(160px, 24vw, 310px); }
.cloud-b { right: -3%; top: 17%; width: clamp(180px, 27vw, 340px); }
.cloud-c { left: 30%; top: 29%; width: clamp(150px, 19vw, 230px); opacity: .55; }
.station-shell { position: relative; width: min(100%, 590px); margin: 0 auto; min-height: 100dvh; padding: 23px 15px 26px; }
.station-card {
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border: 1px solid #fff9;
  border-radius: 22px;
  box-shadow: 0 25px 65px -26px #49203680;
  overflow: hidden;
}
.station-card[aria-busy=true] { padding: 28px; }
.station-head { display: flex; justify-content: space-between; align-items: center; min-height: 55px; border-bottom: 1px solid var(--line); padding: 8px 27px; }
.station-label { display: flex; align-items: center; gap: 8px; color: #8e3b1b; font-size: 13px; font-weight: 700; }
.station-label i { box-shadow: 0 0 0 4px #f6e1d7; background: #db6432; margin-left: 4px; }
.station-content { padding: 23px 27px 28px; }
.station-content h1 { font-size: clamp(27px, 5vw, 37px); overflow-wrap: anywhere; }
#station-result h1 { margin-bottom: 20px; }
.station-intro { margin: 8px 0 21px; font-size: 14px; line-height: 1.5; }
.station-card .form-stack { gap: 15px; }
.station-card input, .station-card select { border-radius: 12px; min-height: 46px; }
.station-card .primary { justify-content: space-between; min-height: 48px; border-radius: 12px; padding-inline: 16px; }
.station-submit { display: grid; padding-top: 12px; border-top: 1px solid #dcd1e0; }
#game-form .primary:disabled { background: #e7e0ea; color: var(--muted); opacity: 1; }
.pin-input { letter-spacing: .35em; }
.station-card:has(.station-team-options:not([hidden])) { overflow: visible; }
.station-team-picker { position: relative; display: grid; gap: 7px; min-width: 0; font-size: 14px; font-weight: 700; }
.station-team-trigger {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 48px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--control);
  color: var(--ink);
  text-align: left;
  font-size: 16px;
  font-weight: 700;
}
.station-team-trigger[aria-expanded=true] { border-color: #c75c32; background: #fffaf7; }
.station-team-value, .station-team-options li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.station-team-name {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px;
  align-items: baseline;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.station-team-number {
  min-width: 2ch;
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.station-team-balance {
  border-radius: 7px;
  padding: 5px 8px;
  background: #e2f1e8;
  color: var(--good);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}
.station-team-balance.negative { background: #f9e5e9; color: var(--bad); }
.station-team-chevron {
  width: 8px;
  height: 8px;
  border: solid var(--muted);
  border-width: 0 2px 2px 0;
  margin: 0 2px 4px 0;
  transform: rotate(45deg);
}
.station-team-trigger[aria-expanded=true] .station-team-chevron { margin: 4px 2px 0 0; transform: rotate(225deg); }
.station-team-options {
  position: absolute;
  z-index: 2;
  inset: calc(100% + 5px) 0 auto;
  max-height: min(320px, 45vh);
  overflow: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 16px 35px #49203638;
  list-style: none;
}
.station-team-options:focus-visible { outline: none; }
.station-team-options li { min-height: 44px; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 15px; }
.station-team-options li[aria-selected=true] { background: #fff1e9; }
.station-team-options li.is-active { box-shadow: inset 0 0 0 1px #ca896e; background: #fff5ee; }
.difficulty, .outcomes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.difficulty label, .outcomes label { position: relative; cursor: pointer; }
.difficulty input, .outcomes input { position: absolute; opacity: 0; width: 1px; height: 1px; padding: 0; min-height: 0; }
.difficulty label > span, .outcomes label > span { display: block; border-radius: 13px; background: var(--control); border: 1px solid var(--line); padding: 10px 11px; }
.difficulty input:focus-visible + span, .outcomes input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.difficulty input:checked + span { border-color: #c75c32; background: #fff1e9; }
.difficulty b { display: block; line-height: 1.08; font-size: 23px; }
.difficulty small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.difficulty em { position: absolute; top: 11px; right: 9px; padding: 3px 6px; border-radius: 7px; color: #903e20; background: #f7e2d9; font: 650 11px var(--mono); }
.outcomes i { font-style: normal; margin-right: 3px; }
.outcomes input[value=win]:checked + span { color: var(--good); background: #e7f6ec; border-color: #5d9e78; }
.outcomes input[value=loss]:checked + span { color: var(--bad); background: #fdecee; border-color: #c57880; }
.preview { display: flex; gap: 8px; justify-content: space-between; align-items: center; border-radius: 9px; background: var(--control); padding: 9px 11px; font-size: 13px; }
.preview strong { font: 700 16px var(--mono); }
.station-navigation {
  position: fixed;
  z-index: 1;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  gap: 7px;
}
.station-navigation button {
  min-height: 44px;
  padding: 8px 15px;
  border: 1px solid #fff9;
  border-radius: 12px;
  background: #fff3e9;
  color: #431e27;
  box-shadow: 0 4px 17px #351e2940;
  font-size: 13px;
  font-weight: 700;
}
.station-navigation button:hover { background: white; }
.station-navigation button[aria-expanded=true] { border-color: var(--accent); }
.station-history h2 { font-size: clamp(24px, 4vw, 32px); }
.station-history > .muted { margin: 7px 0 16px; font-size: 14px; }
.station-history > .message { margin-bottom: 10px; }
.station-history-list { border-top: 1px solid var(--line); margin: 0; padding: 0; list-style: none; }
.station-history-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 6px 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.history-team { font-size: 14px; overflow-wrap: anywhere; }
.history-delta, .history-time { text-align: right; white-space: nowrap; }
.history-details { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.history-details, .history-time { color: var(--muted); font-size: 12px; }
.station-history-paging { display: flex; justify-content: flex-end; gap: 8px; margin-top: 13px; }
.station-history-paging:not(:has(button:not([hidden]))) { display: none; }

@media (max-width: 850px) {
  .station-shell:has(+ .station-navigation:not([hidden])) { padding-bottom: 123px; }
}
@media (max-width: 760px) {
  .admin-shell { grid-template-columns: 1fr; align-content: start; }
  .admin-sidebar { border-right: 0; border-bottom: 1px solid #d5dee6; padding: 7px 12px; }
  .sidebar-title { display: none; }
  .admin-sidebar nav { grid-template-columns: repeat(3, 1fr); }
  .admin-sidebar a { justify-content: center; padding-inline: 4px; }
  .admin-main, .live-shell { padding-top: 25px; }
}
@media (max-width: 420px) {
  .topbar { padding-inline: 11px; }
  .topbar nav { column-gap: 9px; }
  .topbar nav a, .topbar nav button { font-size: 12px; }
  .topbar nav button { padding-inline: 5px; }
  .brand { gap: 7px; font-size: 13px; }
  .brand small { font-size: 10px; }
  .brand-icon { min-width: 30px; height: 31px; }
  .tab-icon { display: none; }
  .page-heading { align-items: flex-start; }
  .page-heading p { font-size: 13px; }
  .panel-heading { padding-inline: 12px; }
  .station-head, .station-content { padding-inline: 17px; }
  .history-time { grid-column: 1 / -1; text-align: left; }
  .difficulty label > span, .outcomes label > span { padding-inline: 8px; }
  .difficulty b { font-size: 21px; }
  .difficulty em { top: 10px; right: 7px; }
}
