/* Kości in the AleGry look: paper background, ink outlines, hard shadows; white dice on a green table. */
:root {
  --paper: #FFF7EA;
  --ink: #1D1533;
  --muted: #574D6E;
  --primary: #D93D22;
  --lemon: #FFD23F;
  --lemon-light: #FFF3C4;
  --mint: #20B69A;
  --plum-light: #E9E3FF;
  --sky-light: #E3F4FF;
  --tomato-light: #FFE1D9;
  --mint-light: #D7F5EC;
  --line: 3px solid var(--ink);
  --radius: 18px;
  --radius-sm: 10px;
  --font-heading: 'Fredoka', 'Trebuchet MS', 'Segoe UI', sans-serif;
  --font-body: 'Nunito', 'Segoe UI', Verdana, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { background: var(--paper); color: var(--ink); }
body { margin: 0; padding: 4px 8px 12px 4px; font: 16px/1.5 var(--font-body); }
h2 { font-family: var(--font-heading); line-height: 1.15; }
:focus-visible { outline: 3px solid #7A5CFA; outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.notice { margin: 1rem; padding: .75rem 1rem; border: 2px solid var(--ink); border-radius: var(--radius-sm); background: var(--lemon-light); }

.button { font: 700 1rem var(--font-heading); padding: .6rem 1.1rem; border: var(--line); border-radius: 999px; background: var(--primary); color: #fff; box-shadow: 3px 3px 0 var(--ink); cursor: pointer; }
.button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.button:disabled { opacity: .5; cursor: default; transform: none; box-shadow: 3px 3px 0 var(--ink); }
.button--ghost { background: #fff; color: var(--ink); }
.button--big { font-size: 1.15rem; padding: .75rem 1.6rem; }

.board { background: #fff; border: var(--line); border-radius: var(--radius); box-shadow: 5px 5px 0 var(--ink); overflow: hidden; }
.board__bar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: var(--plum-light); border-bottom: var(--line); }
.board__name { margin: 0; font: 700 1.15rem var(--font-heading); }
.board__counters { margin: 0; display: flex; gap: 1rem; font-weight: 700; font-size: .9rem; }
.board__counters strong { font: 700 1.15rem var(--font-heading); }

.tool { padding: .45rem .9rem; border: var(--line); border-radius: 999px; background: #fff; color: var(--ink); box-shadow: 2px 2px 0 var(--ink); font: 700 .95rem var(--font-heading); cursor: pointer; }
.tool:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.tool:disabled { opacity: .45; cursor: default; }
.tip { margin: .8rem 0 0; font-size: .85rem; color: var(--muted); }

.setup { padding: 1.25rem; text-align: center; }
.setup h2 { margin: 0 0 .8rem; font-size: 1.5rem; }
.players { display: grid; gap: .5rem; width: min(100%, 22rem); margin: 0 auto; }
.player { display: flex; align-items: center; gap: .4rem; }
.player input, .player__name { flex: 1; min-width: 0; padding: .55rem .8rem; border: var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink); font: 600 1rem var(--font-body); text-align: left; }
.player__name { background: var(--sky-light); }
.player__remove { width: 2.4rem; height: 2.4rem; border: var(--line); border-radius: 50%; background: #fff; color: var(--ink); font: 700 1.2rem/1 var(--font-heading); cursor: pointer; }
.setup__add { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin: .9rem 0 1.1rem; }

.game { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: flex-start; justify-content: center; padding: 1rem 1.25rem 1.25rem; }
.table { flex: 1 1 18rem; max-width: 24rem; padding: 1rem; border: var(--line); border-radius: var(--radius); background: #2E8C77; box-shadow: 4px 4px 0 var(--ink); text-align: center; }
.who { margin: 0 0 .8rem; padding: .35rem .8rem; border: var(--line); border-radius: 999px; background: #fff; font: 700 1rem var(--font-heading); }
.who:empty { visibility: hidden; }
.who--0 { background: var(--lemon-light); }
.who--1 { background: var(--sky-light); }
.who--2 { background: var(--tomato-light); }
.who--3 { background: var(--plum-light); }
.dice { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.die { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); aspect-ratio: 1; padding: 14%; border: var(--line); border-radius: 22%; background: #fff; box-shadow: 0 4px 0 var(--ink); cursor: pointer; }
.die span { display: grid; place-items: center; }
.die .pip::before { content: ''; width: 72%; aspect-ratio: 1; border-radius: 50%; background: var(--ink); }
.die.is-held { background: var(--lemon); transform: translateY(-6px); box-shadow: 0 10px 0 var(--ink); }
.die.is-blank .pip::before { background: #D9D3E6; }
.die.is-shaking { animation: shake .11s linear infinite; }
.die:disabled { cursor: default; }
@keyframes shake { 0% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } 100% { transform: rotate(-8deg); } }
.table__actions { margin: 1rem 0 0; }
.table .tip { color: #fff; }

.sheet-wrap { flex: 1 1 22rem; max-width: 34rem; overflow-x: auto; }
.sheet { width: 100%; border-collapse: separate; border-spacing: 0; border: var(--line); border-radius: var(--radius-sm); overflow: hidden; font-size: .92rem; }
.sheet th, .sheet td { padding: .3rem .5rem; border-bottom: 1px solid #DCD5E8; text-align: center; }
.sheet thead th { background: var(--ink); color: #fff; font: 700 .9rem var(--font-heading); max-width: 6rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet thead th.is-current { background: var(--primary); }
.sheet tbody th { text-align: left; font-weight: 700; }
.sheet tbody th small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); }
.sheet td { min-width: 3rem; font: 700 1rem var(--font-heading); }
.sheet td.is-current { background: var(--lemon-light); }
.sheet td.is-written { color: var(--ink); }
.sheet .sheet__last-upper th, .sheet .sheet__last-upper td { border-bottom: 2px solid var(--ink); }
.sheet .sheet__sum th, .sheet .sheet__sum td { background: #F6F3FB; font-size: .85rem; }
.sheet .sheet__bonus th, .sheet .sheet__bonus td { border-bottom: 2px solid var(--ink); }
.sheet .sheet__total th, .sheet .sheet__total td { background: var(--ink); color: #fff; border-bottom: 0; font: 700 1.05rem var(--font-heading); }
.pick { width: 100%; min-width: 2.4rem; padding: .2rem .3rem; border: 2px solid var(--ink); border-radius: 8px; background: #fff; color: #12806B; font: 700 1rem var(--font-heading); cursor: pointer; }
.pick:hover { background: var(--mint-light); }
.pick--zero { color: var(--muted); }

.result { display: none; margin: 0 1.25rem 1.25rem; padding: 1rem 1.25rem; border: var(--line); border-radius: var(--radius); background: var(--lemon); }
.result.is-visible { display: block; }
.result h2 { margin: 0 0 .5rem; font-size: 1.4rem; }
.ranking { margin: 0; padding-left: 1.5rem; font-size: 1.05rem; }
.ranking li { padding: .1rem 0; }
.result__note { margin: .5rem 0 0; font-weight: 800; }
.result__note:empty { display: none; }
.result__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .9rem 0 0; }

.mg-toast { position: fixed; left: 50%; top: 1rem; z-index: 50; max-width: calc(100% - 2rem); transform: translate(-50%, -6rem); visibility: hidden; padding: .6rem 1.1rem; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 800; text-align: center; transition: transform .25s ease, visibility .25s; }
.mg-toast.is-visible { transform: translate(-50%, 0); visibility: visible; }

@media (max-width: 640px) {
  .board__bar { padding: .6rem .75rem; }
  .game { padding: .75rem .5rem 1rem; gap: .9rem; }
  .table { padding: .75rem; }
  .dice { gap: .35rem; }
  .die { border-width: 2px; }
  .sheet { font-size: .82rem; }
  .sheet th, .sheet td { padding: .25rem .3rem; }
  .sheet tbody th small { display: none; }
  .sheet td { min-width: 2.4rem; }
  .result { margin: 0 .75rem 1rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
