/* Mobile-first shell: compact sticky header, equal-width tabs, single column. */

:root {
  /* One source of truth for the content column, shared by .app and .topbar. */
  --col: 1080px;
  --col-pad: 10px;
}

.app {
  position: relative;
  max-width: var(--col);
  margin: 0 auto;
  padding: 0 var(--col-pad) calc(20px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ header */

/*
 * Full-bleed stripe: .app is a centred max-width box, so escaping its padding
 * is not enough — the bar has to span the viewport itself. 50% of the parent
 * plus 50vw back out lands on each viewport edge at any parent width.
 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  width: 100vw;
  margin-inline: calc(50% - 50vw);
  padding: 10px 0;
  background: var(--bg-800);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px rgb(0 0 0 / 35%);
}

/* Contents track the card column: same max-width and same inline padding. */
.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  /*
   * The bar spans the viewport, so its contents must be re-inset to the card
   * column: cards occupy --col minus .app's padding on each side. Capping the
   * inner box at exactly that width and centring it lands the edges on them.
   */
  max-width: calc(var(--col) - var(--col-pad) * 2);
  margin: 0 auto;
  /* Below the cap the bar is viewport-wide, so it needs its own gutter. */
  padding-inline: var(--col-pad);
}

@media (min-width: 1080px) {
  .topbar-inner {
    padding-inline: 0;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  flex: none;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.94rem;
  color: var(--sand-100);
  white-space: nowrap;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Force + server time sit on one line and wrap together on narrow screens. */

/*
 * Mobile-first: brand, then Force, then Server time — each on its own row.
 * The three time slots need their full text width, so nothing here may shrink
 * them; at 320px they cannot share a line with the Force switch either.
 */
.controlbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  flex: 1 0 100%;
  min-width: 0;
}

.controlbar > .control {
  flex: 1 0 100%;
}

/* Line the two control labels up so the groups below them start together. */
.controlbar .control-label {
  flex: none;
  min-width: 74px;
}

/*
 * Below 620px the brand plus three time slots cannot share a line without the
 * times being truncated. Drop the control bar onto its own full-width row and
 * let the brand text ellipsise instead — the times must stay readable.
 */

.control {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

/* Never squeeze the slot group below the width its times need. */
.control-grow {
  flex: 0 1 auto;
}

.control-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* -------------------------------------------------------------------- tabs */

.tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  margin: 10px 0 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-800);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding-top: var(--gap);
}

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 0 6px;
  color: #4c5561;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-align: center;
}

.footer-credit {
  color: var(--amber-500);
  opacity: 0.75;
}

/* ------------------------------------------------------------------- grids */

/* Single column by default; the columns come back at the 620px breakpoint. */
.grid-2,
.grid-3 {
  display: grid;
  gap: 8px 10px;
  grid-template-columns: minmax(0, 1fr);
}

.board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

/* A board holding a single card should not be squeezed into one column. */
.board-single {
  grid-template-columns: minmax(0, 1fr);
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 6px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

@media (min-width: 620px) {
  :root {
    --col-pad: 18px;
  }

  .topbar {
    padding: 12px 0;
  }

  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-single {
    grid-template-columns: minmax(0, 1fr);
  }

  .control-label {
    font-size: 0.76rem;
  }

  /* Enough room again: brand and both controls share one row. */
  .controlbar {
    flex: 0 1 auto;
  }

  .controlbar > .control {
    flex: 0 1 auto;
  }

  .controlbar .control-label {
    min-width: 0;
  }
}

@media (min-width: 940px) {
  .board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board-single {
    grid-template-columns: minmax(0, 1fr);
  }
}
