/* Elftausend — Spielseite (nutzt Tokens aus styles.css) */

:root {
  --elf-blue:        #2563eb;
  --elf-yellow:      #e9a53a;
  --elf-warn:        #d97706;
  --elf-gold-bg:     #fffbea;
  --elf-silver-bg:   #f7f7f7;
  --elf-bronze-bg:   #fdf4f0;
  --elf-gold-txt:    #b8860b;
  --elf-silver-txt:  #6e6e6e;
  --elf-bronze-txt:  #8b4513;
}

/* Hero ---------------------------------------------------------------- */
.elf-hero {
  background: var(--surface-container-low);
  padding-block: clamp(2rem, 5vw, 3.5rem) clamp(1.5rem, 4vw, 2.5rem);
}
.elf-hero .display-lg { margin: 0.75rem 0 0; }
.elf-hero .body-lg {
  max-width: 56ch;
  margin-top: 1rem;
  color: var(--on-surface-variant);
}

/* Game section -------------------------------------------------------- */
.elf-game {
  background: var(--surface-container);
  padding-block: clamp(2.5rem, 6vw, 4.5rem);
}
.elf-panel {
  background: var(--surface-container-lowest);
  border-radius: var(--radius-lg);
  padding: clamp(1.5rem, 4vw, 2.75rem);
  box-shadow: var(--shadow-soft);
  margin-bottom: 2rem;
}

/* Setup --------------------------------------------------------------- */
.elf-panel > .label-md { display: block; margin: 1.5rem 0 0.6rem; }
.elf-count {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.elf-countbtn {
  font: inherit;
  font-weight: 700;
  width: 3rem;
  height: 3rem;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--surface-container-highest);
  color: var(--on-surface);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.elf-countbtn:hover { transform: scale(1.05); }
.elf-countbtn.is-active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
  color: var(--on-primary);
}
.elf-names {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}
@media (min-width: 600px) {
  .elf-names { grid-template-columns: repeat(2, 1fr); }
}
.elf-nameinput,
.elf-submit input {
  font: inherit;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-container-highest);
  color: var(--on-surface);
  width: 100%;
}
.elf-nameinput:focus-visible,
.elf-submit input:focus-visible {
  outline: 2px solid rgba(202, 11, 25, 0.4);
  outline-offset: 0;
}

/* Board-Layout: Tabelle links, Spielplan rechts ----------------------- */
.elf-board-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Rechte Seite zentriert wie die Stage (kleine Bildschirme) */
.elf-board-right {
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

/* Runden-Punkte-Tabelle ---------------------------------------------- */
.elf-roundtable-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(5 * 2.5rem + 3.75rem);
  border-radius: var(--radius-sm);
  border: 1px solid var(--outline-variant);
  margin-bottom: 1.5rem;
}
.elf-roundtable {
  min-width: 100%;
  border-collapse: collapse;
}
.elf-roundtable thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-container);
  padding: 0.6rem 0.75rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  border-bottom: 2px solid var(--outline-variant);
}
.elf-roundtable thead th {
  min-width: 4.5rem;
  max-width: 8rem;
}
.elf-roundtable thead th:first-child {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}
.elf-roundtable thead th.is-current {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
  color: var(--on-primary);
}
.elf-roundtable-total {
  display: block;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.2;
}
.elf-roundtable tbody td {
  padding: 0.5rem 0.75rem;
  text-align: center;
  font-size: 0.875rem;
  border-top: 1px solid var(--outline-variant);
}
.elf-roundtable tbody td:first-child {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--on-surface-variant);
  letter-spacing: 0.05em;
}
.elf-roundtable tbody tr:nth-child(odd)  { background: var(--surface-container-low); }
.elf-roundtable tbody tr:nth-child(even) { background: var(--surface-container); }
.elf-roundtable .is-bust { color: var(--on-surface-variant); }

@media (min-width: 1200px) {
  .elf-board-layout {
    display: grid;
    grid-template-columns: fit-content(45%) minmax(0, 680px);
    gap: 2rem;
    justify-content: end;
  }
  .elf-board-right {
    position: sticky;
    top: 1rem;
    align-self: start;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
  }
  .elf-roundtable-wrap {
    max-height: calc(17 * 2.5rem + 3.75rem);
    margin-bottom: 0;
  }
  .elf-stage {
    margin-inline: 0;
  }
}

.elf-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: baseline;
  margin-bottom: 1rem;
  color: var(--on-surface-variant);
  font-size: 0.95rem;
}
.elf-meta strong {
  color: var(--inverse-surface);
  font-size: 1.15rem;
  margin-left: 0.35rem;
}

