:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --fg: #0f172a;
  --muted: #64748b;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --danger: #b91c1c;
  --tc: #1d4ed8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
* { overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top { padding: 12px 16px 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.search { position: relative; }
.search input {
  width: 100%;
  height: 56px;
  padding: 0 52px 0 18px;
  font-size: 22px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--fg);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { display: none; }
#clear {
  position: absolute; right: 4px; top: 4px; width: 48px; height: 48px;
  border: 0; background: none; font-size: 28px; color: var(--muted);
}
.toolbar { min-width: 0; display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 320px; }
.actions { display: flex; gap: 8px; }
.chips button, .actions button {
  min-height: 44px; padding: 0 16px; border-radius: 12px; font-size: 16px; font-weight: 600;
  border: 1.5px solid var(--line); background: var(--card);
}
.actions button { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.split {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px;
  padding: 4px 16px 16px;
}
#results, #detail { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.listwrap { position: relative; min-height: 0; display: flex; gap: 4px; }
#results { position: relative; flex: 1; min-width: 0; display: grid; gap: 8px; align-content: start; }
.letter {
  position: sticky; top: 0; z-index: 1; padding: 4px 10px; font-size: 14px; font-weight: 800;
  color: var(--accent); background: var(--bg); letter-spacing: .06em;
}
#rail {
  flex: none; width: 36px; display: flex; flex-direction: column; justify-content: space-between;
  padding: 2px 0; touch-action: none; user-select: none; -webkit-user-select: none;
}
#rail[hidden] { display: none; }
#rail span { text-align: center; font-size: 12px; line-height: 1; font-weight: 800; color: var(--accent); }
#rail span.off { color: #cbd5e1; font-weight: 600; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 68px; padding: 10px 14px; text-align: left;
  background: var(--card); border: 2px solid transparent; border-radius: 14px;
}
.row[aria-current="true"] { border-color: var(--accent); }
.row .name { font-size: 20px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.row .sub { font-size: 14px; color: var(--muted); }
.chip {
  flex: none; min-width: 76px; padding: 6px 10px; border-radius: 10px; text-align: center;
  font-weight: 800; font-size: 18px; color: #fff; background: var(--tc);
}
.chip.none { background: none; color: var(--muted); border: 1.5px dashed var(--muted); font-weight: 600; font-size: 14px; }
.hint { color: var(--muted); padding: 24px 8px; text-align: center; }
.hint strong { display: block; color: var(--fg); font-size: 19px; margin-bottom: 4px; }

.card { background: var(--card); border-radius: 18px; padding: 18px; display: grid; gap: 14px; align-content: start; }
.back { display: none; border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 17px; min-height: 44px; padding: 0; justify-self: start; }
.card h2 { margin: 0; font-size: 30px; line-height: 1.15; overflow-wrap: anywhere; }
.meta { margin: 2px 0 0; color: var(--muted); }
.where { display: grid; grid-template-columns: auto 1fr; gap: 12px; }
.where > div { border-radius: 16px; padding: 12px 18px; text-align: center; }
.where small { display: block; font-size: 13px; letter-spacing: .08em; font-weight: 700; opacity: .85; }
.where b { display: block; line-height: 1.05; font-weight: 800; font-variant-numeric: tabular-nums; }
.where .tbl { background: var(--tc); color: #fff; min-width: 120px; }
.where .tbl b { font-size: 76px; }
.where .seat { background: var(--accent-soft); color: var(--tc); }
.where .seat b { font-size: 52px; }
.where .seat.none b { font-size: 24px; margin-top: 12px; }
.dir { margin: 0; font-size: 19px; font-weight: 600; }
.viz { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; align-items: start; }
.viz figure { margin: 0; display: grid; gap: 6px; justify-items: center; }
.viz figcaption { font-size: 13px; color: var(--muted); }
.tdiagram { width: 100%; max-height: 52dvh; }
.mapsvg { width: 100%; height: auto; border-radius: 12px; background: #f8fafc; border: 1px solid var(--line); }
.tdiagram { max-width: 300px; }
.notable { margin: 0; padding: 14px; border: 1.5px dashed var(--muted); border-radius: 14px; color: var(--muted); }

dialog {
  width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 20px; background: var(--card); color: var(--fg);
  overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 6px 20px; }
.dlg-head h2 { margin: 0; font-size: 22px; }
.dlg-close { width: 48px; height: 48px; border: 0; background: none; font-size: 30px; color: var(--muted); }
#dlg-body { padding: 4px 20px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span, .block > h3 { font-size: 14px; font-weight: 700; color: var(--muted); letter-spacing: .02em; margin: 0; }
.block { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 18px; display: grid; gap: 10px; }
select, input[type="text"], input[type="number"], textarea {
  width: 100%; min-height: 48px; padding: 8px 12px; font: inherit; font-size: 17px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--fg);
}
textarea { min-height: 150px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; resize: vertical; }
.check { display: flex; gap: 12px; align-items: center; min-height: 48px; font-size: 17px; }
.check input { width: 24px; height: 24px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { min-height: 48px; padding: 0 18px; border-radius: 12px; font-weight: 700; border: 1.5px solid var(--line); background: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.tgrid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: center; }
.tgrid .th { font-size: 13px; font-weight: 700; color: var(--muted); }
.report { font-size: 15px; color: var(--muted); }
.report ul { margin: 6px 0 0; padding-left: 20px; max-height: 160px; overflow: auto; }
.report .ok { color: #15803d; font-weight: 700; }
.report .warn { color: var(--danger); font-weight: 700; }
.mapnote { margin: 10px 0 0; font-size: 18px; font-weight: 600; }
.mapchips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.mapchips button { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; }
.mapchips button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.version { color: var(--muted); font-size: 13px; }

@media (max-width: 699px) {
  .top { padding: 10px 12px 6px; }
  .search input { height: 52px; font-size: 20px; }
  .split { grid-template-columns: 1fr; padding: 4px 12px 12px; }
  #detail { display: none; }
  .show-detail .listwrap { display: none; }
  .show-detail #detail { display: block; }
  .back { display: inline-flex; align-items: center; }
  .where .tbl { min-width: 96px; }
  .where .tbl b { font-size: 64px; }
  .where .seat b { font-size: 40px; }
  .card h2 { font-size: 26px; }
  .chips button { padding: 0 12px; font-size: 15px; }
  .chips { flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
  .chips::-webkit-scrollbar { display: none; }
  .chips button { flex: none; white-space: nowrap; }
  .actions { width: 100%; }
  .actions button { flex: 1; }
  .show-detail .top .toolbar { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .row, .btn, .chips button { transition: transform .08s ease; }
  .row:active, .btn:active, .chips button:active { transform: scale(.98); }
}

.near { display: grid; gap: 8px; }
.near h3, .mates summary { margin: 0; font-size: 14px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.row.small { min-height: 58px; background: var(--bg); }
.row.small .name { font-size: 18px; }
.mates { display: grid; gap: 8px; }
.mates summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.mates[open] summary { margin-bottom: 8px; }
.mates > .row { margin-bottom: 8px; }
