:root {
  --felt: #052c22;
  --felt-deep: #031711;
  --felt-light: #0d4b36;
  --ink: #fffaf0;
  --muted: #b8c8bd;
  --gold: #d8b35a;
  --gold-soft: #f4d783;
  --danger: #c94747;
  --chip-red: #8f232d;
  --panel: rgba(5, 36, 28, 0.78);
  --line: rgba(216, 179, 90, 0.28);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--felt-deep);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(216, 179, 90, 0.14), transparent 26rem),
    radial-gradient(circle at 88% 16%, rgba(143, 35, 45, 0.22), transparent 18rem),
    linear-gradient(135deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(225deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(160deg, var(--felt), var(--felt-deep) 70%);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.1);
  box-shadow: inset 0 0 0 1px rgba(255, 250, 240, 0.13);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold-soft);
  outline-offset: 3px;
}

a {
  color: var(--gold-soft);
}

.is-hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 4px solid var(--gold);
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--ink) 0 23%, transparent 24%),
    conic-gradient(from 18deg, var(--chip-red) 0 10%, var(--ink) 10% 14%, var(--chip-red) 14% 28%, var(--ink) 28% 32%, var(--chip-red) 32% 46%, var(--ink) 46% 50%, var(--chip-red) 50% 64%, var(--ink) 64% 68%, var(--chip-red) 68% 82%, var(--ink) 82% 86%, var(--chip-red) 86% 100%);
  box-shadow: var(--shadow);
}

.brand h1,
.setup-copy h2,
.paywall h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.2rem, 5vw, 2rem);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.connection-pill {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--gold-soft);
  background: rgba(0, 0, 0, 0.18);
  font-size: 0.86rem;
  font-weight: 800;
}

.connection-pill.is-offline {
  color: #ffd0d0;
  border-color: rgba(201, 71, 71, 0.5);
}

.setup-screen,
.timer-screen {
  position: relative;
}

.setup-copy {
  margin: 22px 0 18px;
}

.setup-copy h2 {
  font-size: clamp(2rem, 12vw, 4.8rem);
  line-height: 0.98;
}

.setup-form {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.preset-field {
  grid-column: 1 / -1;
}

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

.preset-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.setup-form > label,
.compact-input {
  display: grid;
  gap: 8px;
}

.setup-form span,
.setup-form legend {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.setup-form select,
.setup-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(255, 250, 240, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.24);
  padding: 0 14px;
}

.setup-form fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 48px;
  place-items: center;
  padding: 0 8px;
  border: 1px solid rgba(255, 250, 240, 0.14);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.08);
  text-align: center;
}

.segmented input:checked + span {
  border-color: var(--gold);
  color: #1a1306;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
}

.compact-input {
  margin-top: 10px;
}

.primary-action {
  min-height: 58px;
  color: #171006;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  box-shadow: 0 18px 40px rgba(216, 179, 90, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.34);
  font-weight: 900;
}

.resume-button {
  width: 100%;
  margin-top: 12px;
}

.timer-screen {
  display: grid;
  gap: 14px;
}

.table-status,
.clock-layout,
.admin-controls,
.table-meta,
.share-panel,
.paywall {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.table-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.table-status h2 {
  margin: 0;
  font-size: clamp(1.5rem, 7vw, 3rem);
  letter-spacing: 0;
}

.code-block {
  display: grid;
  gap: 2px;
  min-width: 96px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 250, 240, 0.13);
  border-radius: 8px;
  text-align: center;
}

.code-block span,
.metric span,
.table-meta span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.code-block strong {
  color: var(--gold-soft);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
}

.clock-layout {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.clock-panel {
  display: grid;
  min-height: 246px;
  place-items: center;
  text-align: center;
}

.status-text {
  margin: 0;
  color: var(--gold-soft);
  font-size: clamp(1rem, 4vw, 1.5rem);
  font-weight: 900;
}

.countdown {
  font-variant-numeric: tabular-nums;
  font-size: clamp(4.4rem, 27vw, 12rem);
  font-weight: 950;
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: 0 12px 42px rgba(0, 0, 0, 0.55);
}

.hand-ended {
  width: min(100%, 420px);
  min-height: 64px;
  color: #fff;
  background: linear-gradient(180deg, #d75a5a, var(--danger));
  font-size: 1.08rem;
  font-weight: 900;
}

.new-game-button {
  width: min(100%, 360px);
  min-height: 58px;
  color: #171006;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  font-weight: 900;
}

.blind-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(255, 250, 240, 0.13);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 6px;
  color: var(--ink);
  font-size: clamp(1.4rem, 8vw, 3.6rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
}

.admin-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.admin-controls button:nth-child(1),
.admin-controls button:nth-child(6) {
  grid-column: span 2;
}

.admin-controls button:hover,
.resume-button:hover {
  background: rgba(255, 250, 240, 0.16);
}

.admin-controls button:nth-child(6) {
  color: #ffd0d0;
  box-shadow: inset 0 0 0 1px rgba(201, 71, 71, 0.46);
}

.table-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.table-meta div {
  min-width: 0;
  padding: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.table-meta strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 4px;
  font-size: 1.25rem;
}

.share-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
}

.share-panel a {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
}

#qrCanvas {
  width: 112px;
  height: 112px;
  border: 6px solid #fffaf0;
  border-radius: 8px;
  background: #fffaf0;
}

