:root {
  --paper: #f3efe6;
  --card: #fffcf8;
  --ink: #1a2332;
  --muted: #5e6876;
  --line: #e4ddd2;
  --teal: #0e6b66;
  --teal-deep: #0a524e;
  --open: #157a45;
  --open-soft: #e7f6ee;
  --gold: #8a5a12;
  --danger: #9d3b32;
  --danger-line: #efd2cf;
  --shadow: 0 16px 40px rgba(36, 28, 18, 0.08);
  --radius: 18px;
  --header: rgba(255, 252, 248, 0.92);
  --field: #fff;
  --nav-bg: var(--ink);
  --nav-fg: #fff;
  --closed: #d9d3c8;
  --dot: #e7e1d8;
  --dot-border: #d5cec3;
  --tag: #f3efe6;
  --hover-line: #cfc6b8;
  --toast-fg: #fff;
}

html[data-theme="light"] { color-scheme: light; }

/* Dark mode redefines the same tokens. The navigation pill and the toast text invert with the ink. */
html[data-theme="dark"] {
  --paper: #10141a;
  --card: #1b222c;
  --ink: #f4efe6;
  --muted: #a9b2be;
  --line: #313a48;
  --teal: #3cbfb6;
  --teal-deep: #9ae6df;
  --open: #3dbe78;
  --open-soft: rgba(61, 190, 120, 0.18);
  --gold: #e4b15c;
  --danger: #f0a39c;
  --danger-line: #5c3330;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  --header: rgba(16, 20, 26, 0.92);
  --field: #141a22;
  --nav-bg: #f4efe6;
  --nav-fg: #12161c;
  --closed: #3c4554;
  --dot: #2a3340;
  --dot-border: #4a5566;
  --tag: #2a3340;
  --hover-line: #526070;
  --toast-fg: #12161c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(14, 107, 102, 0.08), transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
}

a { color: var(--teal-deep); }

button, input, select { font: inherit; }

.top {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 18px 28px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-width: 180px;
}
.mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background:
    linear-gradient(160deg, #149188, var(--teal-deep));
  box-shadow: inset 0 0 0 6px rgba(255, 252, 248, 0.18);
}
.brand strong {
  display: block;
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.brand em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
}

nav { display: flex; gap: 6px; }
nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
}
nav a[aria-current="page"] {
  background: var(--nav-bg);
  color: var(--nav-fg);
}

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.status-line { margin: 0; color: var(--muted); font-size: 13px; max-width: 320px; text-align: right; }

.btn {
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  background: var(--card);
}
.btn:hover { border-color: var(--hover-line); }
.lang-menu { position: relative; }
.btn.lang {
  min-width: 64px;
  height: 40px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.btn.lang[aria-expanded="true"] svg { transform: rotate(180deg); }
.lang-list {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 30;
  margin: 0;
  padding: 6px;
  min-width: 180px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
/* The menu aligns to the right edge when the button is too close to the window edge. */
.lang-list.flip { left: auto; right: 0; }
.lang-list[hidden] { display: none; }
.lang-list button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
}
.lang-list button:hover, .lang-list button:focus-visible { background: var(--tag); outline: none; }
.lang-list button[aria-selected="true"] { color: var(--teal-deep); font-weight: 650; }
.lang-list .tick { width: 16px; height: 16px; flex: none; visibility: hidden; }
.lang-list button[aria-selected="true"] .tick { visibility: visible; }
.btn.theme { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; }
.btn.theme .sun { display: none; }
html[data-theme="dark"] .btn.theme .moon { display: none; }
html[data-theme="dark"] .btn.theme .sun { display: block; }
.btn.primary { background: var(--teal); color: white; border-color: var(--teal); }
.btn.primary:hover { background: var(--teal-deep); }
.btn.quiet { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.busy { opacity: 1; background: var(--teal); color: white; border-color: var(--teal); cursor: progress; }
.btn.done { opacity: 1; background: #1c7c4a; color: white; border-color: #1c7c4a; cursor: default; }
.btn.small { padding: 6px 10px; font-size: 13px; }

main { width: min(1180px, calc(100% - 36px)); margin: 28px auto 48px; }

.page-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-end; margin-bottom: 18px; }
.page-head h1 {
  font-family: "Iowan Old Style", Palatino, serif;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}
.lede { margin: 0; color: var(--muted); max-width: 62ch; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel > h2 {
  font-family: "Iowan Old Style", Palatino, serif;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
}

.legend { display: flex; gap: 16px; color: var(--muted); font-size: 13px; align-items: center; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.swatch.open { background: var(--open); }
.swatch.closed { background: var(--closed); }

.board-wrap { overflow: auto; margin-top: 8px; }
table.board { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; }
table.board th, table.board td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); }
table.board th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--card);
}
/* Route column frozen together with the header: this header cell sits above the others. */
.route-col { text-align: left !important; position: sticky; left: 0; background: var(--card); min-width: 180px; z-index: 1; }
th.route-col { z-index: 2; }
td.route-col { font-weight: 650; }

