:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #595959;
  --line: #767676;
  --accent: #0b4fa8;
  --error: #a30000;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #ededed;
    --muted: #b0b0b0;
    --line: #8a8a8a;
    --accent: #7ab5ff;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.5 system-ui, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

/* Nu e h1: fiecare ecran are propriul h1, iar două h1 pe pagină strică navigarea pe titluri. */
.brand { margin: 0; font-weight: 700; font-size: 1.25rem; }

nav ul { display: flex; flex-wrap: wrap; gap: 1rem; margin: 0; padding: 0; list-style: none; }

main { max-width: 44rem; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

h1 { font-size: 1.6rem; margin-top: 0; }
h2 { font-size: 1.25rem; }

a { color: var(--accent); }

/* Focus vizibil peste tot — pentru navigare la tastatură și pentru utilizatorii cu vedere parțială. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Titlurile primesc focus la schimbarea ecranului; conturul ar deruta, dar
   ascunderea completă a focusului ar fi o greșeală de accesibilitate. */
h1:focus { outline: none; }
h1:focus-visible { outline: 3px solid var(--accent); }

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

input[type="text"], input[type="password"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  width: min(100%, 22rem);
}

input[aria-invalid="true"] { border-color: var(--error); border-width: 2px; }

button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}
button[type="submit"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

fieldset { border: 1px solid var(--line); border-radius: 4px; margin: 1rem 0; }
legend { padding: 0 0.4rem; font-weight: 600; }

.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: 0.25rem; font-weight: 600; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0; }
.error { color: var(--error); font-weight: 600; margin: 0.25rem 0 0; }

.history { list-style: none; padding: 0; }
.hist-item { border: 1px solid var(--line); border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 0.75rem; }
.hist-line { margin: 0 0 0.25rem; }
.hist-scores { margin: 0; color: var(--muted); }

.games { list-style: none; padding: 0; }
.games li { border: 1px solid var(--line); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.games h2 { margin-top: 0; }

#board { margin-bottom: 2rem; }

/* Bara de sus: starea turei la stânga, butonul de culori la dreapta. */
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.turn { font-weight: 600; font-size: 1.15rem; margin: 0; }
.gear-btn { flex: none; padding: 0.6rem 1rem; font-weight: 600; }

/* ------------------------------------------------------------------ zaruri */

/* Suprafața de joc: foarte închisă, cu zarurile mari. Cele trei culori vin din
   variabilele setate de JS (--surface, --die, --pip), ca să fie schimbabile de user. */
.dice-surface {
  --surface: #0b0b0d;
  --die: #ffd400;
  --pip: #111114;
  background: var(--surface);
  border-radius: 14px;
  padding: clamp(0.5rem, 2.5vw, 1.1rem);
  /* Trei pe rând: șase zaruri stau pe două rânduri, ca să fie mult mai mari. */
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.4rem, 2vw, 0.9rem);
  justify-content: center;
  align-content: center;
  min-height: 6rem;
}

/* Fiecare zar: cifra deasupra, fața cu puncte dedesubt. Lățime fixă la ~o treime, deci
   trei încap pe un rând și al patrulea trece pe rândul următor. */
.die-cell { flex: 0 0 auto; width: min(30%, 7rem); display: flex; flex-direction: column; align-items: center; gap: 0.3rem; }

/* Când e rândul tău, zarurile se pot atinge ca să iei o combinație. */
.dice-surface.playable .die-cell { cursor: pointer; }
.dice-surface.playable .die-cell:active .die { transform: scale(0.94); }
@media (hover: hover) {
  .dice-surface.playable .die-cell:hover .die { outline: 3px solid var(--die); outline-offset: 3px; }
}
.die-value {
  color: var(--die);
  font-weight: 800;
  font-size: clamp(1.2rem, 5vw, 2.2rem);
  line-height: 1;
}

.die {
  width: 100%;
  aspect-ratio: 1;
  background: var(--die);
  border-radius: 16%;
  padding: 12%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.08s ease;
}
.pip { border-radius: 50%; }
.pip.on { background: var(--pip); }

.dice-empty { color: var(--muted); font-size: 1.1rem; margin: auto; }

