/* Name Hat.
 *
 * The palette, the rows, the banner and the button shapes arrive unchanged
 * from the single-file app this was converted from. What is new is only what
 * the conversion needed: a header that holds chrome, a help sheet, the hat
 * list, and a 44px floor on the header controls.
 */

:root {
  color-scheme: light dark;

  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-sunken: #f7f8fa;
  --border: #dcdfe4;
  --border-strong: #c3c8d0;
  --text: #1b1f24;
  --text-muted: #616b78;
  --text-faint: #98a1ac;
  --accent: #2f5cff;
  --accent-hover: #2749d6;
  --accent-text: #ffffff;
  --accent-soft: #e8edff;
  --winner: #b25e00;
  --winner-soft: #fff6e6;
  --winner-border: #f0c088;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --scrim: rgba(16, 24, 40, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-sunken: #22272f;
    --border: #2e343d;
    --border-strong: #3d444f;
    --text: #e6e9ee;
    --text-muted: #9aa4b1;
    --text-faint: #6d7783;
    --accent: #6b8cff;
    --accent-hover: #85a0ff;
    --accent-text: #10131a;
    --accent-soft: #23304f;
    --winner: #f0b467;
    --winner-soft: #33291a;
    --winner-border: #6b5330;
    --danger: #f2837c;
    --danger-soft: #3a2220;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --scrim: rgba(0, 0, 0, 0.62);
  }
}

* { box-sizing: border-box; }

/* No `height: 100%` on html/body: an app scrolls as a document (R-A8) and the
   footer sits at the end of it, so the page is as tall as its content. */
body {
  margin: 0;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 620px;
  margin: 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* Wraps rather than squeezes. Three controls plus a title do not fit beside
   each other at 320px, and a header that overflows is worse than one that is
   two lines tall on a narrow phone — especially here, where the page scrolls
   anyway. */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 24px 0 16px;
}

.hdr-text {
  flex: 1 1 200px;
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.app-header p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.hdr-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* R-C5/R-C11: the 44px floor. Stated on the ids as well as the class, because
   the check that measures this reads selectors, and a floor it cannot see is
   a floor nobody is holding. */
#hdr .hdr-btn,
#hdr #hdrHelp,
#hdr #hdrHats {
  min-width: 44px;
  min-height: 44px;
}

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

button {
  font: inherit;
  cursor: pointer;
  color: var(--text);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--surface-sunken); }

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600; min-height: 44px;}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 10px; min-height: 44px;}

.btn-quiet:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

.btn-lg {
  padding: 12px 20px;
  font-size: 15px; min-height: 44px;}

/* ---------- banner ---------- */

.banner {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  text-align: center;
}

/* The label and the name each sit in a fixed band. A status message and a
   large winner name are different sizes, so without the fixed bands the
   banner would grow when someone is drawn and shove the list down. */
.banner-label {
  display: block;
  height: 16px;
  font-size: 11px;
  font-weight: 650;
  line-height: 16px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.banner-name {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  margin-top: 6px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.banner.is-winner {
  border-color: var(--winner-border);
  background: var(--winner-soft);
}

.banner.is-winner .banner-label { color: var(--winner); }

/* One rule for both, so the name does not shift when the spin lands. */
.banner.is-winner .banner-name,
.banner.is-spinning .banner-name {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
}

.banner.is-nudged { animation: nudge 320ms ease; }

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
}

.controls .btn-primary { flex: 1; min-height: 44px;}

/* The hat list still wraps: Export and Import are peers with no primary. */
.controls-wrap { flex-wrap: wrap; }

.controls-wrap .btn { flex: 1 1 auto; min-height: 44px;}

/* Draw a name is alone on its row at every width, and it is the tallest,
   widest thing on the screen after the banner. It used to be `flex: 1` among
   three peers, which made it the widest of four equals rather than the one
   thing you are here to press. */
#run-controls .btn-primary {
  flex: 1 1 100%;
  min-height: 52px;
  font-size: 16px;
}

/* ---------- the round bar ---------- */

.round-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  margin: 0 0 10px;
  padding: 0 2px;
}

.round-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.round-label {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Smaller than a primary and larger than the 44px floor, because a round
   boundary is pressed once per round and must still be a comfortable target. */
.btn-sm {
  min-height: 44px;
  padding: 6px 12px;
  font-size: 13px;
}

.stats {
  display: flex;
  gap: 14px;
  height: 18px;
  margin: 0;
  padding: 0;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--text-muted);
}

.stats b {
  font-weight: 600;
  color: var(--text);
}

/* ---------- list ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.row-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  box-shadow: var(--shadow);
}

.row-main:hover:not(:disabled) { border-color: var(--border-strong); }

.marker {
  flex: none;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 650;
  color: var(--text-faint);
}

.row-name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.tag {
  flex: none;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface-sunken);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Three row states, and none of them is told apart by colour alone (R7.6):
   drawn carries a number in the marker and a strikethrough, out carries a
   dash, a dashed border and an "Out" tag, waiting carries an empty circle. */
.row.is-gone .row-main {
  background: var(--surface-sunken);
  box-shadow: none;
}

.row.is-gone .row-name {
  color: var(--text-faint);
  text-decoration: line-through;
}

.row.is-gone .marker {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

.row.is-absent .row-main {
  background: transparent;
  border-style: dashed;
  box-shadow: none;
}

.row.is-absent .row-name { color: var(--text-faint); }

.row.is-winner .row-main {
  border-color: var(--winner-border);
  background: var(--winner-soft);
}

.row.is-winner .row-name { color: var(--text); }

.row.is-candidate .row-main {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.row-side {
  flex: none;
  min-width: 46px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.row-side:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}

.row-side.is-danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.name-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
}

/* ---------- the hat list ---------- */

.hat-count {
  flex: none;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.row.is-active .row-main {
  border-color: var(--accent);
}

/* ---------- manage ---------- */

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.add-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* Height is reserved even when empty, so a message appearing or clearing
   never moves anything below it. */
.note {
  min-height: 18px;
  margin: 0 2px 10px;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--text-muted);
}

.note.is-error { color: var(--danger); }

.empty {
  margin: 0;
  padding: 26px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  font-size: 13.5px;
  color: var(--text-muted);
}

.hint {
  margin: 20px 2px 0;
  font-size: 12px;
  color: var(--text-faint);
}

.hint kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 11px;
}

/* ---------- help sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheetCard {
  width: 100%;
  max-width: 460px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.sheetCard h2 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 650;
}

.sheetCard p {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-muted);
}

.sheetCard p b { color: var(--text); }

.sheetCard .hint { margin: 0 0 16px; }

.sheetCard .btn { width: 100%; min-height: 44px;}

[hidden] { display: none !important; }

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