:root {
  --bg: #0b3b2f;
  --panel: rgba(6, 26, 20, 0.62);
  --text: #f4efe4;
  --muted: #b4cdc2;
  --accent: #ffc94a;
  --accent-deep: #b8861b;
  --accent-ink: #2a1d00;
  --die: #f6f1e6;
  --pip: #14161b;
  --pip-one: #c62a22;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 48%, transparent 55%, rgba(0, 0, 0, 0.45));
}

/* Top bar: result chips + sum */
.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(to bottom, rgba(4, 20, 15, 0.7), transparent);
  pointer-events: none;
}

.chips {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), var(--chip, 40px));
  gap: 6px;
}

.chip {
  pointer-events: auto;
  width: var(--chip, 40px);
  height: var(--chip, 40px);
  padding: calc(var(--chip, 40px) * 0.14);
  border-radius: calc(var(--chip, 40px) * 0.24);
  border: 0;
  background: var(--die);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s, opacity 0.2s, box-shadow 0.15s;
}

.chip .pip {
  width: 72%;
  height: 72%;
  margin: auto;
  border-radius: 50%;
}

.chip .pip.on { background: var(--pip); }
.chip.v1 .pip.on { background: var(--pip-one); width: 95%; height: 95%; }
.chip.empty { opacity: 0.3; }
.chip.locked {
  transform: translateY(2px);
  box-shadow: 0 0 0 3px var(--accent), 0 3px 10px rgba(0, 0, 0, 0.4);
}

.sum {
  min-width: 58px;
  max-width: 84px;
  text-align: center;
  line-height: 1;
}
.sum small {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sum b {
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

/* Bottom bar: hints + buttons */
.bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(to top, rgba(4, 20, 15, 0.75), transparent);
  pointer-events: none;
}

.combo {
  min-height: 28px;
  display: flex;
  align-items: center;
}
.combo span {
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1);
}
.combo span.big { font-size: 20px; padding: 6px 20px; }

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 1.3em;
  max-width: 420px;
}

.actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 440px;
}

button { font: inherit; touch-action: manipulation; cursor: pointer; }

.throw {
  flex: 1;
  height: 60px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 6px 0 var(--accent-deep), 0 12px 22px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s;
}
.throw:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--accent-deep), 0 6px 12px rgba(0, 0, 0, 0.3);
}
.throw:disabled { opacity: 0.55; cursor: default; }

.icon-btn {
  width: 60px;
  height: 60px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--panel);
  color: var(--text);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.2s;
}
.icon-btn.hidden { opacity: 0; pointer-events: none; }
.icon-btn.small {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
}

button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

/* Sheets: settings, new game, score card */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  animation: fade 0.2s;
}
.backdrop[hidden], .sheet[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 18px calc(env(safe-area-inset-bottom) + 18px);
  border-radius: 22px 22px 0 0;
  background: #10271f;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slide-up 0.25s cubic-bezier(.2, .9, .3, 1);
  -webkit-user-select: text;
  user-select: text;
}

.sheet > * { flex-shrink: 0; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40%); opacity: 0; } }

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  background: #10271f;
}
.sheet h2 { margin: 0; font-size: 20px; }

.close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 16px;
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }
.label { font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }

.segmented {
  display: flex;
  padding: 4px;
  gap: 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
}
.segmented button {
  flex: 1;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button {
  width: 52px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 24px;
}
.stepper button:disabled { opacity: 0.35; }
.stepper output { min-width: 40px; text-align: center; font-size: 26px; font-weight: 800; }

.switch {
  position: relative;
  width: 54px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  transition: background 0.2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

.primary, .secondary {
  height: 52px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 17px;
}
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.primary:disabled { opacity: 0.45; }
.secondary { border: 1px solid rgba(255, 255, 255, 0.2); background: transparent; color: var(--text); }

.names { display: flex; flex-direction: column; gap: 8px; }
.names input {
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.names input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.winner {
  padding: 14px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  text-align: center;
  font-weight: 800;
  font-size: 18px;
}

/* Score card */
.table-wrap { margin-top: -8px; }
.card {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.card th, .card td {
  padding: 0 8px;
  height: 36px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.card th:first-child, .card td:first-child { text-align: left; padding-left: 4px; }
.card thead th {
  position: sticky;
  top: 60px;
  z-index: 1;
  background: #10271f;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .current { background: rgba(255, 201, 74, 0.09); }
.card thead th.current { color: var(--accent); background: #1e3423; }
.card tr.sub td { color: var(--muted); font-size: 13px; height: 30px; }
.card tr.total td { font-weight: 800; font-size: 17px; border-bottom: 0; }
.card tr.pickable { cursor: pointer; }
.card td.preview { color: var(--accent); font-style: italic; opacity: 0.85; }
.card td.preview.zero { color: var(--muted); opacity: 0.6; }
.card tr.selected td { background: rgba(255, 201, 74, 0.28); }
.card tr.selected td.preview { opacity: 1; font-weight: 800; font-style: normal; }

/* Short landscape screens */
@media (max-height: 460px) {
  .top { padding-top: calc(env(safe-area-inset-top) + 6px); padding-bottom: 6px; }
  .sum b { font-size: 24px; }
  .bottom { flex-direction: row; justify-content: center; padding-top: 6px; padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
  .hint { display: none; }
  .combo { order: 2; min-width: 90px; }
  .throw, .icon-btn { height: 48px; }
  .icon-btn { width: 48px; }
}