/* --------------------------------------------------------------- mod simplu */

/* Vedere curată pentru slab-văzători: un singur rând de cifre în loc de zaruri
   desenate, iar meniul arată doar punctajul. Culorile alese de user se păstrează. */
.simple-mode .dice-surface { min-height: 3.5rem; padding: 0.6rem 0.9rem; }
.simple-digits {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: clamp(0.6rem, 3vw, 1.4rem);
  width: 100%;
}
.simple-digit {
  color: var(--die);
  font-weight: 800;
  font-size: clamp(2rem, 10vw, 3.2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.dice-surface.playable .simple-digit { cursor: pointer; }
@media (hover: hover) {
  .dice-surface.playable .simple-digit:hover { text-decoration: underline; }
}
/* Rândul de opțiuni în mod simplu: punctajul mare și lizibil. */
.menu-take-simple .simple-score { font-size: 1.3rem; font-weight: 700; }

/* ------------------------------------------------------------------ meniul */

#menu { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; }

#menu [role="menuitem"] {
  text-align: left;
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1.1rem;
  min-height: 3rem; /* țintă de atins comodă pe telefon */
}
/* Prima combinație — cea mai valoroasă — subliniată discret. */
#menu .menu-take:first-child { border-color: var(--accent); border-width: 2px; }

/* „Salvează”: fracția mare, roșu cât n-ai destul, verde când poți. */
.bank-action { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.action-value { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.bank-wait { border-color: #d13b3b; color: #ff6b6b; }
.bank-wait .action-value { color: #ff6b6b; }
.bank-ok { border-color: #2ea043; color: #56d364; }
.bank-ok .action-value { color: #56d364; }

/* „Aruncă”: pus deoparte, cu spațiu deasupra, ca să nu-l atingi din greșeală. Mare și clar. */
.roll-action {
  margin-top: 1.25rem;
  padding: 1.1rem 1rem;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.roll-action[aria-disabled="true"] { background: transparent; color: var(--muted); }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }
[aria-disabled="true"] { opacity: 0.55; }

/* Zarul de probă din panoul de culori. */
.preview-wrap { margin: 0.75rem 0; }
.dice-surface.preview { min-height: auto; max-width: 12rem; margin: 0 auto; }
.preset-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.preset-list button { flex: 1 1 8rem; }
.dialog input[type="color"] { width: 4rem; height: 2.4rem; padding: 0.15rem; vertical-align: middle; }

/* Comutatorul de mod simplu: bifa mare, eticheta lângă ea. */
.field-check { display: flex; align-items: center; gap: 0.6rem; }
.field-check input[type="checkbox"] { width: 1.5rem; height: 1.5rem; flex: none; }
.field-check label { font-size: 1.1rem; }

.backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  z-index: 20;
}
.dialog {
  background: var(--bg); color: var(--fg);
  border: 2px solid var(--line); border-radius: 8px;
  padding: 1.25rem;
  max-width: 30rem; width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.dialog h2 { margin-top: 0; }
.dialog h3 { margin-bottom: 0.4rem; }
.standings { margin: 0 0 1rem; padding-left: 1.5rem; }
.standings li { padding: 0.15rem 0; font-weight: 600; }
.standings li:first-child { color: var(--accent); } /* câștigătorul */
.awards { margin: 0 0 1rem; padding-left: 1.2rem; }
.awards li { padding: 0.2rem 0; }
.dialog input[type="number"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); color: inherit;
  width: 8rem;
}

table { border-collapse: collapse; margin: 1rem 0; }
caption { text-align: left; font-weight: 600; margin-bottom: 0.4rem; }
th, td { border: 1px solid var(--line); padding: 0.4rem 0.8rem; text-align: left; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.6rem 1rem;
  background: var(--bg);
  border: 2px solid var(--accent);
  z-index: 10;
}
.skip-link:focus { left: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* În timpul jocului antetul (brand + navigare) dispare — rămân doar cele trei butoane
   din bara jocului. „Meniu" (aria-expanded) îl aduce înapoi punând .show-chrome pe body. */
body.in-game .skip-link,
body.in-game header { display: none; }
body.in-game.show-chrome header { display: block; }
