:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --panel: #fffdf8;
  --ink: #171717;
  --muted: #67635b;
  --line: #ded8cc;
  --accent: #246b5a;
  --accent-strong: #16483d;
  --danger: #b63b3b;
  --warning: #cf5f1b;
  --shadow: 0 14px 36px rgba(32, 27, 18, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  min-height: 42px;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

button:hover,
.file-button:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent), var(--line) 45%);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0.6rem 0.75rem;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.danger-button {
  color: var(--danger);
}

.ghost-button {
  background: transparent;
}

.large-button {
  min-width: 150px;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.host-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.host-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.host-header h1 {
  margin: 0;
  font-size: clamp(2.3rem, 7vw, 5.2rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.header-actions,
.control-row,
.inline-form,
.segmented {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wrap {
  flex-wrap: wrap;
}

.tv-mirror {
  display: grid;
  grid-template-columns: minmax(210px, 0.65fr) 1fr;
  gap: 16px;
  align-items: stretch;
  background: #151b1a;
  color: #fff9eb;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.mirror-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.mirror-main strong {
  grid-row: span 2;
  font-size: clamp(4.2rem, 14vw, 8rem);
  line-height: 0.85;
}

.mirror-main #mirror-timer {
  font-size: clamp(1.8rem, 5vw, 3.3rem);
  font-weight: 900;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #cfe7df;
  padding: 0.4rem 0.7rem;
  font-weight: 800;
}

.mirror-phase {
  margin: 0 0 0.75rem;
  color: #cfe7df;
  font-weight: 800;
}

.mirror-categories {
  margin: 0;
  padding-left: 1.3rem;
  display: grid;
  gap: 0.25rem;
}

.host-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.panel {
  grid-column: span 4;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.game-panel,
.score-panel,
.categories-panel {
  grid-column: span 6;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.status-text {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.letter-chip {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 900;
}

.field {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.inline-field {
  grid-template-columns: auto minmax(90px, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.short-field {
  width: 96px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.toggle input {
  width: 20px;
  min-height: 20px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 12px;
}

.segmented button {
  padding-inline: 0.45rem;
}

.stepper {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.stepper button {
  min-height: 54px;
  font-size: 1.3rem;
  font-weight: 900;
}

.inline-form {
  align-items: stretch;
  margin-bottom: 12px;
}

.inline-form input {
  flex: 1;
}

.editable-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}

.editable-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 8px;
}

.editable-list span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.file-button {
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.table-wrap {
  overflow-x: auto;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
}

.score-table th,
.score-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
}

.score-table th {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.score-table td:nth-child(2) {
  display: flex;
  gap: 8px;
  min-width: 160px;
}

.score-table input {
  width: 86px;
}

.urgent {
  color: var(--warning) !important;
}

.host-dark {
  --bg: #121514;
  --panel: #191f1d;
  --ink: #fff9eb;
  --muted: #b7b0a2;
  --line: #343b38;
  --accent: #5fc4a8;
  --accent-strong: #3da98c;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.22);
}

.host-dark button,
.host-dark input,
.host-dark select,
.host-dark .editable-list li {
  background: #111514;
  color: var(--ink);
}

body[data-view="tv"] {
  min-height: 100vh;
  background: #0f1514;
  color: #fff8e8;
  overflow-x: hidden;
}

.tv-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: clamp(18px, 3vw, 34px);
  padding: clamp(24px, 5vw, 72px);
}

.tv-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
}

.tv-round,
.tv-phase,
.tv-label {
  margin: 0;
  color: #9fcbbc;
  font-size: clamp(1.05rem, 2.4vw, 1.7rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tv-phase {
  margin-top: 0.35rem;
  color: #ddd3bf;
  letter-spacing: 0;
  text-transform: none;
}

.tv-timer {
  min-width: 210px;
  text-align: right;
  font-size: clamp(4.2rem, 12vw, 10rem);
  font-weight: 950;
  line-height: 0.85;
}

.tv-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: end;
  gap: clamp(18px, 4vw, 42px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  padding-bottom: clamp(18px, 3vw, 32px);
}

.tv-hero h1 {
  margin: 0;
  font-size: clamp(8rem, 26vw, 23rem);
  line-height: 0.75;
  letter-spacing: 0;
}

.tv-section h2 {
  margin: 0 0 clamp(16px, 3vw, 28px);
  color: #ddd3bf;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
}

.tv-categories {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 22px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.tv-categories li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: baseline;
  min-height: 74px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.055);
  padding: clamp(12px, 2vw, 20px);
}

.tv-categories span {
  color: #6dbda4;
  font-size: clamp(1rem, 2vw, 1.45rem);
  font-weight: 950;
}

.tv-categories strong {
  font-size: clamp(1.45rem, 3vw, 3rem);
  line-height: 1.04;
  overflow-wrap: anywhere;
}

.tv-scores {
  display: grid;
  gap: clamp(12px, 1.6vw, 18px);
}

.tv-score-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: clamp(14px, 3vw, 32px);
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.055);
  padding: clamp(14px, 2vw, 24px);
}

.tv-score-row span:first-child {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #9fcbbc;
  font-size: 1.6rem;
  font-weight: 950;
}

.tv-score-row strong {
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 1;
}

.tv-score-row span:last-child {
  color: #fff0c4;
  font-size: clamp(1.7rem, 4vw, 4rem);
  font-weight: 950;
}

.tv-score-row.winner {
  border-color: #f3c968;
  background: rgba(243, 201, 104, 0.16);
}

.empty-state {
  margin: 0;
  color: #ddd3bf;
  font-size: clamp(1.5rem, 4vw, 3.2rem);
}

@media (max-width: 920px) {
  .host-header,
  .tv-mirror {
    grid-template-columns: 1fr;
  }

  .host-header {
    display: grid;
    align-items: start;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .panel,
  .game-panel,
  .score-panel,
  .categories-panel {
    grid-column: span 12;
  }
}

@media (max-width: 640px) {
  .host-shell {
    width: min(100% - 18px, 520px);
    padding-top: 14px;
  }

  .tv-mirror,
  .panel {
    padding: 12px;
  }

  .inline-form,
  .control-row,
  .header-actions {
    align-items: stretch;
  }

  .inline-form {
    flex-direction: column;
  }

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

  .editable-list li {
    grid-template-columns: 1fr;
  }

  .score-table {
    min-width: 560px;
  }

  .tv-shell {
    padding: 18px;
  }

  .tv-topbar,
  .tv-hero {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tv-timer {
    min-width: 0;
    text-align: left;
  }

  .tv-categories {
    grid-template-columns: 1fr;
  }

  .tv-score-row {
    grid-template-columns: 48px 1fr;
  }

  .tv-score-row span:last-child {
    grid-column: 2;
  }
}
