:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #5b6577;
  --faint: #8a94a6;
  --gear: #a7aebb;
  --line: #e4dfd6;
  --accent: #073590;
  --badge-bg: #073590;
  --badge-text: #f1c933;
  --soon-bg: #ffe08a;
  --soon-text: #5a4300;
  --now-bg: #2e7d32;
  --now-text: #ffffff;
  --past-bg: #d9d4cb;
  --past-text: #4a5262;
  --enroute-bg: #dbe7f6;
  --enroute-text: #073590;
  --none-bg: #e9e5de;
  --none-text: #5b6577;
  --error: #b3261e;
  --overlay: rgba(29, 36, 51, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Phone portrait sizes; landscape overrides below. */
  --pad: 16px;
  --gap: clamp(8px, 1.5vh, 18px);
  --fs-head: clamp(20px, 6.6vw, 32px);
  --fs-city: clamp(36px, min(14vw, 7.5vh), 72px);
  --fs-time: clamp(16px, min(5vw, 2.6vh), 24px);
  --fs-label: clamp(13px, min(3.8vw, 1.9vh), 18px);
  --fs-value: clamp(18px, min(6vw, 3vh), 30px);
  --fs-empty: clamp(24px, 7vw, 40px);
  --logo: clamp(40px, 11vw, 56px);
  --photo-h: 17vh;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--pad) var(--pad) 56px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto 1fr auto;
  grid-template-areas: "status" "photo" "airline" "board" "cells";
  gap: var(--gap);
  transition: opacity .4s;
}

body.tone-now::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 10px var(--now-bg);
}
body.tone-past .screen { opacity: .8; }
body.tone-none .screen,
body.tone-notfound .screen {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr;
  grid-template-areas: "status";
  align-items: center;
  justify-items: center;
}
body.tone-none .status,
body.tone-notfound .status { align-self: center; }

.status { grid-area: status; min-width: 0; max-width: 100%; }
.pill {
  display: inline-block;
  max-width: 100%;
  padding: .25em .7em;
  border-radius: 999px;
  font-weight: 700;
  font-size: var(--fs-head);
  line-height: 1.2;
  background: var(--none-bg);
  color: var(--none-text);
  overflow-wrap: anywhere;
}
body.tone-soon .pill { background: var(--soon-bg); color: var(--soon-text); }
body.tone-now .pill { background: var(--now-bg); color: var(--now-text); }
body.tone-past .pill { background: var(--past-bg); color: var(--past-text); }
body.tone-enroute .pill { background: var(--enroute-bg); color: var(--enroute-text); }
body.tone-none .pill,
body.tone-notfound .pill { font-size: var(--fs-empty); text-align: center; }

.big-auto {
  display: block;
  margin: 1.2em auto 0;
  font: inherit;
  font-size: var(--fs-head);
  font-weight: 700;
  padding: .6em 1.2em;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--surface);
  cursor: pointer;
}
body.tone-notfound .status { text-align: center; }

.photo { grid-area: photo; margin: 0; min-width: 0; }
.photo img {
  display: block;
  width: 100%;
  height: var(--photo-h);
  object-fit: cover;
  border-radius: 12px;
  background: var(--line);
}
.photo figcaption { font-size: 12px; margin-top: 4px; text-align: right; }
.photo a { color: var(--muted); text-decoration: none; }

.airline { grid-area: airline; display: flex; align-items: center; gap: .45em; min-width: 0; font-size: var(--fs-head); }
.logo { width: var(--logo); height: var(--logo); border-radius: 10px; object-fit: contain; background: var(--surface); flex: none; }
.badge {
  width: var(--logo); height: var(--logo); border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--badge-bg); color: var(--badge-text);
  font-weight: 800; font-size: calc(var(--logo) * .32);
}
.airline-name { font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }

.board {
  grid-area: board;
  background: var(--surface);
  border-radius: 16px;
  padding: clamp(14px, 2.4vh, 28px) clamp(16px, 2.4vw, 32px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: space-evenly;
  gap: 8px;
  min-width: 0;
}
.end { min-width: 0; }
.label { font-size: var(--fs-label); color: var(--muted); }
.city { font-size: var(--fs-city); font-weight: 800; line-height: 1.05; overflow-wrap: normal; word-break: normal; }
.time { font-size: var(--fs-time); color: var(--muted); margin-top: .2em; }
.sched { font-size: var(--fs-label); color: var(--faint); }
.plane { font-size: calc(var(--fs-city) * .6); color: var(--faint); transform: rotate(90deg); justify-self: start; line-height: 1; }
.bar { height: clamp(6px, 1vh, 12px); border-radius: 6px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); }

.cells {
  grid-area: cells;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  min-width: 0;
}
.cells div { min-width: 0; }
.cells dt { font-size: var(--fs-label); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.cells dd { margin: 0; font-size: var(--fs-value); font-weight: 700; line-height: 1.15; }
.cells dd span { white-space: nowrap; }

.gear {
  position: fixed;
  right: 8px;
  bottom: 6px;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--gear);
  font-size: 22px;
  cursor: pointer;
}

.settings {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.panel {
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 16px;
}
.panel h2 { margin: 0; font-size: 20px; }
.panel .row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.panel label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 14px; }
.panel input {
  font: inherit;
  font-size: 17px;
  color: var(--text);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
}
.panel button {
  font: inherit;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.panel .error { margin: -4px 0 0; color: var(--error); font-size: 15px; font-weight: 600; }
.panel .actions { display: flex; justify-content: flex-end; gap: 10px; }
.panel .primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }

body.tone-list .screen {
  grid-template-rows: auto 1fr;
  grid-template-areas: "status" "list";
}
.list { grid-area: list; display: grid; gap: calc(var(--gap) * 2); align-content: start; min-width: 0; }
.list h2 { margin: 0 0 .3em; font-size: var(--fs-label); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.list ol { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--gap); }
.list li {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: .6em;
  padding: .45em .6em;
  border-radius: 14px;
  background: var(--surface);
  font-size: var(--fs-value);
}
#list-past li { background: var(--none-bg); color: var(--muted); }
.row-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.row-logo, .row-badge { width: 1.6em; height: 1.6em; border-radius: 8px; object-fit: contain; background: var(--surface); }
.row-badge { display: grid; place-items: center; font-size: .55em; width: 2.9em; height: 2.9em; font-weight: 700; background: var(--badge-bg); color: var(--badge-text); }
.row-text { display: grid; min-width: 0; }
.row-text b, .row-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-text small { font-size: .6em; color: var(--muted); white-space: normal; }

@media (min-width: 700px) and (min-aspect-ratio: 1/1) {
  body.tone-list .screen { grid-template-columns: minmax(0, 1fr); grid-template-areas: "status" "list"; }
  .list { width: min(100%, 1100px); align-content: center; }
  .list li { font-size: clamp(24px, min(3.6vw, 5.6vh), 60px); }
  body.tone-list .status { align-self: start; }
  :root {
    --pad: clamp(20px, 3vh, 36px);
    --gap: clamp(12px, 2.2vh, 26px);
    --fs-head: clamp(26px, min(3.6vw, 5.4vh), 60px);
    --fs-city: clamp(48px, min(11vw, 16vh), 190px);
    --fs-time: clamp(18px, min(2.4vw, 3.6vh), 40px);
    --fs-label: clamp(14px, min(1.5vw, 2.2vh), 24px);
    --fs-value: clamp(22px, min(3.2vw, 4.8vh), 54px);
    --fs-empty: clamp(30px, min(4.4vw, 6.6vh), 72px);
    --logo: clamp(52px, 8vh, 96px);
    --photo-h: clamp(140px, 24vh, 300px);
  }
  .screen {
    padding: var(--pad) calc(var(--pad) + 6px) calc(var(--pad) + 30px);
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "status photo"
      "airline photo"
      "board board"
      "cells cells";
    column-gap: clamp(16px, 2.4vw, 32px);
  }
  .status { align-self: end; }
  .airline { align-self: start; }
  .photo img { width: clamp(220px, 32vw, 520px); }
  .board {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: clamp(12px, 2vw, 28px);
    border-radius: 20px;
  }
  .to { text-align: right; }
  .plane { transform: none; justify-self: center; }
  .bar { grid-column: 1 / 4; }
  .cells { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
