* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --apron: #C8C6BF;   /* concrete-gray apron */
  --field: #F0C400;   /* pack yellow accents */
  --ink: #202E40;     /* pack navy linework */
  --board: #1B2A3C;   /* departure-board navy */
  --white: #ffffff;
  --red: #F07050;     /* pack coral */
  --blue: #00B0A0;    /* pack teal */
  --dim: #9fb0c2;
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--apron);
  color: var(--ink);
  font-family: Futura, "Avenir Next", "Century Gothic", "Trebuchet MS", sans-serif;
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

/* ---------------- departure board ---------------- */
#board {
  background: var(--board);
  border-bottom: 5px solid var(--ink);
  display: flex;
  align-items: flex-end;
  gap: 26px;
  padding: 12px 18px 14px;
  flex-wrap: wrap;
}

.grp { min-width: 0; }
.grow { flex: 1; }

.lbl {
  display: block;
  color: var(--field);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.24em;
  margin-bottom: 6px;
}

.flaps { display: flex; gap: 2px; flex-wrap: wrap; }

.flap {
  min-width: 15px;
  text-align: center;
  padding: 6px 2px;
  border-radius: 3px;
  color: #f4eede;
  font: 700 15px ui-monospace, Menlo, Consolas, monospace;
  background: linear-gradient(180deg, #2c3f57 0%, #253549 47%, #101b28 50%, #1e2c3d 53%, #1a2734 100%);
  transform-origin: 50% 50%;
  animation: flip 0.25s ease;
}
.flap.still { animation: none; }

/* starts tilted but readable — a cell must never render edge-on/blank,
   even during its stagger delay (hence no fill mode) */
@keyframes flip {
  from { transform: rotateX(55deg); }
  to   { transform: none; }
}

/* ---------------- stage ---------------- */
#stage { position: relative; flex: 1; min-height: 0; }

#scene { display: block; width: 100%; height: 100%; }

#runs {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--board);
  border: 3px solid var(--ink);
  padding: 12px 16px;
  min-width: 240px;
}
#runs h2 {
  color: var(--field);
  font-size: 9px;
  letter-spacing: 0.28em;
  margin-bottom: 7px;
}
#results { list-style: none; max-height: 120px; overflow-y: auto; }
#results li {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: #e8e8e8;
  font: 600 12px ui-monospace, Menlo, monospace;
  padding: 3px 0;
}
#results li.empty { color: #666; }
#results li.best { color: var(--field); }
#results li.best::before { content: "★ "; }

/* ---------------- control deck ---------------- */
#deck {
  background: var(--board);
  border-top: 5px solid var(--ink);
  display: flex;
  align-items: flex-start;
  gap: 26px;
  padding: 13px 18px 15px;
  flex-wrap: wrap;
  color: #eee;
}

.deck-lbl {
  display: block;
  color: var(--field);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.24em;
  margin-bottom: 7px;
}

.ctl { min-width: 0; }
.ctl.grow { flex: 1; min-width: 260px; }

.selwrap { position: relative; display: block; }
.selwrap::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--field);
  pointer-events: none;
  font-size: 13px;
}
select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: var(--board);
  color: var(--field);
  border: 2px solid var(--field);
  border-radius: 0;
  padding: 9px 36px 9px 12px;
  font: 700 14px Futura, "Avenir Next", sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

#strategy-desc {
  margin-top: 7px;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--dim);
  max-width: 460px;
}

button {
  font-family: inherit;
  border-radius: 0;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.actions { display: flex; gap: 10px; align-items: center; padding-top: 16px; }

#board-btn {
  background: var(--field);
  color: var(--ink);
  border: 2px solid var(--field);
  font-size: 16px;
  font-weight: 800;
  padding: 12px 28px;
}
#board-btn:hover { background: var(--white); border-color: var(--white); }

#reset, #design {
  background: none;
  border: 2px solid #4a5d75;
  color: #ddd;
  font-size: 12px;
  font-weight: 700;
  padding: 12px 18px;
}
#reset:hover, #design:hover { border-color: #ddd; }
#design { border-color: var(--blue); color: var(--blue); }
#design:hover { background: var(--blue); color: var(--ink); border-color: var(--blue); }

#speeds { display: flex; gap: 6px; }
#speeds button {
  background: none;
  border: 2px solid #4a5d75;
  color: #ddd;
  font-size: 12px;
  font-weight: 700;
  padding: 9px 12px;
}
#speeds button.on {
  background: var(--field);
  border-color: var(--field);
  color: var(--ink);
}

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

.chips { display: flex; gap: 14px; padding-top: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #ccc;
}
.chip img {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  image-rendering: auto;
}
.chip .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  flex-shrink: 0;
}

/* ---------------- strategy designer ---------------- */
#dz {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 24, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 12px;
}
#dz[hidden] { display: none; }

