:root {
  --felt: #0f2e22;
  --felt-deep: #0a2118;
  --felt-mid: #164032;
  --ink: #14201a;
  --paper: #fffdf7;
  --paper-edge: #e8e0cc;
  --muted: #5c6b63;
  --accent: #c41e3a;
  --accent-deep: #9a1530;
  --gold: #d4a017;
  --ok: #1f7a4d;
  --danger: #b42318;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --font-display: "Archivo Black", "Arial Black", sans-serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: var(--felt);
  --bg-elevated: #16382c;
  --fg: #f4f7f4;
  --fg-muted: #a7b8ae;
  --surface: rgba(255, 253, 247, 0.08);
  --surface-strong: var(--paper);
  --surface-ink: var(--ink);
  --border: rgba(255, 255, 255, 0.12);
  --chip: rgba(255, 255, 255, 0.1);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #e8f0ea;
  --bg-elevated: #ffffff;
  --fg: #14201a;
  --fg-muted: #5c6b63;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-ink: #14201a;
  --border: rgba(20, 32, 26, 0.12);
  --chip: rgba(15, 46, 34, 0.08);
  --shadow: 0 10px 28px rgba(15, 46, 34, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  html[data-theme="system"] {
    --bg: #e8f0ea;
    --bg-elevated: #ffffff;
    --fg: #14201a;
    --fg-muted: #5c6b63;
    --surface: #ffffff;
    --surface-strong: #ffffff;
    --surface-ink: #14201a;
    --border: rgba(20, 32, 26, 0.12);
    --chip: rgba(15, 46, 34, 0.08);
    --shadow: 0 10px 28px rgba(15, 46, 34, 0.12);
    color-scheme: light;
  }
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(196, 30, 58, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(212, 160, 23, 0.12), transparent 50%),
    linear-gradient(165deg, var(--felt-mid), var(--felt) 42%, var(--felt-deep));
  color: var(--fg);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html[data-theme="light"] body,
html[data-theme="system"] body {
  background:
    radial-gradient(1000px 500px at 0% 0%, rgba(196, 30, 58, 0.08), transparent 50%),
    linear-gradient(180deg, #f3f7f4, #dce8e0 60%, #cfdfd5);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] body {
    background:
      radial-gradient(1200px 600px at 10% -10%, rgba(196, 30, 58, 0.18), transparent 55%),
      radial-gradient(900px 500px at 100% 0%, rgba(212, 160, 23, 0.12), transparent 50%),
      linear-gradient(165deg, var(--felt-mid), var(--felt) 42%, var(--felt-deep));
  }
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

a {
  color: inherit;
}

.app {
  min-height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
}

.view[hidden],
[hidden] {
  display: none !important;
}

.topbar,
.game-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.topbar.compact h1,
.game-heading {
  flex: 1;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 5vw, 2rem);
  letter-spacing: 0.04em;
  line-height: 1;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--fg-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--chip);
  color: var(--fg);
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.94);
}

.home-scroll,
.setup-scroll,
.history-scroll,
.help-scroll,
.settings-scroll {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 28px;
}

.hero-actions {
  display: grid;
  gap: 12px;
}

@media (min-width: 640px) {
  .hero-actions {
    grid-template-columns: 1fr 1fr;
  }
}

.action-tile {
  text-align: left;
  padding: 20px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.action-tile.primary {
  background: linear-gradient(145deg, #d62845, var(--accent-deep));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 14px 32px rgba(196, 30, 58, 0.35);
}

.action-tile:active {
  transform: translateY(1px) scale(0.99);
}

.action-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.8;
}

.action-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.action-copy {
  font-size: 0.92rem;
  opacity: 0.88;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
}

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

.panel-head.tight {
  margin-top: 8px;
}

.panel-head h2,
.settings-section,
.help-block h2 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
  font-weight: 700;
}

.panel-meta {
  font-size: 0.8rem;
  color: var(--fg-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat {
  text-align: center;
  padding: 10px 4px;
  border-radius: 12px;
  background: var(--chip);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 12px;
  border-radius: 14px;
  background: var(--chip);
  border: 1px solid transparent;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.game-card:active {
  transform: scale(0.99);
}

.game-card-title {
  font-weight: 650;
}

.game-card-meta,
.game-card-score {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.game-card-score {
  grid-row: span 2;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--fg);
}

.empty-hint {
  margin: 4px 2px 8px;
  color: var(--fg-muted);
  font-size: 0.92rem;
}

.home-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 650;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.pill-btn:active {
  transform: scale(0.97);
}

.pill-btn.solid {
  background: var(--accent);
  color: #fff;
}

.pill-btn.outline {
  border: 1px solid var(--border);
  background: var(--chip);
}

.pill-btn.wide {
  width: 100%;
}

.text-btn {
  color: var(--accent);
  font-weight: 650;
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  font-size: 0.8rem;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 650;
}

.field input {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--chip);
  padding: 0 14px;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.2);
}

.player-inputs {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}

.player-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
}