.paywall {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.product-grid button {
  display: grid;
  min-height: 78px;
  place-items: center;
  padding: 8px;
  border-radius: 8px;
  color: #1a1306;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
}

.product-grid strong,
.product-grid span {
  display: block;
}

.product-grid span {
  color: #4a3710;
  font-size: 0.8rem;
  font-weight: 800;
}

.stress-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(3, 23, 17, 0.92);
}

.stress-overlay span {
  color: var(--gold-soft);
  font-size: min(42vw, 19rem);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 20px 80px rgba(0, 0, 0, 0.62);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 30;
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(3, 23, 17, 0.95);
  box-shadow: var(--shadow);
  text-align: center;
}

.install-banner {
  position: fixed;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  z-index: 35;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 10px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(3, 23, 17, 0.96);
  box-shadow: var(--shadow);
}

.install-banner strong,
.install-banner span {
  display: block;
}

.install-banner strong {
  font-size: 0.95rem;
}

.install-banner span {
  color: var(--muted);
  font-size: 0.78rem;
}

.install-banner button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 900;
}

.install-banner #installButton {
  color: #171006;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
}

.dismiss-install {
  width: 40px;
  padding: 0;
}

@media (max-width: 719px) {
  body.timer-active {
    overflow: hidden;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .topbar {
    flex: 0 0 auto;
    gap: 8px;
    margin-bottom: 8px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-width: 3px;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .eyebrow {
    font-size: 0.58rem;
    margin-bottom: 2px;
  }

  .connection-pill {
    padding: 6px 8px;
    font-size: 0.72rem;
  }

  .setup-screen {
    overflow: auto;
    padding-bottom: 72px;
  }

  .setup-copy {
    margin: 8px 0 10px;
  }

  .setup-copy h2 {
    font-size: clamp(1.65rem, 10vw, 2.7rem);
  }

  .setup-form {
    gap: 10px;
    padding: 10px;
  }

  .setup-form.chef-preset .preset-controlled {
    display: none;
  }

  .preset-note {
    margin-top: 6px;
    font-size: 0.8rem;
  }

  .segmented {
    gap: 6px;
  }

  .segmented span,
  .setup-form select,
  .setup-form input {
    min-height: 42px;
  }

  .primary-action {
    min-height: 48px;
  }

  .timer-screen {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 7px;
    overflow: hidden;
  }

  .table-status,
  .clock-layout,
  .admin-controls,
  .table-meta {
    box-shadow: none;
  }

  .table-status {
    padding: 8px 10px;
  }

  .table-status h2 {
    font-size: clamp(1.1rem, 6vw, 1.65rem);
  }

  .code-block {
    min-width: 82px;
    padding: 6px 8px;
  }

  .code-block span,
  .metric span,
  .table-meta span {
    font-size: 0.56rem;
  }

  .code-block strong {
    font-size: 0.9rem;
  }

  .clock-layout {
    min-height: 0;
    gap: 7px;
    padding: 8px;
  }

  .clock-panel {
    align-content: center;
    gap: 6px;
    min-height: 0;
  }

  .status-text {
    font-size: clamp(0.82rem, 3.4vw, 1.05rem);
  }

  .countdown {
    font-size: clamp(3.35rem, 23vw, 7.2rem);
  }

  .hand-ended,
  .new-game-button {
    min-height: 46px;
    font-size: 0.95rem;
  }

  .blind-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .metric {
    min-height: 58px;
    padding: 8px 6px;
  }

  .metric strong {
    margin-top: 4px;
    font-size: clamp(1.05rem, 6.2vw, 1.9rem);
  }

  .admin-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 7px;
  }

  .admin-controls button,
  button {
    min-height: 38px;
  }

  .admin-controls button {
    padding: 0 6px;
    font-size: clamp(0.68rem, 2.9vw, 0.86rem);
    white-space: nowrap;
  }

  .admin-controls button:nth-child(1),
  .admin-controls button:nth-child(6) {
    grid-column: span 1;
  }

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

  .table-meta div {
    padding: 7px 5px;
  }

  .table-meta strong {
    margin-top: 2px;
    font-size: clamp(0.78rem, 3.3vw, 1rem);
  }

  .share-panel {
    display: none;
  }

  .paywall {
    position: fixed;
    right: 8px;
    bottom: 8px;
    left: 8px;
    z-index: 24;
  }
}

@media (max-width: 390px) and (max-height: 720px) {
  .brand h1 {
    display: none;
  }

  .topbar {
    margin-bottom: 6px;
  }

  .timer-screen {
    gap: 5px;
  }

  .clock-layout {
    gap: 5px;
    padding: 6px;
  }

  .countdown {
    font-size: clamp(3rem, 21vw, 5.6rem);
  }

  .metric {
    min-height: 50px;
    padding: 6px 4px;
  }

  .admin-controls {
    gap: 5px;
    padding: 5px;
  }

  .admin-controls button,
  button {
    min-height: 34px;
  }

  .table-meta div {
    padding: 5px 4px;
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding: 28px;
  }

  .setup-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .setup-form fieldset,
  .primary-action {
    grid-column: span 2;
  }

  .clock-layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
    align-items: stretch;
  }

  .clock-panel {
    min-height: 420px;
  }

  .blind-grid {
    grid-template-columns: 1fr;
  }

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

  .admin-controls button:nth-child(1),
  .admin-controls button:nth-child(6) {
    grid-column: span 1;
  }

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

@media (orientation: landscape) and (max-height: 620px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    margin-bottom: 10px;
  }

  .clock-layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  }

  .clock-panel {
    min-height: 250px;
  }

  .countdown {
    font-size: clamp(4rem, 18vw, 9rem);
  }
}