.cell { display: flex; justify-content: center; gap: 8px; }
.slot { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
/* Board dot. Green means an open seat; the gold ring means a watch already covers this slot. */
.dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--dot-border);
  background: var(--dot);
  padding: 0;
  cursor: pointer;
}
.dot.on { background: var(--open); border-color: #0f6a3d; box-shadow: 0 0 0 4px var(--open-soft); }
.dot.watched { outline: 2px solid var(--gold); outline-offset: 2px; }
.dot:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

.follow-band {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}
.follow-band .btn { flex: none; }

.form-grid { display: grid; grid-template-columns: 1.4fr 0.8fr 0.9fr; gap: 12px; min-width: 0; }
label.field, div.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.field[hidden], .check[hidden] { display: none; }
label.field input, label.field select, div.field input {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
}
.secret { position: relative; display: block; }
.secret input { width: 100%; padding-right: 44px; }
.peek {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.peek svg { width: 20px; height: 20px; }
.peek:hover, .peek[aria-pressed="true"] { color: var(--ink); }
.generate { align-self: flex-start; }
.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: var(--ink);
  font-size: 14px;
  margin: 2px 0 0;
}
.check input { margin-top: 2px; accent-color: var(--teal); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
.field .form-error { margin: 0; }
.choice { display: flex; gap: 8px; }
.choice label {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  background: var(--field);
  cursor: pointer;
}
.choice input { accent-color: var(--teal); }
.choice label:has(input:checked),
.channel-pick label:has(input:checked) {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
  background: var(--open-soft);
}
.span-all { grid-column: 1 / -1; }
fieldset.span-all {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}
fieldset.span-all legend {
  padding: 0;
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}
.channel-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 0; }
.channel-pick label {
  min-width: 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
}
.channel-pick strong { display: block; }
.channel-pick label span span { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.channel-pick input { accent-color: var(--teal); margin-top: 3px; }
.form-grid .form-actions,
.form-grid .form-error { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; align-items: end; }
.form-error { color: var(--danger); margin: 8px 0 0; }
.form-status { color: #1c7c4a; margin: 8px 0 0; font-weight: 650; }
.hint { color: var(--muted); margin: 0; }
a.btn { display: inline-block; text-decoration: none; }
input.token { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
/* Outside editing, the disabled field reads as a sentence, not as a grayed-out input. */
label.field input:disabled {
  opacity: 1;
  color: var(--ink);
  background: transparent;
  border-color: transparent;
  padding-left: 0;
  font-weight: 650;
  cursor: default;
}
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.watch {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.watch:last-child { border-bottom: 0; }
.watch h2 { margin: 0 0 4px; font-size: 18px; }
.watch p { margin: 0; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; border-radius: 999px; padding: 3px 8px; background: var(--tag); color: var(--ink); }
.row-actions { display: flex; gap: 8px; }

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.settings h2 { font-family: "Iowan Old Style", Palatino, serif; font-size: 28px; margin: 0 0 6px; }
.settings .stack { display: flex; flex-direction: column; gap: 12px; }

.tip {
  position: fixed;
  z-index: 40;
  width: 260px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
}
/* Invisible bridge between the dot and the bubble: the pointer can cross without the hover closing. */
.tip::before {
  content: "";
  position: absolute;
  left: -12px;
  right: -12px;
  height: 18px;
}
.tip[data-side="below"]::before { top: -18px; }
.tip[data-side="above"]::before { bottom: -18px; }
.tip[hidden] { display: none; }
.tip .kicker { margin: 0; color: var(--teal); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.tip h3 { margin: 4px 0; font-size: 18px; }
.tip .when { margin: 0; color: var(--muted); font-size: 13px; }
.tip .price { margin: 10px 0 0; font-family: "Iowan Old Style", Palatino, serif; font-size: 28px; }
.tip .missing { margin: 10px 0 0; color: var(--muted); }
.tip .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tip a.book, .tip a.follow {
  display: inline-block;
  text-decoration: none;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
}
.tip a.book { background: var(--teal); color: white; }
.tip a.follow { border: 1px solid var(--line); color: var(--ink); background: var(--card); }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--toast-fg);
  border-radius: 999px;
  padding: 10px 16px;
  z-index: 50;
}
.toast[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(16, 20, 26, 0.46);
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(460px, 100%);
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}
.modal-card h2 {
  font-family: "Iowan Old Style", Palatino, serif;
  font-size: 28px;
  font-weight: 600;
  margin: 4px 0 12px;
}
.modal-card .kicker { margin: 0; color: var(--teal); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.modal-card ol { margin: 0 0 16px; padding-left: 18px; }
.modal-card li { margin: 0 0 8px; }
.modal-card li:last-child { margin-bottom: 0; }
.linkish { background: none; border: 0; padding: 0; color: var(--teal-deep); cursor: pointer; text-decoration: underline; font: inherit; }

.empty { padding: 28px 8px; color: var(--muted); }
/* Without a session, the script sets data-auth="out" and removes the navigation, the status, and the check button. */
body[data-auth="out"] #nav,
body[data-auth="out"] #status-line,
body[data-auth="out"] #btn-check { display: none; }

.login { width: min(420px, 100%); margin: 10vh auto 0; }
.login h1 {
  font-family: "Iowan Old Style", Palatino, serif;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
}
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.login .switch { margin: 16px 0 0; }
.login .btn.primary { align-self: flex-start; }

footer { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 16px 28px; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; gap: 12px; padding: 14px; }
  .top-actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .status-line { text-align: left; }
  .settings, .form-grid { grid-template-columns: 1fr; }
  .follow-band { flex-direction: column; align-items: flex-start; }
  .channel-pick { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 32px; }
  .watch { grid-template-columns: 1fr; }
}
