:root {
  --bottom-pad: calc(20px + env(safe-area-inset-bottom));
  --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) 0 env(safe-area-inset-left);
}

.top { display: flex; gap: 8px; align-items: center; min-width: 0; }
.search { position: relative; flex: 1; min-width: 0; }
.search input {
  width: 100%;
  height: 52px;
  padding: 0 48px 0 16px;
  font-size: 20px;
  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: 2px; top: 2px; width: 48px; height: 48px;
  border: 0; background: none; font-size: 28px; color: var(--muted);
}
.tool {
  flex: none; height: 52px; padding: 0 16px; border-radius: 14px; font-size: 16px; font-weight: 700;
  border: 1.5px solid var(--accent); color: var(--accent); background: var(--accent-soft);
}
.tool.icon { width: 52px; padding: 0; font-size: 22px; }

.split {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 16px;
  padding: 12px 16px 0;
}
.left { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
@property --fade-end { syntax: '<length>'; inherits: false; initial-value: 0px; }
#results, #detail {
  overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0;
  --fade-end: 0px;
  transition: --fade-end .2s ease;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - var(--fade-end)), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - var(--fade-end)), transparent);
}
#results.more, #detail.more { --fade-end: 44px; }
#results { padding-bottom: var(--bottom-pad); }
.listwrap { position: relative; flex: 1; min-height: 0; display: flex; gap: 4px; }
#results { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
#results > * { flex: none; }
.letter {
  position: sticky; top: -2px; z-index: 1; padding: 6px 10px 4px; font-size: 14px; font-weight: 800;
  color: var(--accent); background: var(--bg); letter-spacing: .06em;
  box-shadow: 0 -2px 0 var(--bg), 0 2px 0 var(--bg);
}
#rail {
  flex: none; width: 36px; display: flex; flex-direction: column; justify-content: space-between;
  padding: 2px 0 var(--bottom-pad); 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; height: auto; flex: none; 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 .txt { min-width: 0; display: grid; gap: 2px; }
.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 18px 0 0; padding: 20px 20px var(--bottom-pad); display: grid; gap: 16px; align-content: start; min-height: 100%; }
.info { display: grid; gap: 14px; align-content: start; min-width: 0; }
.head, .rest { display: grid; gap: 14px; align-content: start; min-width: 0; }
.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: minmax(0, 2fr) minmax(0, 3fr); 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 { --tile-tbl: 76px; --tile-seat: 52px; }
.where > div { min-width: 0; container-type: inline-size; display: flex; flex-direction: column; justify-content: center; }
.where b { display: block; line-height: 1.05; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.where .tbl { background: var(--tc); color: #fff; }
.where .tbl b { font-size: min(var(--tile-tbl), calc(100cqw / (var(--chars, 1) * 0.8))); }
.where .seat { background: var(--accent-soft); color: var(--tc); }
.where .seat b { font-size: min(var(--tile-seat), calc(100cqw / (var(--chars, 1) * 0.8))); }
.where .seat.none { --tile-seat: 34px; }
.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 (min-width: 1080px) {
  .split { grid-template-columns: minmax(330px, 380px) minmax(0, 1fr); }
  #detail { overflow: hidden; overflow: clip; -webkit-mask-image: none; mask-image: none; }
  .card { height: 100%; min-height: 0; padding-bottom: 0; grid-template-columns: minmax(0, 1fr) clamp(250px, 32%, 340px); grid-template-rows: minmax(0, 1fr); column-gap: 24px; }
  .card .info { grid-column: 1; grid-row: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; overflow: hidden; }
  .info .head { flex: none; }
  .info .rest { flex: 1; min-height: 0; overflow-y: auto; align-content: start; margin: 0 -20px; padding: 0 20px var(--bottom-pad); }
  .card .viz { padding-bottom: var(--bottom-pad); }
  .card .viz { grid-column: 2; grid-row: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; row-gap: 10px; justify-items: center; }
  .viz figure { min-width: 0; min-height: 0; }
  .viz figure:first-child { width: 100%; height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; justify-items: center; row-gap: 4px; }
  .viz figure:first-child .tdiagram { height: 100%; width: 100%; max-width: none; max-height: none; }
  .viz .mapfig { width: 100%; }
  .viz .mapfig .mapsvg { height: min(25dvh, 250px); width: auto; max-width: 100%; }
  .viz figcaption { font-size: 12px; line-height: 1.3; text-align: center; }
  .where { --tile-tbl: 96px; --tile-seat: 64px; }
  .card h2 { font-size: 34px; }
  .dir { font-size: 20px; }
}
@media (max-width: 699px) {
  .split { grid-template-columns: minmax(0, 1fr); padding: 10px 12px 0; }
  .left { display: contents; }
  .top { grid-row: 1; }
  .listwrap { grid-row: 2; }
  .split { grid-template-rows: auto minmax(0, 1fr); }
  #detail { display: none; grid-row: 2; }
  .show-detail .listwrap { display: none; }
  .show-detail #detail { display: block; }
  .back { display: inline-flex; align-items: center; }
  .where { --tile-tbl: 64px; --tile-seat: 40px; }
  .card h2 { font-size: 26px; }
}
@media (prefers-reduced-motion: no-preference) {
  .row, .btn { transition: transform .08s ease; }
  .row:active, .btn:active { transform: scale(.98); }
}

.near { display: flex; flex-direction: column; gap: 8px; }
.near > * { flex: none; }
/* The 2px overlap (top: -2px plus the shadow) hides the hairline iOS lets rows show beside a sticky heading. */
.near h3 { position: sticky; top: -2px; z-index: 1; background: var(--card); padding: 8px 0 8px; box-shadow: 0 -2px 0 var(--card), 0 2px 0 var(--card); }
.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: flex; flex-direction: column; gap: 8px; }
.mates > * { flex: none; }
.mates summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.mates[open] summary { margin-bottom: 8px; }
.mates > .row { margin-bottom: 8px; }

#tip {
  position: fixed; z-index: 1000; pointer-events: none; max-width: 260px;
  padding: 10px 14px; border-radius: 12px; background: #0f172a; color: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .35);
}
#tip[hidden] { display: none; }
#tip b { display: block; font-size: 18px; line-height: 1.25; }
#tip span { display: block; font-size: 14px; opacity: .85; line-height: 1.35; }
.mapsvg, .tdiagram { touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
dialog .mapsvg, dialog .tdiagram { touch-action: none; }
@media (min-width: 1080px) { .mapsvg, .tdiagram, .viz figure { touch-action: none; } }
.seat.probe > rect, .seat.probe > circle { stroke: #ef4444; stroke-width: 3.5; }
.seat.mate > rect, .seat.mate > circle { stroke: #2563eb; stroke-width: 3; }

.mapfig { cursor: pointer; border-radius: 12px; }
.mapfig:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.mapfig .mapsvg { pointer-events: none; }