.elf-status {
  min-height: 1.6rem;
  margin: 0 0 1.25rem;
  font-weight: 600;
  color: var(--inverse-surface);
}

/* Dice ---------------------------------------------------------------- */
/* Spielbrett-Stage: festes Seitenverhaeltnis = Bildmasse 1600x1195,
   damit Becher/Flaechen-Prozentkoordinaten 1:1 aufs Bild mappen. */
.elf-stage {
  position: relative;
  width: 100%;
  max-width: 680px;
  margin: 0 auto 1.25rem;
  aspect-ratio: 1600 / 1195;
  background: url("/img/Elftau_Background.jpg") center / 100% 100% no-repeat;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.elf-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.elf-die {
  --pip: var(--inverse-surface);
  --rot: 0deg;
  --sc: 1;
  border: 0;
  background: var(--surface-container-lowest);
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  gap: 6%;
  border-radius: 16%;
  cursor: pointer;
  overflow: hidden;
}

/* Alle Wuerfel liegen absolut auf dem Brett (Mittelpunkt via translate).
   Freie Wuerfel etwas groesser; Slot-Wuerfel bekommen ihre Breite aus
   slotStyle() (JS) und passen damit auf die Ablage-Felder. */
.elf-stage .elf-die {
  position: absolute;
  /* Breite/Hoehe setzt JS in px (aus der Stage-Breite) – robust ggue.
     Grid-Min-Content-Effekten bei prozentualer Breite. */
  pointer-events: auto;
  transform: translate(-50%, -50%) rotate(var(--rot)) scale(var(--sc));
  transition:
    left 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.28s ease;
}
.elf-stage .elf-die.is-dealing { opacity: 0; }
.elf-stage .elf-die:hover:not(.is-sel):not(.elf-die--locked) {
  --sc: 1.08;
  z-index: 3;
}

.elf-die i {
  align-self: center;
  justify-self: center;
  width: 58%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pip);
  visibility: hidden;
}
.elf-die[data-v="1"] i:nth-child(5),
.elf-die[data-v="2"] i:nth-child(1), .elf-die[data-v="2"] i:nth-child(9),
.elf-die[data-v="3"] i:nth-child(1), .elf-die[data-v="3"] i:nth-child(5), .elf-die[data-v="3"] i:nth-child(9),
.elf-die[data-v="4"] i:nth-child(1), .elf-die[data-v="4"] i:nth-child(3), .elf-die[data-v="4"] i:nth-child(7), .elf-die[data-v="4"] i:nth-child(9),
.elf-die[data-v="5"] i:nth-child(1), .elf-die[data-v="5"] i:nth-child(3), .elf-die[data-v="5"] i:nth-child(5), .elf-die[data-v="5"] i:nth-child(7), .elf-die[data-v="5"] i:nth-child(9),
.elf-die[data-v="6"] i:nth-child(1), .elf-die[data-v="6"] i:nth-child(4), .elf-die[data-v="6"] i:nth-child(7), .elf-die[data-v="6"] i:nth-child(3), .elf-die[data-v="6"] i:nth-child(6), .elf-die[data-v="6"] i:nth-child(9) {
  visibility: visible;
}

/* Farb-Markierung (auch auf herausgelegten Wuerfeln beibehalten) */
.elf-die.is-blue   { outline: 3px solid var(--elf-blue);   outline-offset: 2px; }
.elf-die.is-red    { outline: 3px solid var(--primary);    outline-offset: 2px; }
.elf-die.is-yellow { outline: 3px solid var(--elf-yellow); outline-offset: 2px; }
/* getrennte Gruppe (z. B. Drilling teilweise weggelegt) -> gestrichelt */
.elf-die.is-dashed { outline-style: dashed; }
.elf-die.is-sel {
  box-shadow: var(--shadow-float);
  background: var(--secondary-container);
}
.elf-stage .elf-die.is-sel { --sc: 1.14; z-index: 4; }

/* Auf einem Ablage-Feld liegende Wuerfel (Breite kommt aus slotStyle) */
.elf-die--slot { box-shadow: 0 2px 7px rgba(57, 56, 50, 0.22); }
.elf-die.is-kept { cursor: pointer; }
.elf-stage .elf-die.is-kept:hover { --sc: 1.1; z-index: 4; }
/* locked = endgueltig, nicht mehr rueckholbar */
.elf-die--locked {
  cursor: default;
  opacity: 0.95;
}

/* Actions ------------------------------------------------------------- */
.elf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.elf-actions .btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
.elf-actions .btn-ghost { margin-left: auto; color: var(--on-surface-variant); }

