:root {
  color-scheme: dark;
  --bg: #141614;
  --felt: #1c4a3e;
  --felt-deep: #12342d;
  --panel: #20231f;
  --panel-strong: #292d27;
  --line: rgba(248, 241, 223, 0.16);
  --text: #f8f1df;
  --muted: #b8b19f;
  --gold: #e4b94f;
  --teal: #1fb09a;
  --red: #d85c57;
  --green: #7ac46c;
  --ink: #151712;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --tap: 46px;
  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;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(31, 176, 154, 0.08), transparent 34%),
    linear-gradient(180deg, #171914, #0f1110 72%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  background: rgba(20, 22, 20, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
}

.brand strong {
  display: block;
  font-size: 1.18rem;
}

.brand span,
.eyebrow,
.muted {
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 18px 14px 38px;
}

.page.compact {
  width: min(520px, 100%);
}

.band {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 2px, transparent 2px 8px),
    linear-gradient(135deg, var(--felt), var(--felt-deep));
}

.hero-table {
  position: relative;
  min-height: 236px;
  padding: 28px 18px;
  overflow: hidden;
}

.hero-table::after {
  content: "";
  position: absolute;
  inset: auto -10% -70px -10%;
  height: 130px;
  background: rgba(8, 12, 10, 0.34);
  transform: rotate(-2deg);
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 720px;
}

.hero-title {
  margin: 0;
  font-size: clamp(2.35rem, 3.2rem, 3.2rem);
  line-height: 0.95;
}

.hero-copy {
  max-width: 42rem;
  margin: 14px 0 0;
  color: #e7dec7;
  font-size: 1rem;
  line-height: 1.5;
}

.grid {
  display: grid;
  gap: 14px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1fr);
}

.panel,
.game-list-item,
.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(32, 35, 31, 0.96);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel.flush {
  padding: 0;
  overflow: hidden;
}

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

.section-title h1,
.section-title h2,
.section-title h3 {
  margin: 0;
}

.button,
.icon-button {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #282c26;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  text-decoration: none;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: rgba(248, 241, 223, 0.34);
}

.button.primary {
  border-color: rgba(228, 185, 79, 0.6);
  background: var(--gold);
  color: #1d1605;
  font-weight: 800;
}

.button.teal {
  border-color: rgba(31, 176, 154, 0.6);
  background: #176c60;
}

.button.danger {
  border-color: rgba(216, 92, 87, 0.62);
  background: #5a2725;
}

.button.ghost {
  background: transparent;
}

.icon-button {
  width: var(--tap);
  padding: 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field label {
  color: var(--muted);
  font-size: 0.92rem;
}

.input,
.select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151713;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.input:focus,
.select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(228, 185, 79, 0.18);
}

.tabs,
.segmented {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151713;
  gap: 4px;
}

.tab,
.segment {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.tab.active,
.segment.active {
  background: var(--panel-strong);
  color: var(--text);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.status-pill.live {
  color: #d9ffe1;
  border-color: rgba(122, 196, 108, 0.52);
}

.status-pill.warn {
  color: #ffe9bb;
  border-color: rgba(228, 185, 79, 0.56);
}

.game-list {
  display: grid;
  gap: 10px;
}

.game-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
  text-align: left;
  color: var(--text);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #191c18;
  padding: 12px;
  min-height: 86px;
}

.score-card.current {
  border-color: rgba(228, 185, 79, 0.72);
  background: #2c2718;
}

.score-card strong {
  display: block;
  overflow-wrap: anywhere;
}

.score-value {
  margin-top: 8px;
  color: var(--gold);
  font-size: 1.35rem;
  font-weight: 850;
}

.board-shell {
  display: grid;
  gap: 14px;
}

.dice-table {
  position: relative;
  min-height: 334px;
  border: 1px solid rgba(248, 241, 223, 0.18);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 11px),
    linear-gradient(135deg, #205443, #102d28);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.28), var(--shadow);
  padding: 18px;
  overflow: hidden;
}

.turn-banner {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  min-height: 56px;
  margin-bottom: 16px;
}

.turn-banner h1 {
  margin: 0;
  font-size: 1.25rem;
}

.turn-score {
  display: grid;
  place-items: center;
  min-width: 92px;
  min-height: 58px;
  border: 1px solid rgba(228, 185, 79, 0.55);
  border-radius: var(--radius);
  background: rgba(20, 22, 20, 0.68);
}

.turn-score span {
  color: var(--muted);
  font-size: 0.76rem;
}

.turn-score strong {
  color: var(--gold);
  font-size: 1.2rem;
}

.dice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 12px;
  max-width: 440px;
  margin: 0 auto;
}

.die {
  aspect-ratio: 1;
  min-width: 0;
  border: 0;
  border-radius: 16%;
  background: #f8f1df;
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.08), 0 14px 30px rgba(0, 0, 0, 0.32);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 15%;
  transform: translateZ(0);
}

.die.placeholder {
  opacity: 0.34;
}

.die.selected {
  outline: 4px solid var(--gold);
  outline-offset: 3px;
}

.die.rolling {
  animation: dice-roll 0.56s infinite cubic-bezier(0.23, 0.84, 0.44, 1);
}

.pip {
  width: 54%;
  height: 54%;
  align-self: center;
  justify-self: center;
  border-radius: 50%;
  background: transparent;
}

.pip.active {
  background: #161914;
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.12);
}

.board-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.board-actions .wide {
  grid-column: 1 / -1;
}

.roll-meta {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: #e4dcc8;
  font-size: 0.95rem;
}

.option-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px dashed rgba(228, 185, 79, 0.48);
  border-radius: var(--radius);
  background: rgba(228, 185, 79, 0.08);
  padding: 12px;
  color: #f5e5b5;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.56);
}

.modal {
  width: min(520px, 100%);
  padding: 16px;
}

.toast-root {
  position: fixed;
  inset: auto 12px max(12px, env(safe-area-inset-bottom)) 12px;
  z-index: 80;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(520px, 100%);
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111310;
  color: var(--text);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.offline-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
}

.offline-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 24px;
  text-align: center;
}

.settings-list {
  display: grid;
  gap: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
}

.switch-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--gold);
}

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

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

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

@keyframes dice-roll {
  0% {
    transform: rotate(0deg) translateY(0);
  }
  35% {
    transform: rotate(18deg) translateY(-10px);
  }
  70% {
    transform: rotate(-14deg) translateY(5px);
  }
  100% {
    transform: rotate(0deg) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 760px) {
  .page {
    padding: 26px 22px 48px;
  }

  .dashboard-grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.6fr);
    align-items: start;
  }

  .board-shell {
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
    align-items: start;
  }

  .dice-grid {
    grid-template-columns: repeat(3, 116px);
    justify-content: center;
  }

  .modal-backdrop {
    place-items: center;
  }
}
