:root {
  color-scheme: light;
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
  color: #172d29;
  background: #e9eee7;
  --ink: #172d29;
  --muted: #465f54;
  --line: #c8d5c9;
  --paper: #f9fbf5;
  --yellow: #f9cf65;
  --mono: "Cascadia Code", "Consolas", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background-image: linear-gradient(90deg, #203a2912 1px, transparent 1px), linear-gradient(#203a2912 1px, transparent 1px);
  background-size: 32px 32px;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
button:focus-visible, input:focus-visible { outline: 3px solid #2c8769; outline-offset: 3px; }
[hidden] { display: none !important; }

.relay { width: min(100% - 2rem, 960px); margin: 0 auto; padding: clamp(.75rem, 3vw, 2.25rem) 0 2rem; }
.departure-board { overflow: hidden; border-radius: 18px; background: var(--ink); color: white; box-shadow: 0 10px 26px #172d291f; }
.departure-main { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: clamp(.9rem, 3vw, 1.35rem); }
.brand { display: flex; align-items: center; gap: .9rem; }
.brand h1 { margin: 0; font-size: clamp(1.9rem, 4.4vw, 2.65rem); line-height: 1; letter-spacing: -.055em; }
.brand p { margin: .45rem 0 0; color: #d1e0d3; }
.brand-mark { display: grid; gap: 5px; place-content: center; flex: 0 0 3.2rem; height: 3.2rem; border-radius: .85rem; background: var(--yellow); }
.brand-mark span { width: 23px; height: 3px; background: var(--ink); border-radius: 1rem; position: relative; }
.brand-mark span::before { content: ""; position: absolute; left: 4px; top: -2px; height: 7px; width: 5px; border-radius: 1rem; background: var(--ink); }
.brand-mark span:nth-child(2)::before { left: 14px; }

.mode { display: flex; flex: 0 0 auto; gap: .25rem; padding: .3rem; border: 1px solid #62766c; border-radius: .75rem; }
.mode button { min-height: 2.45rem; padding: 0 .75rem; border: 0; border-radius: .48rem; color: #eff6eb; background: transparent; font-weight: 650; }
.mode button:hover { background: #395348; }
.mode button[aria-pressed="true"] { color: var(--ink); background: var(--yellow); }
.mode button:focus-visible, .departure-detail button:focus-visible { outline-color: var(--yellow); }
.departure-detail { display: flex; justify-content: space-between; align-items: center; gap: .6rem; min-height: 2.95rem; padding: .35rem clamp(1.1rem, 4vw, 1.9rem); border-top: 1px solid #4e6658; background: #223e34; color: #ecf5e8; font-size: .875rem; }
.departure-detail button { border: 0; padding: .35rem .55rem; border-radius: .35rem; color: var(--yellow); background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.departure-detail button:hover { background: #3c5547; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 1rem; margin-top: .85rem; align-items: start; }
.game-panel, .keyboard-panel, .rule-panel { border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: 0 5px 16px #172d2909; }
.game-panel { padding: clamp(1rem, 3.3vw, 1.8rem); }
.endpoints { display: flex; justify-content: space-between; align-items: end; gap: clamp(.35rem, 1.65vw, .9rem); }
.endpoint { flex: 0 1 auto; min-width: 0; }
.endpoint > span { display: block; color: var(--muted); font-size: .875rem; font-weight: 700; margin-bottom: .45rem; }
.endpoint-destination > span { text-align: right; }
.flap-word { display: flex; gap: clamp(2px, .55vw, 5px); }
.flap-letter { display: grid; place-items: center; width: clamp(1.45rem, 4.85vw, 2.85rem); height: clamp(2rem, 6.6vw, 3.7rem); border: 1px solid #162b25; border-radius: .37rem; background: linear-gradient(0deg, #294338 49%, #142b24 50%, #21392f 52%); color: #fbf9ed; font: 700 clamp(1.08rem, 3.35vw, 2rem)/1 var(--mono); box-shadow: inset 0 -2px #132d2380; }
.endpoint-destination .flap-letter { border-color: #9c721f; background: linear-gradient(0deg, #ffd879 49%, #bf963d 50%, #ffe39d 52%); color: #302408; box-shadow: inset 0 -2px #a781263c; }
.route-line { position: relative; min-width: .6rem; align-self: end; flex: 1 1 auto; height: .6rem; margin-bottom: clamp(.72rem, 2.45vw, 1.52rem); border-block: 1px solid #71877a; }
.route-line::before { content: ""; display: block; height: 100%; background: repeating-linear-gradient(90deg, transparent 0 5px, #71877a 5px 6px); }

.route-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 1rem 0 .9rem; overflow: hidden; border: 1px solid var(--line); border-radius: .7rem; background: var(--line); }
.route-metrics div { display: flex; align-items: center; justify-content: space-between; gap: .3rem; padding: .65rem clamp(.55rem, 2vw, .85rem); background: #edf3ea; }
.route-metrics span { font-size: .875rem; color: var(--muted); }
.route-metrics strong { font: 700 1.05rem var(--mono); }

.route-history { margin-top: .95rem; }
.route-history h2 { margin: 0 0 .45rem; font-size: .95rem; }
.history { display: grid; gap: .35rem; max-height: 11.5rem; margin: 0; padding: 0; list-style: none; overflow: auto; }
.history li { display: flex; align-items: center; gap: .65rem; min-height: 2.75rem; padding: .3rem .65rem; border: 1px solid var(--line); border-radius: .58rem; background: #f2f6ed; }
.history li:last-child { border-color: #82a695; background: #e5f0e5; }
.history li.new-stop { animation: arrive .22s ease-out; }
.stop-number { min-width: 1.2rem; color: var(--muted); font: .825rem var(--mono); }
.stop-word { display: flex; gap: .22rem; }
.stop-letter { display: grid; place-items: center; width: 1.45rem; height: 1.65rem; border-radius: .28rem; font: 700 1rem var(--mono); }
.stop-letter.changed { background: #c6e5d4; }
.stop-label { margin-left: auto; font-size: .875rem; color: var(--muted); }
@keyframes arrive { from { opacity: .6; transform: translateY(-.25rem); } to { opacity: 1; transform: translateY(0); } }

.current-stop { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; width: fit-content; max-width: 100%; margin: 0 0 .65rem; padding: .3rem .45rem .3rem .6rem; border: 1px solid #c8d5c9; border-radius: .5rem; background: #edf3e8; }
.current-stop-label { color: var(--muted); font-size: .875rem; font-weight: 650; }
.current-stop-letters { display: flex; gap: .22rem; }
.current-stop-tile { display: grid; place-items: center; width: 1.6rem; min-height: 1.65rem; border-radius: .27rem; background: #264d3d; color: #f8fbf3; font: 700 .95rem/1 var(--mono); }
.current-stop-tile.is-changed { background: var(--yellow); color: #2e301b; }
.current-stop-tile.is-new { animation: stop-flip .26s ease-out; }
@keyframes stop-flip { from { transform: scaleY(.28); } to { transform: scaleY(1); } }
.entry-labels { display: flex; align-items: baseline; flex-wrap: wrap; gap: .3rem .65rem; margin-bottom: .4rem; }
.entry label { font-size: .98rem; font-weight: 700; }
.entry-labels > span { color: var(--muted); font-size: .875rem; }
.entry-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .7rem; align-items: stretch; }
.draft-grid { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .38rem; }
.draft-grid input { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; font-size: 16px; }
.draft-cell { min-width: 0; min-height: clamp(2.75rem, 8vw, 3.35rem); padding: 0; border: 1px solid #9fb5a4; border-radius: .45rem; background: linear-gradient(#f9fbf5 49%, #dce9da 50%, #edf5e9 51%); color: #527261; font: 700 clamp(1.2rem, 4vw, 1.6rem)/1 var(--mono); box-shadow: inset 0 -2px #c7d8c8; }
.draft-cell.has-letter { color: var(--ink); }
.draft-cell.is-changed { color: #214924; background: #d6eacb; border-color: #5f8f5c; }
.draft-cell.is-active, .draft-cell:focus-visible { border-color: #2c8769; outline: 2px solid #2c8769; outline-offset: 1px; }
.draft-cell:hover { border-color: #2c8769; }
.draft-grid[data-invalid="true"] .draft-cell { border-color: #b5726e; }
.primary-button { min-height: 2.9rem; padding: 0 .95rem; border: 1px solid #19392d; border-radius: .65rem; background: #264d3d; color: white; font-weight: 650; }
.primary-button:hover { background: #19392d; }
.game-message { min-height: 1.45em; margin: .6rem 0 .55rem; color: var(--muted); font-size: .9rem; line-height: 1.35; }
.game-message[data-state="error"] { color: #9a3434; }
.game-message[data-state="success"] { color: #1e6347; font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.minor-button { min-height: 2.55rem; padding: .35rem .75rem; border: 1px solid #9bb2a2; border-radius: .58rem; background: #f3f7ee; color: var(--ink); font-weight: 650; }
.minor-button:hover:not(:disabled) { background: #dfeddf; }
.share-preview { width: 100%; margin-top: .65rem; padding: .55rem; resize: vertical; border: 1px solid #9bb2a2; border-radius: .55rem; background: white; color: var(--ink); font: inherit; }

.side-panel { display: grid; gap: 1rem; }
.keyboard-panel, .rule-panel { padding: clamp(.75rem, 2.5vw, 1.35rem); }
.game-panel .keyboard-panel { margin-top: .9rem; padding: .65rem .55rem .75rem; background: #eff4eb; box-shadow: none; border-radius: .6rem; }
.side-panel h2 { margin: 0 0 .75rem; font-size: 1.05rem; letter-spacing: -.015em; }
.keyboard { display: grid; gap: .38rem; }
.key-row { display: flex; justify-content: center; gap: clamp(.15rem, .58vw, .34rem); }
.key { flex: 1 1 0; max-width: 2.75rem; min-width: 0; min-height: 2.6rem; padding: 0; border: 1px solid #a7b8a9; border-radius: .42rem; background: #f9fbf5; color: var(--ink); box-shadow: 0 2px #cad8cb; font: 700 clamp(.84rem, 2.3vw, 1rem) var(--mono); }
.key:hover:not(:disabled) { background: #d6e8d8; }
.key:active:not(:disabled) { transform: translateY(1px); }
.key-wide { flex-grow: 1.6; max-width: 3.8rem; }
.rule-panel p { margin: .7rem 0 0; color: #334e42; line-height: 1.55; }
.example { display: flex; flex-wrap: wrap; gap: .5rem; width: max-content; max-width: 100%; margin-top: .75rem; padding: .4rem .55rem; border: 1px dashed #9ab2a1; border-radius: .4rem; background: #edf4eb; color: #294c3d; font: 700 .9rem var(--mono); }
.example span { color: #687f70; }
.site-footer { margin-top: 1rem; font-size: .9rem; }
.site-footer a { color: #2b5441; text-underline-offset: 3px; }

.departure-detail:has(.route-controls:not([hidden])) { flex-wrap: wrap; }
.route-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.route-controls label { font-weight: 650; }
.route-controls select { max-width: 100%; min-height: 2.2rem; padding: .3rem .55rem; border: 1px solid #819a8c; border-radius: .45rem; background: #162e25; color: #f7f9ed; font: inherit; }
.route-controls select:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
.route-controls button { min-height: 2.2rem; border: 1px solid #82998b; padding-inline: .65rem; text-decoration: none; }
.route-controls #start-sprint { border-color: var(--yellow); background: var(--yellow); color: var(--ink); font-weight: 700; }
.route-controls #start-sprint:hover { background: #ffe397; }
.route-controls #start-sprint:focus-visible { outline-offset: 3px; }
.sprint-metrics { position: relative; padding-bottom: 5px; }
.sprint-metrics progress { position: absolute; inset: auto 0 0; display: block; width: 100%; height: 5px; padding: 0; border: 0; accent-color: #427b55; }
.sprint-metrics progress::-webkit-progress-bar { background: #dbe8d8; }
.sprint-metrics progress::-webkit-progress-value { background: #427b55; transition: width .16s linear; }
.sprint-metrics progress::-moz-progress-bar { background: #427b55; }
.sprint-metrics.urgent #sprint-time { color: #9a3434; }
.sprint-metrics.urgent progress { accent-color: #aa4a42; }
.sprint-metrics.urgent progress::-webkit-progress-value { background: #aa4a42; }
.sprint-metrics.urgent progress::-moz-progress-bar { background: #aa4a42; }
.mode-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin: 0; }
.mode-stats > div { min-width: 0; padding: .58rem .64rem; border-radius: .55rem; border: 1px solid #d4e1d2; background: #edf4eb; }
.mode-stats dd { margin: 0 0 .2rem; color: #254939; font: 700 clamp(1.05rem, 3.6vw, 1.4rem) var(--mono); overflow-wrap: anywhere; }
.mode-stats dt { color: var(--muted); font-size: .875rem; }
.stats-note { font-size: .875rem; }
.result { margin-top: .85rem; padding: 1rem; border: 1px solid #a9bda9; border-radius: .85rem; background: linear-gradient(134deg, #edf6e9, #fcf2cd); }
.result-kicker { color: #4b6152; font-size: .875rem; font-weight: 700; }
.result h2 { margin: .25rem 0; font-size: clamp(1.2rem, 4vw, 1.65rem); letter-spacing: -.03em; }
.result p { margin: .35rem 0 .7rem; color: #355145; line-height: 1.45; }
.result details { margin-bottom: .75rem; }
.result summary { width: fit-content; cursor: pointer; font-size: .9rem; font-weight: 650; }
.result summary:focus-visible { outline: 2px solid #2c8769; outline-offset: 4px; }
.review-stops { display: flex; flex-wrap: wrap; gap: .3rem; margin: .55rem 0 0; padding: 0; list-style: none; }
.review-stops li { display: inline-flex; padding: .25rem .42rem; border: 1px solid #bacdb5; border-radius: .32rem; background: #fcfdf8; font: 700 .83rem/1.35 var(--mono); }
.sprint-review { display: grid; }
.sprint-review li { display: block; overflow-wrap: anywhere; }
.result #share-status { margin-bottom: 0; font-size: .875rem; }

@media (max-width: 750px) {
  .game-layout { grid-template-columns: 1fr; gap: .75rem; }
  .side-panel { gap: .75rem; }
  .route-line { max-width: 12rem; }
  .flap-letter { width: clamp(1.45rem, 7vw, 2.85rem); height: clamp(2rem, 9vw, 3.7rem); }
  .key { max-width: 3.35rem; }
  .key-wide { max-width: 4.25rem; }
}

@media (max-width: 590px) {
  .departure-main { align-items: stretch; flex-direction: column; }
  .mode { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mode button { padding-inline: .35rem; }
  .route-controls label { font-size: .825rem; }
}

@media (max-width: 410px) {
  .relay { width: calc(100% - 1rem); }
  .departure-main { padding: .95rem .72rem; gap: .75rem; }
  .brand { gap: .45rem; }
  .brand-mark { flex-basis: 2.35rem; height: 2.35rem; border-radius: .55rem; }
  .brand-mark span { width: 20px; }
  .brand-mark span:nth-child(2)::before { left: 11px; }
  .brand h1 { font-size: clamp(1.35rem, 6.3vw, 1.8rem); }
  .brand p { font-size: .875rem; }
  .mode { gap: .1rem; padding: .18rem; }
  .mode button { min-height: 2.2rem; padding: 0 .4rem; font-size: .9rem; }
  .departure-detail { padding-inline: .72rem; }
  .game-panel { padding: .75rem; }
  .entry-row { gap: .5rem; }
  .draft-grid { gap: .32rem; }
  .game-panel .keyboard-panel { padding-inline: .4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
