:root {
  color-scheme: dark;
  --page: #15131e;
  --panel: #211d2b;
  --well: #191622;
  --line: #494056;
  --ink: #f8eedb;
  --muted: #bdafc8;
  --gold: #f7c870;
  --mint: #a4edd7;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font: 100%/1.45 system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, textarea, input { font: inherit; }
button, summary { cursor: pointer; }
button[aria-disabled="true"], button:disabled { cursor: default; }
button, summary, input, textarea, a { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }
a { color: var(--gold); text-underline-offset: 3px; }
h1, h2, p { margin: 0; }
h1, h2 { font-family: var(--mono); line-height: 1.12; }

.shell { width: min(100%, 72rem); margin-inline: auto; padding: 1.3rem 0.85rem 1rem; }
.masthead { display: flex; align-items: center; gap: 0.85rem; margin: 0.25rem 0 1.25rem; }
.masthead h1 { font-size: clamp(1.7rem, 5.4vw, 2.9rem); letter-spacing: -0.065em; }
.crest {
  flex: 0 0 2.6rem;
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 6px;
  background: #33283a;
  border: 2px solid #80644c;
  box-shadow: 0 3px 0 #0e0b14;
}
.crest i { background: #755b55; box-shadow: inset 0 -2px #574148; }
.crest i:nth-child(2) { background: var(--gold); box-shadow: inset 0 -2px #ab6c37; }
.layout { display: grid; gap: 1rem; align-items: start; }
.panel { min-width: 0; padding: 0.9rem; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px #100e17; }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.8rem; }
h2 { font-size: 1.13rem; letter-spacing: -0.035em; }
.count { color: var(--muted); font: 0.81rem var(--mono); text-align: right; }

.floor-scroll { background: var(--well); padding: 0.55rem; border: 1px solid #514356; max-height: 29rem; overflow: auto; }
.floor { position: relative; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.38rem; list-style: none; margin: 0; padding: 0 0 4px; }
.tile {
  --top: #423950;
  --bottom: #332c40;
  --edge: #6c5d79;
  --side: #292234;
  min-width: 0;
  min-height: 4.65rem;
  display: grid;
  grid-template-rows: 0.79rem auto 1fr;
  align-items: end;
  gap: 0.14rem;
  border: 1px solid var(--edge);
  padding: 0.3rem 0.22rem 0.36rem;
  background:
    linear-gradient(var(--edge) 0 0) 3px 3px / 3px 3px no-repeat,
    linear-gradient(var(--edge) 0 0) calc(100% - 3px) 3px / 3px 3px no-repeat,
    linear-gradient(var(--top), var(--bottom));
  box-shadow: inset 0 2px var(--top), inset 0 -2px var(--side), 0 3px var(--side);
  position: relative;
}
.tile-state { color: #e5d8ed; min-height: 0.79rem; padding-inline: 0.35rem; font: 0.65rem/1.1 var(--mono); }
.tile-avatar {
  display: block;
  justify-self: center;
  width: 2.65rem;
  height: 2.65rem;
  image-rendering: pixelated;
  filter: hue-rotate(var(--avatar-hue, 0deg)) drop-shadow(0 2px 1px #130d17);
}
.tile-name {
  position: relative;
  z-index: 2;
  text-align: center;
  min-width: 0;
  width: 100%;
  overflow-wrap: anywhere;
  font-weight: 650;
  font-size: clamp(0.76rem, 2.8vw, 0.92rem);
  line-height: 1.18;
  text-shadow: 0 1px 2px #15131e;
}
.tile[data-state="drawn"] { --top: #302b38; --bottom: #272331; --edge: #51475c; --side: #1c1825; color: #c8bfd1; }
.tile[data-state="active"] { --top: #345a54; --bottom: #254740; --edge: #a4edd7; --side: #203b35; }
.tile[data-state="winner"] { --top: #725127; --bottom: #50371f; --edge: #f7c870; --side: #3a2616; }
.tile[data-state="winner"] .tile-state { color: #fff0b7; font-weight: 700; }
.tile[data-state="active"], .tile[data-state="winner"] { outline: 1px solid var(--edge); z-index: 1; }
.tile[data-state="vacant"] { --top: #342d40; --bottom: #2c2537; --edge: #51465d; --side: #211a2b; }
.tile[data-state="vacant"]:nth-child(n+7) { display: none; }
.empty-floor {
  position: absolute;
  inset: 50% 0.35rem auto;
  z-index: 3;
  transform: translateY(-20%);
  width: fit-content;
  max-width: calc(100% - 0.7rem);
  margin: auto;
  padding: 0.26rem 0.8rem 0.45rem;
  text-align: center;
  background: #201a2a;
  border: 1px solid #756384;
  box-shadow: 0 3px #17111e;
}
.empty-floor strong, .empty-floor span { display: block; }
.empty-floor span { font-size: 0.79rem; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; color: var(--muted); font-size: 0.75rem; margin-top: 0.63rem; }
.legend span { display: flex; align-items: center; gap: 0.35rem; }
.legend i { display: block; width: 0.65rem; height: 0.65rem; border: 1px solid #9684a6; background: #51445f; }
.legend .legend-winner { border-color: var(--gold); background: #745127; }
.legend .legend-drawn { border-color: #87778e; background: #25212e; }
.result {
  display: grid;
  align-content: center;
  gap: 0.12rem;
  min-height: 5.1rem;
  margin-top: 0.75rem;
  padding: 0.55rem 0.7rem;
  background: #292334;
  border: 1px solid #53465f;
  overflow-wrap: anywhere;
}
.result-label { font: 0.75rem var(--mono); color: var(--muted); }
.result strong { font-size: clamp(1.08rem, 4.8vw, 1.7rem); line-height: 1.18; }
.result-detail { font-size: 0.78rem; color: var(--muted); }
.result.won { background: #392b22; border-color: #b8884e; }
.result.won .result-label, .result.won strong { color: var(--gold); }
.draw-actions { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0.55rem; margin-top: 0.75rem; }
button { min-height: 44px; padding: 0.42rem 0.7rem; font-weight: 720; border: 1px solid transparent; background: transparent; color: var(--ink); }
.primary { flex: 1 1 12rem; min-height: 52px; font: 700 1.05rem var(--mono); background: var(--gold); border-color: #ffdea0; color: #2a1b1c; box-shadow: 0 3px #946237; }
.primary:not([aria-disabled="true"]):hover { background: #ffda91; }
.primary:not([aria-disabled="true"]):active { translate: 0 2px; box-shadow: 0 1px #946237; }
.primary[aria-disabled="true"] { background: #443549; color: #d8cadf; border-color: #695470; box-shadow: 0 3px #2b2230; }
.secondary { background: #483854; border-color: #80698f; }
.quiet { color: #e0d3e6; border-color: #6b5777; }
.secondary:hover, .quiet:hover { background: #574365; }
.secondary:active, .quiet:active { background: #3c2e48; }
.history { margin-top: 0.75rem; }
summary { color: var(--muted); line-height: 44px; font-size: 0.86rem; width: fit-content; }
.history ol { margin: 0; padding-left: 1.7rem; color: var(--ink); overflow-wrap: anywhere; }
.history li { margin: 0.3rem 0; }

.roster form, dialog form { display: grid; gap: 0.5rem; }
.roster label, dialog label { font-size: 0.88rem; color: var(--muted); }
textarea, input {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  border: 1px solid #796987;
  border-radius: 0;
  padding: 0.6rem 0.65rem;
  background: var(--well);
}
textarea { resize: vertical; min-height: 5.5rem; }
input { min-height: 44px; }
.form-status { color: var(--mint); font-size: 0.84rem; margin-top: 0.45rem; overflow-wrap: anywhere; }
.form-status:empty { margin: 0; }
.seed-note { border: 1px solid #816649; padding: 0.55rem; margin-bottom: 0.75rem; }
.seed-note p { color: var(--gold); margin-bottom: 0.35rem; font-size: 0.85rem; }
.roster-list { padding: 0; list-style: none; margin: 0; max-height: 19rem; overflow: auto; overscroll-behavior: contain; }
.roster-list:not(:empty) { margin-top: 0.65rem; }
.roster-list li { display: flex; align-items: center; gap: 0.1rem; padding-right: 0.2rem; min-width: 0; border-top: 1px solid #463a51; }
.roster-entry { flex: 1; min-width: 0; padding: 0.25rem; overflow-wrap: anywhere; font-size: 0.9rem; }
.roster-entry small { display: block; color: var(--muted); font-size: 0.72rem; }
.row-action { min-width: 44px; color: #e4d1ed; font-size: 0.8rem; padding-inline: 0.38rem; }
.row-action:hover, .row-action:active { background: #493754; }
.row-action:focus-visible { outline-offset: -3px; }
.privacy { font-size: 0.77rem; color: var(--muted); margin-top: 0.85rem; }
footer { margin-top: 1.25rem; font-size: 0.75rem; color: var(--muted); }

dialog { width: min(26rem, calc(100vw - 2rem)); background: var(--panel); color: var(--ink); border: 1px solid #8c7699; padding: 1.15rem; }
dialog::backdrop { background: rgb(13 10 20 / 78%); }
dialog h2 { margin-bottom: 0.45rem; }
dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.65rem; flex-wrap: wrap; }
noscript { display: block; margin-top: 1rem; }

@media (min-width: 40rem) {
  .shell { padding: 2rem 1.5rem 1.25rem; }
  .panel { padding: 1.15rem; }
  .floor-scroll { padding: 0.7rem; }
  .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.56rem; }
  .tile[data-state="vacant"]:nth-child(n+7) { display: grid; }
}
@media (min-width: 57rem) {
  .shell { padding-top: 2.65rem; }
  .masthead { margin-bottom: 1.6rem; }
  .layout { grid-template-columns: minmax(0, 2.1fr) minmax(17rem, 1fr); gap: 1.3rem; }
  .tile { min-height: 5.4rem; padding-bottom: 0.5rem; }
  .tile-avatar { width: 3.15rem; height: 3.15rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