.switch-row.compact {
  padding: 4px 0 12px;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: none;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.35);
  transition: background 0.2s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.settings-scroll .settings-section {
  margin: 8px 0 4px;
}

.settings-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.settings-row.static {
  cursor: default;
}

.settings-row.danger .settings-label {
  color: #ff8d7e;
}

.settings-label {
  font-weight: 650;
}

.settings-sub {
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.game-top {
  margin-bottom: 10px;
}

.turn-line {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.turn-meta {
  font-size: 0.82rem;
  color: var(--fg-muted);
}

.player-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 4px;
  scrollbar-width: none;
}

.player-tabs::-webkit-scrollbar {
  display: none;
}

.player-tab {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid transparent;
  font-weight: 650;
  white-space: nowrap;
}

.player-tab.active {
  background: var(--paper);
  color: var(--ink);
  border-color: transparent;
}

.player-tab.current-turn:not(.active) {
  border-color: var(--gold);
}

.scorecard-wrap {
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--paper-edge);
}

.scorecard {
  display: grid;
}

.score-section-label {
  padding: 10px 14px 4px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7a6f58;
  font-weight: 700;
  background: #f3ecda;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  min-height: 48px;
  border-top: 1px solid #ebe3cf;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  width: 100%;
}

.score-row:disabled {
  opacity: 1;
}

.score-row.open:active {
  background: #f7efd8;
}

.score-row .label {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.score-row .hint {
  font-size: 0.78rem;
  color: #8a7f66;
  font-weight: 500;
}

.score-row .value {
  display: grid;
  place-items: center;
  border-left: 1px solid #ebe3cf;
  font-family: var(--font-display);
  font-size: 1.15rem;
  background: #fffaf0;
}

.score-row.open .value {
  color: #b0a48a;
}

.score-row.filled .value {
  color: var(--ink);
}

.score-row.total .label,
.score-row.total .value {
  background: #efe6cf;
  font-weight: 700;
}

.score-row.bonus.earned .value {
  color: var(--ok);
}

.score-row.yahtzee-row .label {
  color: var(--accent);
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}

.help-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.help-block p,
.help-list {
  margin: 8px 0 0;
  line-height: 1.5;
  color: var(--fg);
}

.help-list {
  padding-left: 1.1rem;
}

.help-img {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 12, 9, 0.55);
  display: grid;
  align-items: end;
  z-index: 40;
  padding: 12px;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (min-width: 720px) {
  .sheet-backdrop {
    align-items: center;
    justify-items: center;
  }
}

.sheet {
  width: min(480px, 100%);
  background: var(--bg-elevated);
  color: var(--fg);
  border-radius: 22px 22px 18px 18px;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  animation: rise 0.22s ease;
}

@keyframes rise {
  from {
    transform: translateY(16px);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.sheet h2 {
  margin: 0 36px 6px 0;
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}

.sheet-sub {
  margin: 0 0 12px;
  color: var(--fg-muted);
}

.sheet-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

.quick-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-scores button {
  min-width: 48px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--chip);
  border: 1px solid var(--border);
  font-weight: 650;
}

.quick-scores button.suggested {
  background: rgba(196, 30, 58, 0.16);
  border-color: var(--accent);
  color: #ffd0d7;
}

html[data-theme="light"] .quick-scores button.suggested {
  color: var(--accent-deep);
}

@media (prefers-color-scheme: light) {
  html[data-theme="system"] .quick-scores button.suggested {
    color: var(--accent-deep);
  }
}

.sheet-list {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.sheet-item {
  width: 100%;
  text-align: left;
  padding: 14px 10px;
  border-radius: 12px;
  font-weight: 650;
}

.sheet-item:active {
  background: var(--chip);
}

.sheet-item.danger {
  color: #ff8d7e;
}

.results-list {
  margin: 12px 0 18px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.results-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--chip);
  font-weight: 650;
}

.results-list li.winner {
  border: 1px solid var(--gold);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  z-index: 50;
  box-shadow: var(--shadow);
  max-width: min(92vw, 420px);
  text-align: center;
  animation: rise 0.2s ease;
}

/* Tablet landscape: keep scorecard readable */
@media (min-width: 768px) and (orientation: landscape) {
  .app[data-view="game"] {
    max-width: 1200px;
  }

  .score-row {
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
