/*
  Intergalactic Twilight Imperium — the whole stylesheet.

  Hand-written, no framework: one file, served static, no build step. Mirrors
  BulletHeartSingles' approach, which is why there is no Tailwind here.

  Mobile first. The two real surfaces are a phone (players, score entry) and a
  TV across the room (Feature 7), so nothing here may depend on a hover state
  and nothing may assume a mouse. Desktop is a widened phone.

  Dark only: the app is used in a room lit for a board game and shown on a TV,
  where a white page is a lamp. `color-scheme: dark` is set in base.html so
  form controls and scrollbars follow.
*/

:root {
  /* Deep space, not black — pure black crushes on a TV's contrast curve. */
  --bg: #0b0d17;
  --bg-raised: #151929;
  --bg-sunken: #080a12;
  --border: #262c42;
  --border-bright: #3a4263;

  --text: #e8eaf2;
  --text-dim: #98a0bd;
  --text-faint: #6a7194;

  /* Warm gold — the TI4 trade-goods colour. Accents only. */
  --accent: #d9a441;
  --accent-dim: #8c6a2b;
  --accent-text: #1a1204;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 1rem;
  --measure: 46rem;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  /* iOS: keep the space background under the home-indicator area. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

/* ---------------------------------------------------------------- nav ---- */

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 0.65rem 1rem;
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
  /* Sticky so the tabs stay reachable one-thumbed on a long scoreboard. */
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-left { display: flex; align-items: center; gap: 1rem; min-width: 0; }

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.nav-mark { color: var(--accent); font-size: 1.1rem; }

/* "Intergalactic TI4" is short enough to hold at every width, so the wordmark
   no longer drops on a narrow phone — losing it left a bare glyph that read as
   a rendering fault rather than a brand. */
.nav-brand-text { white-space: nowrap; }

.nav-tabs { display: flex; gap: 0.25rem; }

.nav-tab {
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.95rem;
  white-space: nowrap;
}
.nav-tab.active { background: var(--bg-raised); color: var(--text); }

.nav-right { display: flex; align-items: center; gap: 0.75rem; }
.nav-user {
  color: var(--text-dim);
  font-size: 0.9rem;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-login { text-decoration: none; font-size: 0.95rem; }

/* --------------------------------------------------------------- main ---- */

.main {
  flex: 1;
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* --------------------------------------------------------------- hero ---- */

.hero { text-align: center; padding: 1rem 0 2rem; }

.hero-mark {
  font-size: 2.5rem;
  color: var(--accent);
  line-height: 1;
}

.hero-title {
  margin: 0.5rem 0 0.75rem;
  font-size: clamp(1.9rem, 8vw, 3rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
  font-weight: 700;
}

.hero-lede {
  margin: 0 auto;
  max-width: 34rem;
  color: var(--text-dim);
  font-size: 1.02rem;
}

.hero-points {
  list-style: none;
  margin: 1.75rem auto 0;
  padding: 0;
  max-width: 34rem;
  text-align: left;
  display: grid;
  gap: 0.85rem;
}
.hero-points li {
  display: flex;
  gap: 0.6rem;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.hero-points strong { color: var(--text); }
.hero-point-mark { color: var(--accent-dim); flex: none; }

/* -------------------------------------------------------------- panel ---- */

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.1rem 1.25rem;
  margin-top: 1.5rem;
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  font-weight: 600;
}

.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.event-list a { text-decoration: none; }

.empty { margin: 0; color: var(--text-dim); }

/* ------------------------------------------------------------ buttons ---- */

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  /* 44px min target — this is used on a phone mid-game. */
  min-height: 44px;
  line-height: 1.9;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* ------------------------------------------------------ signin notice ---- */

.signin-notice {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
  padding: 0.9rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
}
.signin-notice-text { flex: 1 1 14rem; color: var(--text-dim); font-size: 0.95rem; }
.signin-notice-text strong { color: var(--text); }
.signin-notice-close {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
}

/* --------------------------------------------------------------- misc ---- */

.build-note {
  margin-top: 2rem;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
}
.build-note code { font-family: var(--font-mono); font-size: 0.8rem; }

.footer {
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: center;
  display: grid;
  gap: 0.35rem;
}
.footer strong { color: var(--text-dim); font-weight: 600; }

.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.25rem 0.1rem;
  border-bottom: 2px solid transparent;
}
.nav-link.active, .nav-link:hover { color: var(--text); border-bottom-color: var(--accent-dim); }

/* ------------------------------------------------------------ library ---- */
/*
  The public reference browse (Feature 3). Card text is the point of the page,
  so it is set at full width and full length — no truncation, no click-through.
*/

.panel-lede { color: var(--text-dim); margin: 0 0 1rem; }

.lib-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.lib-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
}
.lib-tab.active {
  border-color: var(--accent-dim);
  color: var(--text);
  background: var(--bg-raised);
}
.lib-tab-count {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.lib-note {
  color: var(--text-faint);
  font-size: 0.9rem;
  margin: 0 0 1rem;
  max-width: var(--measure);
}

.lib-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }

.lib-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.lib-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.lib-card-name { margin: 0 0.3rem 0 0; font-size: 1.05rem; }

/* Card text carries meaningful paragraph breaks straight from the wiki. */
.lib-text {
  margin: 0 0 0.5rem;
  color: var(--text-dim);
  white-space: pre-line;
}
.lib-text:last-child { margin-bottom: 0; }

.lib-side {
  display: inline-block;
  min-width: 4.2rem;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border-bright);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--text-faint);
  white-space: nowrap;
}
.tag-law, .tag-high { border-color: #6b3a4a; color: #d99aaa; }
.tag-directive, .tag-moderate { border-color: #4a5a3a; color: #a8c68a; }
.tag-low { border-color: #3a5a6b; color: #8ab8d9; }
.tag-elect, .tag-complexity { border-color: var(--accent-dim); color: var(--accent); }
.tag-removed { border-color: #6b4a3a; color: #d9a48a; }

.lib-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
.lib-faction {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.lib-faction-name { flex: 1 1 100%; font-weight: 600; }

.lib-colors {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
}
.lib-color {
  border-radius: var(--radius-sm);
  padding: 0.9rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.lib-color-name { font-weight: 600; }
.lib-color-hex { font-family: var(--font-mono); font-size: 0.75rem; opacity: 0.75; }

/* ------------------------------------------------- forms and controls ---- */
/*
  Feature 4. Touch targets first: the people using these are standing over a
  table with a phone in one hand, so nothing is smaller than 44px tall and
  nothing depends on hover.
*/

.panel-narrow { max-width: 34rem; }
.panel-sub { color: var(--text-faint); font-weight: 400; font-size: 0.8em; }

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 1.5rem 0 0.6rem;
}
.section-title:first-of-type { margin-top: 0.5rem; }

.form { display: grid; gap: 1rem; }
.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.field { display: grid; gap: 0.3rem; border: 0; padding: 0; margin: 0; }
.field-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.field-hint { font-size: 0.85rem; color: var(--text-faint); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 16px; /* iOS zooms the page on focus below 16px. */
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

.radio-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.radio, .check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 0.7rem 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  cursor: pointer;
}
.check { width: fit-content; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent-dim); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-quiet { background: none; border-color: var(--border); color: var(--text-faint); }
.btn-danger { border-color: #7a3030; color: #e59a9a; background: none; }

.notice {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: var(--bg-sunken);
  margin: 0 0 1rem;
}
.notice-warn { border-color: #6b5a2b; color: #e0c98a; }
.notice-error { border-color: #7a3030; color: #e59a9a; }

.panel-danger { border-color: #4a2626; }

/* ---------------------------------------------------------- events ------ */

.event-head {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
}
.event-meta { color: var(--text-dim); margin: 0.2rem 0 0; }

.status {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-bright);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}
.status-live { border-color: #3a6b4a; color: #8ad9a4; }
.status-draft { border-color: #6b5a2b; color: #e0c98a; }
.status-complete { border-color: var(--border-bright); color: var(--text-faint); }

.event-list { list-style: none; margin: 0 0 0.5rem; padding: 0; display: grid; gap: 0.4rem; }
.event-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
  justify-content: space-between;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
}
.event-row-link { text-decoration: none; font-weight: 600; }
.event-row-meta { color: var(--text-faint); font-size: 0.85rem; }

.table-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  margin-top: 1rem;
}
.table-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
}
.table-card-name { margin: 0; font-size: 1rem; }
.table-card-meta { color: var(--text-faint); font-size: 0.85rem; margin: 0.2rem 0 0.5rem; }

.settings-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  margin-bottom: 0.75rem;
  display: grid;
  gap: 0.6rem;
}

/* ------------------------------------------------------ user pickers ---- */

.leader-list { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.leader-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.empty-inline { color: var(--text-faint); font-size: 0.85rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  border: 1px solid var(--border-bright);
  border-radius: 999px;
  font-size: 0.85rem;
}
.chip form { display: inline; }
.chip-x {
  background: none;
  border: 0;
  color: var(--text-faint);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.25rem;
  cursor: pointer;
}
.chip-x:hover { color: #e59a9a; }

.user-picker { position: relative; }
.user-results {
  position: absolute;
  z-index: 20;
  top: calc(100% + 2px);
  left: 0;
  min-width: 16rem;
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.user-result {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px;
  align-items: center;
}
.user-result:hover, .user-result:focus { background: var(--bg-sunken); outline: none; }
.user-result-name { font-weight: 600; }
.user-result-mail { color: var(--text-faint); font-size: 0.8rem; font-family: var(--font-mono); }

/* ------------------------------------------------------------ roster ---- */
/*
  Feature 5. The seat list is read far more often than it is edited — a player
  looking up their own colour on a phone — so the read view is the plain one and
  every control hides behind a <details>.
*/

.section-title-note { color: var(--text-faint); font-weight: 400; letter-spacing: 0; }
.inline-form { display: inline; margin-left: 0.5rem; }
.btn-small { min-height: 32px; padding: 0 0.6rem; font-size: 0.85rem; }

.team-row {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.team-chip {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.9rem;
}
.team-chip-name { font-weight: 600; }
.team-chip-size { font-variant-numeric: tabular-nums; opacity: 0.8; }

.seat-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.35rem; }
.seat {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
}
.seat-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.seat-chip {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 1px solid var(--border-bright);
  flex: none;
}
.seat-name { font-weight: 600; }
.seat-faction { color: var(--text-dim); font-size: 0.9rem; }
.pin { color: var(--accent); font-size: 0.8rem; }

.tag-beginner { border-color: #3a5a6b; color: #8ab8d9; }
.tag-intermediate { border-color: #4a5a3a; color: #a8c68a; }
.tag-veteran { border-color: #6b3a4a; color: #d99aaa; }

.seat-edit { margin-top: 0.5rem; }
.seat-edit-toggle {
  cursor: pointer;
  color: var(--text-faint);
  font-size: 0.85rem;
  min-height: 32px;
  display: flex;
  align-items: center;
}
.seat-edit[open] .seat-edit-toggle { color: var(--text-dim); }
.seat-edit .form { margin-top: 0.5rem; }

.mini-field { display: grid; gap: 0.15rem; }
.mini-field > span {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

/* ----------------------------------------------------------- scoring ---- */
/*
  Feature 6. The +/− targets are 56px, not the 44px minimum: the person using
  them is holding a phone in one hand, standing over a crowded table, in a room
  lit for a board game. This is the one control in the app that has to work
  without looking.
*/

.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; counter-reset: rank; }
.standing {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
}
.standing-chip {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 5rem;
  text-align: center;
}
.standing-vp {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
  text-align: right;
}
.standing-members { color: var(--text-faint); font-size: 0.85rem; }

.score-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.score-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
}
.score-row-won { border-color: var(--accent-dim); }
.score-name { font-weight: 600; flex: 1 1 6rem; }
.score-vp {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2rem;
  text-align: right;
}
.tag-won { border-color: var(--accent-dim); color: var(--accent); }

.score-controls { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.btn-vp {
  width: 56px;
  height: 56px;
  font-size: 1.6rem;
  line-height: 1;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--text);
  cursor: pointer;
}
.btn-vp-add { border-color: var(--accent-dim); color: var(--accent); }
.btn-vp[disabled] { opacity: 0.3; cursor: not-allowed; }
.score-exact { display: flex; gap: 0.3rem; align-items: center; }
.score-exact input { width: 4.5rem; text-align: center; }

.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.log-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.log-row-undone { opacity: 0.45; text-decoration: line-through; }
.log-when { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.8rem; }
.log-who { font-weight: 600; flex: 1 1 6rem; }
.log-delta { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 2.2rem; text-align: right; }
.log-delta.up { color: #8ad9a4; }
.log-delta.down { color: #e59a9a; }
.log-vp { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.log-author { color: var(--text-faint); font-size: 0.8rem; }
.log-note { color: var(--text-dim); font-style: italic; }