/* Win panel ----------------------------------------------------------- */
#elf-win .headline-lg { margin: 0 0 1.5rem; }
.elf-submit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  max-width: 30rem;
  margin-bottom: 0.75rem;
}
.elf-submit input { flex: 1 1 12rem; }
.elf-submit .btn[disabled] { opacity: 0.45; cursor: not-allowed; }
#elf-submit-status { min-height: 1.4rem; color: var(--primary); font-weight: 600; }
.elf-win-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }

/* Placement row in round table */
.elf-roundtable tfoot tr.elf-placement-row td {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--on-surface-variant);
  border-top: 2px solid var(--outline-variant);
  padding-top: 0.6rem;
}

/* Highscore ----------------------------------------------------------- */
.elf-highscore {
  background: var(--surface-container-lowest);
  border-radius: var(--radius-lg);
  padding: clamp(1.5rem, 4vw, 2.75rem);
  box-shadow: var(--shadow-soft);
  margin-bottom: 2rem;
}
.elf-highscore .headline-lg { margin: 0; }
.elf-highscore .body-md { color: var(--on-surface-variant); margin: 0.4rem 0 1.25rem; }
.elf-localnote {
  color: var(--elf-warn);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 1rem;
}
.elf-table {
  width: 100%;
  border-collapse: collapse;
}
.elf-table th,
.elf-table td {
  text-align: left;
  padding: 0.7rem 0.75rem;
}
.elf-table thead th {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}
.elf-table tbody tr { background: var(--surface-container-low); }
.elf-table tbody tr:nth-child(2n) { background: var(--surface-container); }
.elf-table tbody td:first-child { font-weight: 800; color: var(--primary); width: 3rem; }
.elf-table tbody td:last-child { font-weight: 700; }
.elf-empty { color: var(--on-surface-variant); font-weight: 500; }

/* Rules --------------------------------------------------------------- */
.elf-rules {
  background: var(--surface-container-lowest);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-soft);
}
.elf-rules summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--inverse-surface);
  list-style: none;
}
.elf-rules summary::-webkit-details-marker { display: none; }
.elf-rules summary::before { content: "▸ "; color: var(--primary); }
.elf-rules[open] summary::before { content: "▾ "; }
.elf-rules .body-md {
  margin: 1rem 0 0.5rem;
  color: var(--on-surface-variant);
}
.elf-rules strong { color: var(--inverse-surface); }

@media (prefers-reduced-motion: reduce) {
  .elf-stage .elf-die { transition: none; }
  .elf-stage .elf-die:hover:not(.is-sel) { --sc: 1; }
}

/* Highscore link on game page */
.elf-scores-more { margin-top: 1rem; text-align: right; }

/* Debug mode indicator */
.elf-debug-flag { color: var(--elf-warn); font-weight: 700; }

/* Highscore page ------------------------------------------------------ */
.hs-layout {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-bottom: 2rem;
}
@media (min-width: 1024px) {
  .hs-layout {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    align-items: start;
    gap: 2.5rem;
  }
  .hs-right {
    position: sticky;
    top: 1rem;
  }
}
.hs-right {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.hs-right .elf-highscore,
.hs-left  .elf-highscore {
  margin-bottom: 0;
}
.hs-overflow { overflow-x: auto; }
.hs-table-wrap {
  overflow-y: auto;
  max-height: 36rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--outline-variant);
  margin-top: 0.75rem;
}
.hs-table-wrap .elf-table {
  border-radius: 0;
}
.hs-table-wrap .elf-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-container);
}
.hs-table td:nth-child(3),
.hs-table th:nth-child(3),
.hs-table td:nth-child(4),
.hs-table th:nth-child(4) {
  text-align: right;
}
.hs-table tbody td:last-child {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  white-space: nowrap;
}
.hs-table thead th:last-child {
  font-size: 0.62rem;
}

/* Top 1 / 2 / 3 medals — higher specificity beats :nth-child(odd/even) */
.elf-table tbody tr.hs-top1 { background: var(--elf-gold-bg); }
.elf-table tbody tr.hs-top2 { background: var(--elf-silver-bg); }
.elf-table tbody tr.hs-top3 { background: var(--elf-bronze-bg); }
.elf-table tbody tr.hs-top1 td:first-child { color: var(--elf-gold-txt);   font-weight: 800; font-size: 1.1rem; }
.elf-table tbody tr.hs-top2 td:first-child { color: var(--elf-silver-txt); font-weight: 800; font-size: 1.05rem; }
.elf-table tbody tr.hs-top3 td:first-child { color: var(--elf-bronze-txt); font-weight: 800; }
