:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #17212b;
  --muted: #647383;
  --border: #dce2e7;
  --accent: #0b6e99;
  --accent-hover: #095a7d;
  --danger: #b42318;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: transparent;
}

.app-sticky-chrome {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.app-sticky-chrome .topbar,
.app-sticky-chrome .section-nav {
  max-width: 720px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.section-nav {
  display: flex;
  gap: 8px;
  padding: 0 18px 10px;
}

.section-chip {
  flex: 1;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
  color: var(--muted);
}

.section-chip.is-active,
.section-chip[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.topbar h1, .topbar p, .panel h2, .panel p { margin: 0; }
.topbar h1 { font-size: 1.35rem; }
.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}
.muted { color: var(--muted); font-size: 0.9rem; }
.status-text { color: var(--muted); font-size: 0.85rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.auth-shell {
  display: none;
}

body.is-auth {
  min-height: 100dvh;
}

body.is-auth .app-chrome {
  display: none !important;
}

body.is-auth .auth-shell {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px;
}

.auth-card .eyebrow {
  margin: 0;
}

.auth-card h2 {
  font-size: 1.45rem;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-submit {
  width: 100%;
}

.turnstile-slot {
  min-height: 0;
}

.turnstile-slot:empty {
  display: none;
}

.text-link {
  appearance: none;
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 4px 0;
  min-height: 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.92rem;
  text-align: center;
}

.text-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.text-link:disabled {
  opacity: 0.45;
  cursor: default;
  text-decoration: none;
}

.auth-support {
  margin: 4px 0 0;
  text-align: center;
  font-size: 0.82rem;
}

.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.panel.auth-card {
  width: min(400px, 100%);
  padding: 22px 20px 18px;
  gap: 12px;
}

.button {
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 700;
}
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.button.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 6px 10px;
  font-weight: 600;
}
.button.quiet:hover {
  color: var(--text);
  background: #eef2f5;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.92rem;
}
input, select {
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.device-workspace {
  display: grid;
  gap: 16px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #e8edf1;
  color: var(--muted);
}
.status-pill.is-online {
  background: #e5f6ec;
  color: #1f7a43;
}
.status-pill.is-offline {
  background: #f3e8e8;
  color: #9b3a32;
}

.status-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 0;
}
.status-facts div {
  display: grid;
  gap: 2px;
}
.status-facts dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}
.status-facts dd {
  margin: 0;
  font-weight: 700;
}

.wifi-hint { font-size: 0.85rem; }

.device-cheatsheet {
  margin: 0;
  padding: 10px 12px 10px 1.35em;
  display: grid;
  gap: 6px;
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.device-cheatsheet strong {
  color: var(--text);
  font-weight: 700;
}

.status-meta {
  display: grid;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.status-meta .support-line,
.status-meta .muted {
  font-size: 0.78rem;
}

.support-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 0;
  font-size: 0.85rem;
}
.support-line code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.88em;
}
.support-copy {
  width: auto;
  display: inline;
  text-align: left;
  font-size: 0.85rem;
}

.look-card .theme-picker {
  margin-bottom: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.brightness-honest-note {
  grid-column: 1 / -1;
  margin: 0;
}

.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.theme-swatch {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
}
.theme-swatch[data-theme="daylight"] { background: #f3f6f9; color: #142033; }
.theme-swatch[data-theme="midnight"] { background: #09121c; color: #f7fafc; }
.theme-swatch[data-theme="harbour"] { background: #e8f1f6; color: #123247; }
.theme-swatch[data-theme="tram"] { background: #eaf4ee; color: #143226; }
.theme-swatch[data-theme="amber"] { background: #f7f1e8; color: #2a2118; }
.theme-swatch[data-theme="sakura"] { background: #fff1f4; color: #3a2430; }
.theme-swatch.is-selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.device-list { display: grid; gap: 8px; }
.device-card {
  display: grid;
  gap: 6px;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.device-card strong { font-size: 1.05rem; }
.device-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.route-list { display: grid; gap: 12px; }

.quote-list { display: grid; gap: 12px; }
.quote-editor {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #fafbfc;
}
.quote-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.quote-summary-button {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  min-height: 0;
  text-align: left;
  display: grid;
  gap: 2px;
  flex: 1;
}
.quote-summary-text {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.quote-fields {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}
.quote-editor.is-empty .quote-toolbar,
.quote-editor.is-empty .quote-fields,
.quote-editor:not(.is-empty) .quote-add,
.quote-editor:not(.is-open) .quote-fields {
  display: none;
}
.quote-editor.is-empty .quote-add {
  width: 100%;
}
.quote-editor label {
  margin: 0;
  display: grid;
  gap: 6px;
}
.quote-editor .enabled-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 0;
  white-space: nowrap;
}
.quote-symbol-wrap {
  position: relative;
  display: block;
}
.quote-symbol-wrap .quote-symbol {
  width: 100%;
}
.quote-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 8;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 180px;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.quote-suggest:not(.is-open) {
  display: none;
}
.quote-suggest-item {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.quote-suggest-item:hover,
.quote-suggest-item:focus {
  background: var(--surface-muted, #f3f4f6);
}
.quote-enabled-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  white-space: nowrap;
}
.quote-color-field {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  max-width: 220px;
}
.quote-board-preview {
  margin-top: 12px;
}
.quote-preview-meta,
.quote-preview-note {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}
.quote-preview-note { margin-top: 8px; }
.quote-preview-board {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #f3f6f9;
  font-family: "Noto Sans HK", "Noto Sans CJK TC", sans-serif;
}
.quote-preview-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 56px 72px;
  gap: 6px;
  align-items: center;
  min-height: 48px;
  padding: 6px 10px;
  border-bottom: 1px solid #d5dee8;
}
.quote-preview-board[data-n="1"] .quote-preview-row { min-height: 72px; }
.quote-preview-board[data-n="3"] .quote-preview-row,
.quote-preview-board[data-n="4"] .quote-preview-row {
  grid-template-columns: 72px minmax(0, 1fr) 48px 52px 88px;
}
.quote-preview-board[data-ext="0"] .quote-preview-ext { visibility: hidden; }
.quote-preview-row:last-child { border-bottom: 0; }
.quote-preview-ident { display: grid; gap: 2px; min-width: 0; }
.quote-preview-ticker {
  font: 600 13px Montserrat, sans-serif;
  color: #142033;
}
.quote-preview-name {
  font-size: 12px;
  color: #5c6b7a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quote-preview-last { display: grid; justify-items: end; gap: 2px; }
.quote-preview-price {
  font: 600 16px Montserrat, sans-serif;
  color: #142033;
}
.quote-preview-change { font: 500 12px Montserrat, sans-serif; }
.quote-board-preview[data-color="green_up"] .quote-preview-change.is-up { color: #1b8a4a; }
.quote-board-preview[data-color="green_up"] .quote-preview-change.is-down { color: #c62828; }
.quote-board-preview[data-color="red_up"] .quote-preview-change.is-up { color: #c62828; }
.quote-board-preview[data-color="red_up"] .quote-preview-change.is-down { color: #1b8a4a; }
.quote-preview-ext {
  display: grid;
  gap: 2px;
  font-size: 11px;
  color: #5c6b7a;
}
.quote-preview-session { font-weight: 700; color: #142033; }
.quote-preview-stats {
  display: grid;
  justify-items: end;
  font: 500 11px Montserrat, sans-serif;
  color: #5c6b7a;
}
.quote-preview-spark {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, #c5d0da, #1b8a4a 55%, #c62828);
}
.quote-preview-board[data-n="3"] .quote-preview-spark,
.quote-preview-board[data-n="4"] .quote-preview-spark {
  grid-column: 5;
}
.quote-preview-board[data-n="1"] .quote-preview-spark,
.quote-preview-board[data-n="2"] .quote-preview-spark {
  grid-column: 1 / -1;
}
.route-editor {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #fafbfc;
}
.route-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.route-summary-button {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  min-height: 0;
  text-align: left;
  display: grid;
  gap: 2px;
  flex: 1;
}
.route-summary-text {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.enabled-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.route-fields {
  display: grid;
  gap: 10px;
}
.route-editor.is-empty .route-toolbar,
.route-editor.is-empty .route-fields,
.route-editor:not(.is-empty) .route-add,
.route-editor:not(.is-open) .route-fields {
  display: none;
}
.route-editor.is-empty .route-add {
  width: 100%;
}

.route-stop-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
}

.route-stop-hint {
  font-size: 0.78rem;
  font-weight: 500;
  color: #7a5b20;
  background: #fff6e5;
  border: 1px solid #efd7a5;
  border-radius: 999px;
  padding: 2px 9px;
  line-height: 1.35;
}

.route-stop-hint[hidden] {
  display: none;
}

.sticky-save {
  display: grid;
  gap: 6px;
  padding-top: 4px;
}
.sticky-save .button {
  width: 100%;
}
.sticky-save.is-dirty .button.primary {
  box-shadow: 0 0 0 2px rgb(11 110 153 / 25%);
}

.toast-region {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 8px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 24px));
}
.toast {
  padding: 10px 12px;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  font-size: 0.9rem;
}
.toast.error { background: var(--danger); }

.doc-page {
  max-width: 42rem;
  margin: 0 auto;
  padding: 20px 18px 48px;
}
.doc-page header {
  margin-bottom: 20px;
}
.doc-page h1 {
  margin: 6px 0 8px;
  font-size: 1.55rem;
}
.doc-page h2 {
  margin: 28px 0 8px;
  font-size: 1.15rem;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.doc-page h3 {
  margin: 16px 0 6px;
  font-size: 1rem;
}
.doc-page p, .doc-page li {
  line-height: 1.55;
}
.doc-page ol, .doc-page ul {
  padding-left: 1.25em;
}
.doc-page table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 8px 0 16px;
}
.doc-page th, .doc-page td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.doc-page th {
  width: 34%;
  background: #eef3f6;
}
.doc-page nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 12px 0 4px;
  font-size: 0.92rem;
}
.doc-page nav a {
  color: var(--accent);
}
.doc-banner {
  background: #fff6e8;
  border: 1px solid #edc98a;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.92rem;
}
.doc-foot {
  margin-top: 32px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.doc-page .lede {
  margin: 0 0 12px;
  font-size: 1rem;
  line-height: 1.5;
}
.help-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: help-step;
  display: grid;
  gap: 10px;
}
.help-steps > li {
  counter-increment: help-step;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px 12px 48px;
  position: relative;
}
.help-steps > li::before {
  content: counter(help-step);
  position: absolute;
  left: 12px;
  top: 12px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.help-steps strong.label {
  display: inline;
  font-weight: 700;
}
.swipe-map {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}
.swipe-map .row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.swipe-map .screen {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 8px;
  background: #eef3f6;
  font-weight: 700;
}
.swipe-map .row + .row {
  margin-top: 2px;
}
.swipe-map .note {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.help-split {
  display: grid;
  gap: 10px;
}
@media (min-width: 640px) {
  .help-split {
    grid-template-columns: 1fr 1fr;
  }
}
.help-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.help-card h3 {
  margin: 0 0 8px;
  border: 0;
  padding: 0;
}
.help-faq {
  display: grid;
  gap: 8px;
  margin: 8px 0 16px;
}
.help-faq details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.help-faq summary {
  cursor: pointer;
  font-weight: 700;
}
.help-faq details p {
  margin: 8px 0 0;
}
.doc-page kbd, .doc-page .ui {
  font-family: inherit;
  font-weight: 700;
  background: #eef3f6;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 6px;
}

@media (max-width: 560px) {
  .settings-grid,
  .quote-fields { grid-template-columns: 1fr; }
  .status-facts { grid-template-columns: 1fr 1fr; }
  .theme-picker { grid-template-columns: repeat(2, 1fr); }
  .content.has-device {
    padding-bottom: 108px;
  }
  .sticky-save {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgb(244 246 248 / 96%);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
  }
  .toast-region {
    bottom: 96px;
  }
}
