:root {
  --paper: #e7dfd0;
  --card: #f7f3ea;
  --ink: #241c16;
  --muted: #6f6256;
  --line: rgba(36, 28, 22, 0.12);
  --brass: #a67c3d;
  --gold: #e4c36a;
  --felt-0: #1c7a62;
  --felt-1: #114f40;
  --point-a: #f0e2c4;
  --point-b: #9c3b2e;
  --warn: #f3d2c2;
  --good: #d7eadc;
  --shadow: 0 16px 40px rgba(48, 28, 12, 0.16);
  --checker: 28px;
  --point: 36px;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 0% -10%, #f8f3e8, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

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

button { cursor: pointer; }

button:disabled,
button.auto-hold { cursor: not-allowed; opacity: 0.45; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  padding: 16px 16px 8px;
}

.brand { margin-right: auto; }

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1, h2, .stats strong {
  font-family: Fraunces, Georgia, "Times New Roman", serif;
  font-weight: 560;
  letter-spacing: -0.03em;
}

h1 { margin: 0; line-height: 0; }

h1 img {
  display: block;
  height: clamp(32px, 5vw, 48px);
  margin-top: 10px;
  width: auto;
}

h2 { margin: 0 0 8px; font-size: 1.7rem; }

.score { display: flex; gap: 8px; }

.side {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: auto;
  min-height: 40px;
  padding: 4px 10px 4px 6px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.turn-clock {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  width: 0;
  pointer-events: none;
}

.side > :not(.turn-clock) {
  position: relative;
  z-index: 1;
}

.side b {
  max-width: 7rem;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side span {
  min-width: 1ch;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.side[data-rank="bronze"] { --side-edge: #c4894a; --side-aura: rgba(176, 96, 42, 0.5); }
.side[data-rank="silver"] { --side-edge: #d5dee8; --side-aura: rgba(150, 168, 188, 0.75); }
.side[data-rank="gold"] { --side-edge: #e4c36a; --side-aura: rgba(214, 164, 48, 0.7); }
.side[data-rank="platinum"] { --side-edge: #9fd4ee; --side-aura: rgba(120, 196, 230, 0.75); }
.side[data-rank="diamond"] { --side-edge: #5ecfff; --side-aura: rgba(70, 190, 255, 0.8); }
.side[data-rank="legend"] { --side-edge: #f0c14a; --side-aura: rgba(196, 92, 255, 0.55); }

.side[data-level="5"] { --side-glow: 0px; }
.side[data-level="4"] { --side-glow: 4px; }
.side[data-level="3"] { --side-glow: 7px; }
.side[data-level="2"] { --side-glow: 10px; }
.side[data-level="1"] { --side-glow: 14px; }

.side[data-rank] {
  border-color: var(--side-edge);
  box-shadow: 0 0 var(--side-glow) var(--side-aura);
}

.side.active {
  box-shadow: inset 0 0 0 2px var(--brass), 0 0 var(--side-glow, 0px) var(--side-aura, transparent);
}

.side.winner { background: var(--good); }

.pip-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: block;
}

.pip-dot.light {
  background: radial-gradient(circle at 35% 30%, #fff, #ddd2c0 62%, #b7a892);
  box-shadow: inset 0 0 0 1px rgba(36, 28, 22, 0.25);
}

.pip-dot.dark {
  background: radial-gradient(circle at 35% 30%, #5c554e, #1b1714 60%, #0d0b0a);
  box-shadow: inset 0 0 0 1px rgba(228, 195, 106, 0.7);
}

.ghost, .texty, .actions button:not(.die), .sheet .primary, .lobby-actions button {
  border-radius: 999px;
  min-height: 44px;
  padding: 0 14px;
  touch-action: manipulation;
}

.ghost, .actions button:not(.primary):not(.die), .texty {
  background: transparent;
  border: 1px solid var(--line);
}

.texty {
  border: 0;
  color: var(--muted);
  min-height: 36px;
}

.primary {
  background: var(--ink);
  color: #f6f1e7;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 332px;
  gap: 16px;
  align-items: start;
  padding: 8px 16px 24px;
}

.table,
.board-scroll { min-width: 0; }

.board-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
}

.frame {
  width: max-content;
  margin-inline: auto;
  padding: 12px;
  border-radius: 22px;
  background: linear-gradient(160deg, #7a5538, #3c2618 42%, #24160f);
}

.felt {
  --checker: 28px;
  --point: 36px;
  --slot-label: 16px;
  --bar: 46px;
  --off: 84px;
  display: grid;
  grid-template-columns: max-content var(--bar) max-content var(--off);
  grid-template-areas:
    "tl bar tr off"
    "bl bar br off";
  gap: 8px 8px;
  padding: 10px;
  border-radius: 12px;
  background:
    radial-gradient(80% 70% at 50% 40%, var(--felt-0), var(--felt-1) 72%);
}

.quadrant {
  position: relative;
  display: flex;
  gap: 2px;
  height: calc(var(--checker) * 5.7 + var(--slot-label));
}

.felt.mirrored {
  grid-template-columns: var(--off) max-content var(--bar) max-content;
  grid-template-areas:
    "off tl bar tr"
    "off bl bar br";
}

.felt.stacked {
  grid-template-columns: max-content var(--bar) var(--off);
  grid-template-areas:
    "tr bar off"
    "tl bar off"
    "bl bar off"
    "br bar off";
}

.felt.mirrored.stacked {
  grid-template-columns: var(--off) var(--bar) max-content;
  grid-template-areas:
    "off bar tr"
    "off bar tl"
    "off bar bl"
    "off bar br";
}

.felt.stacked .bl { margin-top: 10px; }

.tl { grid-area: tl; }
.tr { grid-area: tr; }
.bl { grid-area: bl; }
.br { grid-area: br; }

.quadrant.short { background: rgba(156, 59, 46, 0.28); border-radius: 8px; }

.point {
  position: relative;
  width: var(--point);
  flex: 0 0 var(--point);
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: manipulation;
}

.pip {
  position: absolute;
  left: 1px;
  right: 1px;
}

.point.top .pip {
  top: var(--slot-label);
  bottom: 0;
  clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
}
.point.bottom .pip {
  top: 0;
  bottom: var(--slot-label);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.point.tone-a .pip { background: var(--point-a); }
.point.tone-b .pip { background: var(--point-b); }
.point.legal .pip { background: var(--gold); }
.point.selected .pip { filter: brightness(1.16); }

.idx {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  height: var(--slot-label);
  color: #f6efe4;
  font-size: 11px;
  font-weight: 700;
  line-height: var(--slot-label);
  text-align: center;
  pointer-events: none;
}

.point.top .idx { top: 0; }
.point.bottom .idx { bottom: 0; }

.stack { position: absolute; left: 0; right: 0; pointer-events: none; }
.point.top .stack { top: var(--slot-label); bottom: 0; }
.point.bottom .stack { top: 0; bottom: var(--slot-label); }

.checker {
  position: absolute;
  left: 50%;
  display: grid;
  width: var(--checker);
  height: var(--checker);
  margin-left: calc(var(--checker) * -0.5);
  place-items: center;
  border-radius: 50%;
  font-size: calc(var(--checker) * 0.36);
  font-weight: 700;
  line-height: 1;
  transition: transform 0.12s ease;
}

.rail-top .checker { top: calc(var(--inset, 5px) + var(--i) * var(--checker) * 0.46); }
.rail-bottom .checker { bottom: calc(var(--inset, 5px) + var(--i) * var(--checker) * 0.46); }

.checker.white {
  color: var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff, #efe6d8 58%, #c9bba6);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.7),
    inset 0 0 0 4px rgba(80, 60, 40, 0.18),
    0 1px 1px rgba(0, 0, 0, 0.35);
}

.checker.black {
  color: #f6f1e7;
  background: radial-gradient(circle at 35% 30%, #5a534c, #221e1b 55%, #100e0c);
  box-shadow:
    inset 0 0 0 2px rgba(228, 195, 106, 0.55),
    0 1px 1px rgba(0, 0, 0, 0.4);
}

.checker.editing { outline: 2px solid var(--gold); outline-offset: 1px; }

.point.movable .checker.cap,
.pocket.movable .checker.cap {
  outline: 3px solid var(--gold);
  outline-offset: 1px;
  filter: drop-shadow(0 0 2px rgba(36, 28, 22, 0.9));
}

.point.bottom.selected .checker.cap { transform: translateY(-7px); }
.point.top.selected .checker.cap { transform: translateY(7px); }

.mark {
  position: absolute;
  left: 50%;
  width: calc(var(--checker) * 0.7);
  height: calc(var(--checker) * 0.7);
  margin-left: calc(var(--checker) * -0.35);
  border: 2px dashed rgba(36, 28, 22, 0.55);
  border-radius: 50%;
  pointer-events: none;
}

.point.top .mark { top: calc(var(--slot-label) + 8px); }
.point.bottom .mark { bottom: calc(var(--slot-label) + 8px); }

.bar {
  grid-area: bar;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  border-radius: 8px;
  background: linear-gradient(90deg, #5a3b26, #2a1b12 45%, #5a3b26);
}

.pocket {
  position: relative;
  width: 100%;
  flex: 1;
  border: 0;
  background: transparent;
}

.pocket.selected { box-shadow: inset 0 0 0 2px var(--gold); border-radius: 8px; }

.hinge {
  width: 68%;
  height: 8px;
  margin: 4px 0;
  border-radius: 99px;
  background: linear-gradient(#f3dc9a, #a67c3d);
  flex: 0 0 auto;
}

.off {
  grid-area: off;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.off-pocket {
  position: relative;
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  color: #f6f1e7;
  overflow: hidden;
}

.off-pocket.legal {
  background: rgba(228, 195, 106, 0.35);
  box-shadow: inset 0 0 0 2px var(--gold);
}

.off-pocket .stack { top: 0; bottom: 0; }

.off-metrics {
  position: absolute;
  z-index: 3;
  left: 3px;
  right: 3px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 4px;
  align-items: baseline;
  padding: 3px 4px 4px;
  border-radius: 6px;
  background: rgba(12, 28, 24, 0.78);
  color: #f6f1e7;
  font-size: 10px;
  line-height: 1.35;
  pointer-events: none;
}

.off-metrics i {
  font-style: normal;
  font-weight: 500;
  opacity: 0.82;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-initial { display: none; }

.off-metrics b {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.off-pocket.top .off-metrics { bottom: 3px; }
.off-pocket.bottom .off-metrics { top: 3px; }

.legend {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-wrap {
  position: relative;
  min-width: 0;
}

body:not([data-phase="setup"]) .panel-wrap {
  margin-top: 18px;
  margin-right: 18px;
}

.panel {
  position: relative;
  z-index: 5;
  min-width: 0;
  padding: 14px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(48, 28, 12, 0.08);
}

.compact-toggle {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 6px 16px rgba(48, 28, 12, 0.18);
  transform: translate(50%, -50%);
}

.compact-toggle svg,
.actions button svg,
header button svg,
.game-menu-actions button svg,
#btn-copy-room svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.actions button svg .dot { fill: currentColor; stroke: none; }

.panel:not(.compact) #play-panel button:not(.die) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.panel:not(.compact) #play-panel button svg {
  display: block;
  flex: 0 0 auto;
}

body:not([data-compact="true"]) .icon-expand,
body[data-compact="true"] .icon-compact { display: none; }

body:not([data-fullscreen="true"]) .icon-exit-fs,
body[data-fullscreen="true"] .icon-enter-fs { display: none; }

body:not([data-phase="setup"]) .panel:not(.compact) { padding-right: 28px; }

.panel.compact {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: fit-content;
  min-width: 0;
  padding: 16px 14px;
  overflow: visible;
}

.panel.compact > :not(#play-panel) { display: none !important; }

.panel.compact .roll-line { display: contents; }

.panel.compact #dice {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 0;
  margin: 0;
}
.panel.compact #play-panel > :not(#btn-roll):not(#btn-end):not(#btn-undo):not(#btn-reset):not(.roll-line):not(.cmd) { display: none !important; }

.panel.compact .actions .primary { order: 0; }

.panel.compact .actions {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 0;
}

.panel.compact #btn-roll,
.panel.compact #btn-end,
.panel.compact #btn-undo,
.panel.compact #btn-reset {
  position: relative;
  display: grid !important;
  place-items: center;
  flex: 0 0 auto;
  width: 56px;
  min-width: 56px;
  height: 56px;
  min-height: 56px;
  padding: 0;
}

.panel.compact .actions button svg {
  width: 26px;
  height: 26px;
}

.panel.compact .actions button:not(.die) span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.panel.compact .cmd {
  position: relative;
  display: grid;
  flex: 0 0 auto;
}

.status {
  display: flex;
  flex-direction: column;
  height: calc(2 * 1.4em + 20px);
  margin: 0 0 10px;
  padding: 10px 12px;
  overflow: hidden;
  border-radius: 12px;
  background: #efe6d6;
  line-height: 1.4;
  cursor: pointer;
}

.status.expanded {
  height: auto;
  min-height: calc(2 * 1.4em + 20px);
  overflow: visible;
}

.status.warn { background: var(--warn); }
.status.good { background: var(--good); }

.status-text,
.log {
  margin: 0;
  min-width: 0;
  line-height: 1.4;
}

.status:not(.expanded):not(.has-log) .status-text {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status:not(.expanded).has-log .status-text,
.status:not(.expanded).has-log .log {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status.expanded .status-text,
.status.expanded .log {
  display: block;
  overflow: visible;
  white-space: normal;
}

.log {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.dice {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.die {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 40px;
  height: 40px;
  padding: 5px;
  border: 0;
  border-radius: 8px;
  background: #fbf8f2;
  box-shadow: inset 0 0 0 1px rgba(36, 28, 22, 0.16), 0 2px 0 rgba(36, 28, 22, 0.18);
}

.die.count {
  display: flex;
  align-items: center;
  justify-content: center;
}

.die .mult {
  color: var(--ink);
  font-style: normal;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  pointer-events: none;
}

.die span { border-radius: 50%; background: transparent; }
.die[data-face="1"] span:nth-child(5),
.die[data-face="2"] span:nth-child(1),
.die[data-face="2"] span:nth-child(9),
.die[data-face="3"] span:nth-child(1),
.die[data-face="3"] span:nth-child(5),
.die[data-face="3"] span:nth-child(9),
.die[data-face="4"] span:nth-child(1),
.die[data-face="4"] span:nth-child(3),
.die[data-face="4"] span:nth-child(7),
.die[data-face="4"] span:nth-child(9),
.die[data-face="5"] span:nth-child(1),
.die[data-face="5"] span:nth-child(3),
.die[data-face="5"] span:nth-child(5),
.die[data-face="5"] span:nth-child(7),
.die[data-face="5"] span:nth-child(9),
.die[data-face="6"] span:nth-child(1),
.die[data-face="6"] span:nth-child(3),
.die[data-face="6"] span:nth-child(4),
.die[data-face="6"] span:nth-child(6),
.die[data-face="6"] span:nth-child(7),
.die[data-face="6"] span:nth-child(9) { background: var(--ink); }

.die.numeral {
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.05rem;
}

.die,
.die:disabled { opacity: 1; }
.die.rolled,
.die.rolled:disabled { opacity: 0.72; }
.die.used,
.die.used:disabled { opacity: 0.42; }
.die.choice { box-shadow: 0 0 0 3px var(--gold); }
.die.rolling { animation: wobble 0.12s linear infinite; }

@keyframes wobble {
  50% { transform: rotate(8deg) scale(0.96); }
}

.field, .names, .slider, .slider input { min-width: 0; }

.field, .names label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.slider { display: flex; align-items: center; gap: 8px; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 0.85rem; }
.slider input { flex: 1; height: 36px; accent-color: #8c3d22; }

.names { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.names label { min-width: 0; margin-bottom: 10px; }
.names input, .stats div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 40px;
}

.names input {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--ink);
}

body[data-phase="setup"] .status { display: none; }
body[data-online="true"][data-phase="setup"] .status { display: block; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.stats div { padding: 8px 4px; text-align: center; }
.stats strong { display: block; font-size: 1.55rem; color: var(--ink); }
.stats strong .dice-sides {
  font-size: 1em;
  letter-spacing: normal;
  text-transform: none;
}
.stats strong .dice-x {
  margin-right: 0.22em;
  font-size: 0.62em;
  font-weight: 560;
  letter-spacing: 0;
  text-transform: none;
}
.stats span { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; }

.segmented {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  padding: 3px;
  background: #e7dfd0;
  border-radius: 999px;
}

.segmented button {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented button[aria-pressed="true"] {
  background: #fff;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(36, 28, 22, 0.12);
}

.note { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; }
.note.warn { color: #7a3418; }

.setup-fold {
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}

.setup-fold > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.setup-fold > summary::-webkit-details-marker { display: none; }

.setup-fold > summary::after {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.setup-fold[open] > summary::after {
  margin-top: 4px;
  transform: rotate(-135deg);
}

.setup-fold-body { padding: 0 12px 12px; }

.setup-fold .actions button { flex: 1 1 0; }

.quarters { width: 100%; margin-bottom: 8px; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.quarters caption { margin-bottom: 4px; color: var(--muted); font-size: 0.78rem; text-align: left; }
.quarters th, .quarters td { padding: 4px 2px; text-align: center; }
.quarters tbody th { text-align: left; font-weight: 700; }
.quarters td.bad { color: #8c3d22; font-weight: 700; background: var(--warn); border-radius: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .primary { order: -1; flex: 1 0 100%; }
.actions button:not(.primary):not(.die) { flex: 1 1 calc(50% - 8px); background: #fff; }

.panel:not(.compact) .roll-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 0 100%;
  order: -2;
}

.panel:not(.compact) .roll-line #dice { margin-bottom: 0; }

.panel:not(.compact) .roll-line #btn-roll {
  flex: 1 1 auto;
  order: 0;
  min-width: 0;
}

.cmd {
  position: relative;
  display: flex;
  min-width: 0;
}

.panel:not(.compact) .actions > .cmd {
  order: -1;
  flex: 1 0 100%;
}

.panel:not(.compact) .roll-line .cmd {
  flex: 1 1 auto;
  order: 0;
}

.panel:not(.compact) .cmd > .primary {
  width: 100%;
  padding-right: 42px;
}

.actions button.auto-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  z-index: 1;
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(36, 28, 22, 0.16);
  transform: translateY(-50%);
}

.actions button.auto-toggle[aria-pressed="true"] {
  box-shadow: inset 0 0 0 2px var(--gold);
}

.panel.compact .actions button.auto-toggle {
  top: -1px;
  right: -1px;
  z-index: 2;
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  font-size: 0.72rem;
  transform: none;
}

.panel.compact .actions button.auto-toggle[aria-pressed="true"] {
  background: var(--gold);
  box-shadow: none;
}

#btn-score { margin-top: 8px; }

dialog {
  width: min(440px, calc(100% - 24px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}

#rules { width: min(560px, calc(100% - 24px)); }

#player-profile { width: min(420px, calc(100% - 24px)); }

#player-profile .texty { width: 100%; }

dialog::backdrop { background: rgba(28, 20, 12, 0.55); }

#confirm {
  z-index: 40;
}

#confirm::backdrop { background: rgba(18, 12, 8, 0.78); }

#confirm h2 { margin-bottom: 16px; line-height: 1.25; }

.sheet { padding: 18px; }
.rules h3 { margin: 14px 0 6px; font-size: 1rem; }
.rules ul { margin: 0 0 12px; padding-left: 1.1rem; }
.rules li, .rules p { margin-top: 0; }
.rules table { width: 100%; margin-bottom: 12px; border-collapse: collapse; }
.rules th, .rules td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.sheet .primary { width: 100%; }

.room-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 6px 4px 12px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.room-chip span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.room-chip b {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.14em;
}

.room-chip .texty { min-height: 32px; padding: 0 8px; }

#btn-copy-room {
  display: grid;
  place-items: center;
  width: 32px;
  min-width: 32px;
  padding: 0;
}

#btn-copy-room .icon-copied { display: none; }

#btn-copy-room.copied .icon-copy { display: none; }

#btn-copy-room.copied .icon-copied { display: block; }

header #btn-menu,
header #btn-fullscreen,
header #btn-rules {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  min-width: 95px;
}

#btn-fullscreen[aria-pressed="true"] {
  background: var(--ink);
  color: #f6f1e7;
  border-color: var(--ink);
}

#game-menu { width: min(440px, calc(100% - 24px)); }

.game-menu h2 { margin-bottom: 14px; }

.game-menu-names {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.game-menu-names .side {
  flex: 1 1 160px;
  min-width: 0;
}

#game-menu .side b {
  display: block;
  max-width: none;
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
  overflow-wrap: anywhere;
}

.game-menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.game-menu-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-align: center;
}

.game-menu-actions .texty {
  background: transparent;
  border: 0;
  color: var(--muted);
}

#menu-fullscreen[aria-pressed="true"] {
  background: var(--ink);
  color: #f6f1e7;
  border-color: var(--ink);
}

.game-menu-actions #menu-exit,
.game-menu-actions #menu-close { grid-column: 1 / -1; }

@media (max-width: 420px) {
  .game-menu-actions { grid-template-columns: 1fr; }
}

.lobby {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: url("../background.jpg") center / cover no-repeat;
}

.lobby-stack {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.lobby-card {
  width: 100%;
  padding: 28px 22px 18px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.lobby-tools {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
}

.tool-slot { position: relative; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#btn-profile {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--card);
}

.icon-btn.is-open,
.icon-btn[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--card);
}

#btn-profile.is-in { box-shadow: inset 0 0 0 2px var(--brass); }

.lang-menu {
  position: absolute;
  top: 52px;
  left: 0;
  z-index: 2;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: #fff;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.lang-menu button {
  min-width: 44px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.lang-menu button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--card);
}

.profile-name {
  margin: 0 0 12px;
  text-align: center;
  font-weight: 700;
  font-size: 1.15rem;
}

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

.profile-stats div {
  padding: 12px 8px;
  background: #fff;
  border-radius: 14px;
  text-align: center;
}

.profile-stats dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-stats dd {
  margin: 4px 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.6rem;
}

.rank-badge,
.rank-chip {
  --rank-sat: 1;
  --rank-aura: transparent;
  --rank-pop: 0px;
  position: relative;
  border: 1px solid transparent;
  filter: saturate(var(--rank-sat));
}

.rank-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin: 0 0 14px;
  min-height: 76px;
  padding: 12px 16px 14px;
  border-radius: 18px;
  text-align: center;
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.38),
    0 0 var(--rank-pop) var(--rank-aura);
}

.rank-kicker {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.72;
}

.rank-title {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.55rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.rank-chip {
  display: inline-flex;
  align-items: center;
  flex: none;
  min-height: 22px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 0 calc(var(--rank-pop) * 0.45) var(--rank-aura);
}

.rank-none {
  background: #fff;
  color: var(--muted);
  border-color: var(--line);
  filter: none;
  box-shadow: none;
}

.rank-none .rank-title {
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
}

.rank-badge[data-level="5"],
.rank-chip[data-level="5"] { --rank-sat: 0.86; --rank-pop: 0px; }
.rank-badge[data-level="4"],
.rank-chip[data-level="4"] { --rank-sat: 0.94; --rank-pop: 6px; }
.rank-badge[data-level="3"],
.rank-chip[data-level="3"] { --rank-sat: 1; --rank-pop: 10px; }
.rank-badge[data-level="2"],
.rank-chip[data-level="2"] { --rank-sat: 1.08; --rank-pop: 14px; }
.rank-badge[data-level="1"],
.rank-chip[data-level="1"] { --rank-sat: 1.16; --rank-pop: 20px; }

.rank-bronze {
  --rank-aura: rgba(176, 96, 42, 0.55);
  color: #fff8f0;
  border-color: rgba(255, 214, 176, 0.72);
  background:
    radial-gradient(120% 90% at 12% 0%, rgba(255, 214, 170, 0.5), transparent 42%),
    linear-gradient(145deg, #5a3118 0%, #b8733a 48%, #7c4522 100%);
}

.rank-silver {
  --rank-aura: rgba(150, 168, 188, 0.7);
  color: #17202b;
  border-color: rgba(255, 255, 255, 0.9);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), transparent 38%),
    linear-gradient(135deg, #7e8b9c 0%, #f7fafc 42%, #c5d0dc 68%, #667484 100%);
}

.rank-gold {
  --rank-aura: rgba(214, 164, 48, 0.72);
  color: #3c2806;
  border-color: #fff0b8;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent 34%),
    linear-gradient(135deg, #8a6210 0%, #f3d36a 40%, #fff3c4 52%, #c9962c 78%, #6d4c0c 100%);
}

.rank-platinum {
  --rank-aura: rgba(120, 196, 230, 0.75);
  color: #10283c;
  border-color: #f3fbff;
  background:
    linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.72) 46%, transparent 62%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), transparent 40%),
    linear-gradient(125deg, #8ec8e6 0%, #f7fcff 42%, #d5e4f0 62%, #6eadd0 100%);
  background-size: 220% 100%, auto, auto;
}

.rank-diamond {
  --rank-aura: rgba(70, 190, 255, 0.8);
  color: #04283a;
  border-color: rgba(255, 255, 255, 0.92);
  background:
    linear-gradient(128deg, rgba(255, 255, 255, 0.7) 0 14%, transparent 14% 28%, rgba(255, 255, 255, 0.28) 28% 40%, transparent 40%),
    radial-gradient(90% 80% at 80% 0%, rgba(255, 255, 255, 0.85), transparent 46%),
    linear-gradient(155deg, #5ecfff 0%, #f4fdff 34%, #3aa8f0 58%, #d8f7ff 78%, #1578c9 100%);
}

.rank-legend {
  --rank-aura: rgba(255, 176, 64, 0.8);
  color: #fff6df;
  border-color: rgba(255, 214, 120, 0.85);
  text-shadow: 0 1px 10px rgba(255, 170, 50, 0.35);
  background:
    radial-gradient(80% 120% at 100% 0%, rgba(255, 196, 80, 0.62), transparent 42%),
    radial-gradient(80% 100% at 0% 100%, rgba(186, 64, 255, 0.62), transparent 48%),
    linear-gradient(135deg, #120216 0%, #4a1878 38%, #1a0828 68%, #6a2848 100%);
  background-size: 160% 160%, 160% 160%, 220% 220%;
}

.rank-badge.rank-platinum,
.rank-badge.rank-legend {
  animation: rank-shift 5.5s ease-in-out infinite;
}

.rank-badge.rank-diamond::after,
.rank-chip.rank-diamond::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  top: 18%;
  right: 14%;
  border-radius: 50%;
  background: #fff;
  box-shadow: -18px 16px 0 -1px rgba(255, 255, 255, 0.85), 10px 22px 0 -2px rgba(255, 255, 255, 0.7);
  animation: rank-spark 2.4s ease-in-out infinite;
  pointer-events: none;
}

.rank-chip.rank-diamond { padding-right: 14px; }

.rank-chip.rank-diamond::after {
  width: 3px;
  height: 3px;
  top: 3px;
  right: 5px;
  box-shadow: -7px 7px 0 -1px rgba(255, 255, 255, 0.9);
}

.rank-badge.rank-legend::before {
  content: "";
  position: absolute;
  inset: -40% auto auto 20%;
  width: 40%;
  height: 180%;
  background: linear-gradient(90deg, transparent, rgba(255, 236, 180, 0.28), transparent);
  transform: rotate(18deg);
  animation: rank-glint 4.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes rank-shift {
  0%, 100% { background-position: 0% 40%, 0% 80%, 0% 50%; }
  50% { background-position: 100% 60%, 80% 20%, 100% 50%; }
}

@keyframes rank-spark {
  0%, 100% { opacity: 0.35; transform: scale(0.7); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes rank-glint {
  0%, 100% { transform: translateX(-30%) rotate(18deg); opacity: 0; }
  45% { opacity: 1; }
  70% { transform: translateX(180%) rotate(18deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .rank-badge,
  .rank-chip,
  .rank-badge::before,
  .rank-badge::after,
  .rank-chip::after {
    animation: none;
  }
}

.google-slot {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

#profile-note a { color: inherit; }

.lobby-brand { text-align: center; }

.lobby-brand h1 img {
  height: clamp(36px, 8vw, 56px);
  margin: 8px auto 0;
}

.lobby-as {
  margin: 16px 0;
  text-align: center;
  font-weight: 700;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lobby-actions button { width: 100%; }

.lobby-actions .lobby-secondary {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 44px;
  font-weight: 700;
}

.lobby-actions .lobby-list {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 999px;
  min-height: 44px;
  font-weight: 700;
}

.room-list, .history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 12px;
  max-height: 320px;
  overflow: auto;
}

.room-row, .history-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
  color: var(--ink);
}

.room-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.room-row b, .history-row b { font-weight: 700; }

.room-row > span:not(.room-main), .history-row span {
  color: var(--muted);
  font-size: 0.85rem;
}

.room-row:disabled { opacity: 0.45; }

.bet-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.bet-label b {
  color: var(--ink);
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
}

.lobby-card h2 { text-align: center; }

.lobby input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--ink);
}

.room-key-input {
  min-height: 64px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.42em;
  font-size: 1.7rem;
  font-weight: 700;
}

.lobby-status {
  min-height: 1.2em;
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.lobby-status[data-state="connected"] { color: #1d6b45; }
.lobby-status[data-state="connecting"] { color: #8a5a12; }
.lobby-status[data-state="disconnected"],
.lobby-status[data-state="error"] { color: #8c3d22; }

input:disabled, .segmented button:disabled { opacity: 0.55; }

@media (hover: hover) {
  .point:hover .pip { filter: brightness(1.08); }
}

@media (min-width: 981px) {
  body[data-compact="true"] main { grid-template-columns: minmax(0, 1fr) max-content; }
  body[data-compact="true"] .panel-wrap {
    width: fit-content;
    min-width: 0;
  }
  .panel-wrap { position: sticky; top: 12px; }
  .panel {
    max-height: calc(100dvh - 48px);
    overflow: auto;
  }
  .panel.compact { overflow: visible; max-height: none; }
}

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  body[data-phase="playing"] .panel-wrap,
  body[data-phase="over"] .panel-wrap {
    position: sticky;
    bottom: 12px;
    z-index: 3;
  }
  body[data-phase="playing"] .panel,
  body[data-phase="over"] .panel {
    box-shadow: 0 -8px 24px rgba(48, 28, 12, 0.12);
  }
  body[data-compact="true"] .panel-wrap {
    width: fit-content;
    min-width: 0;
    margin-left: auto;
  }
  .panel.compact .actions {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-width: 0;
  }
  .panel.compact #dice {
    flex-direction: row;
    width: fit-content;
  }
}

@media (max-width: 1040px) {
  header .side b { display: none; }
  header #btn-menu,
  header #btn-fullscreen,
  header #btn-rules {
    position: relative;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
  }
  header #btn-menu span,
  header #btn-fullscreen span,
  header #btn-rules span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
}

@media (max-width: 560px) {
  header {
    --header-cluster-gap: 8px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    justify-content: stretch;
    justify-items: center;
    align-items: center;
    column-gap: var(--header-cluster-gap);
    padding-inline: 12px;
    text-align: center;
  }
  .score {
    grid-column: 1;
    justify-self: end;
    min-width: 0;
  }
  header #btn-menu { grid-column: 2; }
  header:not(:has(.room-chip:not([hidden]))) .score,
  header:not(:has(.room-chip:not([hidden]))) #btn-menu,
  header:not(:has(.room-chip:not([hidden]))) #btn-fullscreen,
  header:not(:has(.room-chip:not([hidden]))) #btn-rules {
    grid-row: 2;
  }
  header:has(.room-chip:not([hidden])) .score,
  header:has(.room-chip:not([hidden])) #btn-menu,
  header:has(.room-chip:not([hidden])) #btn-fullscreen,
  header:has(.room-chip:not([hidden])) #btn-rules {
    grid-row: 3;
  }
  .side { min-width: 0; }
  .brand,
  .room-chip {
    grid-column: 1 / -1;
    margin-right: 0;
  }
  .brand h1 img { margin-inline: auto; }
  main { padding-inline: 12px; }
  .frame { padding: 6px; border-radius: 16px; }
  .felt {
    --bar: 20px;
    --off: 46px;
    gap: 4px;
    padding: 4px;
  }
  .metric-full { display: none; }
  .metric-initial { display: inline; }
  header .side b { max-width: 4.5rem; }
  header #btn-fullscreen,
  header #btn-rules {
    grid-column: 3;
    justify-self: start;
  }
  header #btn-rules {
    margin-left: calc(44px + var(--header-cluster-gap));
  }
  header #btn-menu span,
  header #btn-fullscreen span,
  header #btn-rules span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .die { width: 36px; height: 36px; }
}

@media (max-width: 405px) {
  .panel.compact #btn-roll,
  .panel.compact #btn-end,
  .panel.compact #btn-undo,
  .panel.compact #btn-reset {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
  }
}

body[data-fullscreen="true"] {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}

html:has(body[data-fullscreen="true"]) {
  height: 100%;
  background: var(--paper);
}

body[data-fullscreen="true"] .app {
  max-width: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-fullscreen="true"] header .brand,
body[data-fullscreen="true"] #btn-menu,
body[data-fullscreen="true"] #btn-rules,
body[data-fullscreen="true"] .legend {
  display: none;
}

body[data-fullscreen="true"] header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 10px 2px;
}

body[data-fullscreen="true"] .score { margin-right: auto; }

body[data-fullscreen="true"] .room-chip { margin-right: 0; }

body[data-fullscreen="true"] main {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  padding: 4px 8px 8px;
  overflow: hidden;
}

body[data-fullscreen="true"][data-phase="setup"] main {
  grid-template-columns: minmax(0, 1fr) min(280px, 36%);
}

body[data-fullscreen="true"] .table {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

body[data-fullscreen="true"] .board-scroll {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: safe center;
  padding: 0;
  overflow: hidden;
}

body[data-fullscreen="true"] .board-scroll.can-scroll { overflow: auto; }

body[data-fullscreen="true"] .frame {
  width: max-content;
  max-width: none;
  margin: 0;
}

body[data-fullscreen="true"] .app .panel-wrap {
  position: relative;
  top: auto;
  bottom: auto;
  align-self: center;
  justify-self: end;
  width: fit-content;
  min-width: 0;
  max-height: 100%;
  margin: 0;
  overflow: auto;
}

body[data-fullscreen="true"] .app .panel-wrap:has(.panel.compact) {
  overflow: visible;
  max-height: none;
}

body[data-fullscreen="true"][data-phase="setup"] .app .panel-wrap {
  align-self: stretch;
  width: auto;
  min-width: 0;
}

body[data-fullscreen="true"][data-phase="setup"] .panel {
  max-height: 100%;
  overflow: auto;
}

body[data-fullscreen="true"] .panel.compact .actions {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 0;
}

body[data-fullscreen="true"] .panel.compact #dice {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 0;
}

@media (orientation: portrait) and (min-height: 561px) and (max-width: 900px) and (hover: none) and (pointer: coarse) {
  body[data-fullscreen="true"] .side b {
    display: block;
    max-width: 7rem;
  }
}

@media (orientation: portrait) and (max-width: 900px) and (hover: none) and (pointer: coarse) {
  body[data-fullscreen="true"] {
    position: fixed;
    top: 0;
    left: 100%;
    width: 100dvh;
    height: 100dvw;
    min-height: 0;
    transform: rotate(90deg);
    transform-origin: top left;
    overflow: hidden;
  }
}

@media (max-height: 480px) {
  body[data-fullscreen="true"] .panel.compact .actions,
  body[data-fullscreen="true"] .panel.compact #dice {
    width: fit-content;
    min-width: 0;
  }
  body[data-fullscreen="true"] .panel.compact #btn-roll,
  body[data-fullscreen="true"] .panel.compact #btn-end,
  body[data-fullscreen="true"] .panel.compact #btn-undo,
  body[data-fullscreen="true"] .panel.compact #btn-reset {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
}

body[data-fs-rail="true"] .app {
  position: relative;
}

body[data-fs-rail="true"] header {
  justify-content: flex-start;
  padding-right: calc(var(--fs-rail, 0px) + 8px);
}

body[data-fs-rail="true"] .score { margin-right: 0; }

body[data-fs-rail="true"] header #btn-fullscreen { order: -1; }

body[data-fullscreen="true"][data-fs-rail="true"] main {
  overflow: visible;
  grid-template-columns: minmax(0, 1fr) var(--fs-rail, max-content);
}

body[data-fs-rail="true"] .app .panel-wrap {
  position: absolute;
  top: 0;
  right: 8px;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: var(--fs-rail, max-content);
  height: auto;
  max-height: none;
  margin: 0;
  overflow: auto;
}

body[data-fs-rail="true"] .app .panel-wrap:has(.panel.compact) {
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: none;
  overflow: visible;
}

body[data-fs-rail="true"] .panel.compact {
  width: fit-content;
  max-width: none;
  flex: 0 0 auto;
}

body[data-fullscreen="true"][data-fs-rail="true"][data-phase="setup"] .app .panel-wrap {
  width: min(280px, 36%);
  max-width: 280px;
}

body[data-fs-rail="true"][data-phase="setup"] .panel {
  margin-block: 10px;
  width: 100%;
  max-width: 100%;
  max-height: none;
  overflow: visible;
}

@media (prefers-reduced-motion: reduce) {
  .checker, .die { transition: none; animation: none; }
}