.dz-panel {
  background: var(--board);
  border: 3px solid var(--ink);
  color: #eee;
  padding: 16px 18px;
  max-width: 880px;
  width: 100%;
  max-height: 94dvh;
  overflow-y: auto;
}

.dz-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.dz-title {
  color: var(--field);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.24em;
}
.dz-x {
  background: none;
  border: 2px solid #4a5d75;
  color: #ddd;
  padding: 4px 9px;
  font-size: 12px;
}
.dz-x:hover { border-color: #ddd; }

.dz-hint {
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 12px;
  max-width: 60ch;
}

.dz-palette {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.dz-swatch {
  border: 2px solid transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 10px;
  min-width: 44px;
  display: inline-flex;
  gap: 5px;
  align-items: baseline;
  justify-content: center;
}
.dz-swatch i {
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  opacity: 0.65;
}
.dz-swatch.on {
  border-color: var(--white);
  outline: 2px solid var(--white);
  outline-offset: 1px;
}

.dz-gridwrap { overflow-x: auto; margin-bottom: 12px; }
.dz-grid {
  --cell: 26px;
  display: grid;
  grid-template-columns: 22px repeat(24, var(--cell));
  gap: 2px;
  width: max-content;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.dz-grid button { border: none; border-radius: 3px; padding: 0; }
.dz-cell {
  width: var(--cell);
  height: var(--cell);
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}
.dz-corner { background: none; }
.dz-colhead, .dz-rowhead {
  background: #24354a;
  color: var(--dim);
  font-size: 9px;
  font-weight: 700;
  height: var(--cell);
  cursor: pointer;
}
.dz-colhead:hover, .dz-rowhead:hover { color: var(--white); }
.dz-aisle { background: none; height: 8px; pointer-events: none; }

.dz-row { margin-bottom: 12px; }
.dz-row .deck-lbl { margin-bottom: 6px; }
.dz-within, .dz-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.dz-within button, .dz-presets button {
  background: none;
  border: 2px solid #4a5d75;
  color: #ddd;
  font-size: 10px;
  font-weight: 700;
  padding: 8px 10px;
}
.dz-within button.on {
  background: var(--field);
  border-color: var(--field);
  color: var(--ink);
}
.dz-presets button:hover, .dz-within button:hover { border-color: #ddd; }
.dz-within button.on:hover { border-color: var(--field); }

.dz-name {
  background: var(--board);
  border: 2px solid var(--field);
  color: var(--field);
  font: 700 15px Futura, "Avenir Next", sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 9px 12px;
  width: 100%;
  max-width: 320px;
}
.dz-name:focus-visible { outline: 2px solid var(--white); outline-offset: 2px; }

.dz-foot { display: flex; gap: 10px; }
.dz-save {
  background: var(--field);
  border: 2px solid var(--field);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  padding: 12px 24px;
}
.dz-save:hover { background: var(--white); border-color: var(--white); }
.dz-cancel {
  background: none;
  border: 2px solid #4a5d75;
  color: #ddd;
  font-size: 12px;
  font-weight: 700;
  padding: 12px 16px;
}
.dz-cancel:hover { border-color: #ddd; }

@media (max-width: 640px) {
  .dz-panel { padding: 12px; }
  /* fit all 24 rows on screen: the grid captures touch for painting, so it
     must not need horizontal scrolling */
  .dz-grid { --cell: clamp(10px, calc((100vw - 102px) / 25), 21px); gap: 1px; }
  .dz-cell { font-size: 8px; }
  .dz-colhead, .dz-rowhead { font-size: 7px; }
  .dz-foot { flex-wrap: wrap; }
  .dz-save { flex: 1; }
}

@media (max-width: 900px) {
  #board { gap: 14px; }
  .grp.grow { display: none; }

  /* keep recorded runs visible as a compact translucent overlay */
  #runs {
    background: rgba(27, 42, 60, 0.85);
    border-width: 2px;
    padding: 8px 10px;
    min-width: 0;
    top: 8px;
    right: 8px;
  }
  #runs h2 { font-size: 8px; margin-bottom: 4px; }
  #results li { font-size: 10px; gap: 12px; }
}

@media (max-width: 640px) {
  /* portrait: park the runs overlay in the empty apron between terminal and stand */
  #runs { top: 26%; }

  #board { gap: 10px; padding: 8px 10px 10px; }
  #board .grp:first-child { display: none; } /* decorative flight number */
  .lbl { font-size: 8px; margin-bottom: 4px; }
  .flap { min-width: 11px; padding: 4px 1px; font-size: 12px; }

  #deck { gap: 12px 16px; padding: 10px 12px 14px; }
  .ctl.grow { min-width: 100%; }
  select { font-size: 16px; } /* prevents iOS focus zoom */
  #strategy-desc { font-size: 10px; }
  .actions { width: 100%; padding-top: 0; }
  #board-btn { flex: 1; padding: 13px 20px; }
  #reset { padding: 13px 16px; }
  #speeds button { padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .flap { animation: none; }
}
