/* Subway sign config — mobile-first, dark by default, light when asked. */

:root {
  color-scheme: dark light;

  --bg: #0b0d10;
  --bg-elev: #14181d;
  --bg-input: #1b2027;
  --line: #262d36;
  --text: #e8edf3;
  --text-dim: #9aa6b4;
  --accent: #4c8dff;
  --accent-ink: #ffffff;
  --danger: #ff5c5c;
  --ok: #35c46b;

  --radius: 14px;
  --radius-sm: 10px;
  --pad: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --bg-elev: #ffffff;
    --bg-input: #f0f3f7;
    --line: #dde3ea;
    --text: #131820;
    --text-dim: #5d6a7a;
    --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 8px 24px rgb(16 24 40 / 0.06);
  }
}

* { box-sizing: border-box; }

/* Cards and rows set display, so [hidden] needs to win. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 5px;
}

/* ── Top bar ─────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px var(--pad);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 9px;
}

.bullet {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.85rem;
  font-weight: 700;
}

.conn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-dim);
  min-width: 0;
}

.conn .icon {
  display: grid;
  place-items: center;
  padding: 4px 6px;
  min-height: 28px;
}

.conn-serial {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}

/* ── Layout ──────────────────────────────────────────────────── */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--pad);
}

#editor {
  display: flex;
  flex-direction: column;
  gap: var(--pad);
  margin: 0;
}

#editor[hidden] { display: none; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.count { font-size: 0.8rem; color: var(--text-dim); }

.hint {
  margin: -6px 0 0;
  font-size: 0.83rem;
  color: var(--text-dim);
}

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

.spacer { height: 4px; }

/* ── Fields ──────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.label, legend.label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0;
}

.label output { text-transform: none; color: var(--text); font-weight: 600; }

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 44px;
  appearance: none;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.swatch-select {
  padding-left: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%),
                    radial-gradient(circle at 17px 50%, var(--swatch, #888) 7px, transparent 7px);
  background-position: right 16px center, right 11px center, left center;
  background-size: 5px 5px, 5px 5px, auto;
  background-repeat: no-repeat;
}

.input-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.input-group .unit {
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 0.85rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  min-height: 32px;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

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

/* ── Buttons ─────────────────────────────────────────────────── */

button {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 12px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s, transform 0.05s;
}

button:active:not(:disabled) { transform: scale(0.99); }
button:disabled { opacity: 0.45; cursor: default; }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, white); }

.ghost {
  background: var(--bg-input);
  color: var(--text);
  border-color: var(--line);
}

.ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--bg-input) 80%, var(--text) 8%); }

.block { width: 100%; }

.small { padding: 8px 12px; min-height: 0; font-size: 0.85rem; }

.link {
  background: none;
  border: 0;
  padding: 4px;
  min-height: 0;
  color: var(--accent);
  font-size: 0.82rem;
}

.icon {
  background: none;
  border: 0;
  color: var(--text-dim);
  padding: 6px 8px;
  min-height: 32px;
  line-height: 1;
  font-size: 0.95rem;
}

.icon:hover:not(:disabled) { color: var(--text); }
.icon.danger:hover:not(:disabled) { color: var(--danger); }

/* ── Segmented control ───────────────────────────────────────── */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.seg {
  background: none;
  border: 0;
  color: var(--text-dim);
  padding: 8px 4px;
  min-height: 38px;
  font-size: 0.82rem;
  border-radius: 7px;
}

.seg[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ── Stops ───────────────────────────────────────────────────── */

.stops {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stops.empty::before {
  content: "No stops yet — add up to eight.";
  color: var(--text-dim);
  font-size: 0.87rem;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
}

.stop {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-input) 55%, transparent);
  overflow: hidden;
}

.stop-head {
  display: flex;
  align-items: center;
  padding-right: 6px;
}

.stop-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 10px 4px 10px 12px;
  color: inherit;
  text-align: left;
}

.chevron {
  flex: none;
  width: 7px;
  height: 7px;
  margin: 0 6px 4px 0;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.stop.collapsed .chevron { transform: rotate(-45deg); margin: 0 8px 0 0; }
.stop.collapsed .stop-body { display: none; }

.stop-bullet {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  background: #888;
  color: #000;
}

.stop-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

.stop-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 2px 12px 14px;
}

@media (min-width: 560px) {
  /* Line pairs with station, the printed name with the direction. */
  .stop-body { grid-template-columns: 1fr 1fr; }
}

/* ── Meta ────────────────────────────────────────────────────── */

.meta dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.meta dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
}

.meta dd { margin: 2px 0 0; font-size: 0.92rem; font-weight: 600; }

/* ── Save bar ────────────────────────────────────────────────── */

.savebar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.savebar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 10px var(--pad);
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-status {
  font-size: 0.85rem;
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
}

.savebar.dirty .save-status { color: var(--text); }

.save-actions {
  display: flex;
  gap: 8px;
}

/* ── Toast ───────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(92vw, 480px);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: rise 0.18s ease-out;
}

.toast.error { border-left-color: var(--danger); }

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
