:root {
  --bg-body-dark: #020617;
  --bg-body-light: #f9fafb;
  --bg-card-dark: #020617;
  --bg-card-light: #ffffff;
  --border-color-dark: #1f2937;
  --border-color-light: #e5e7eb;
  --text-primary-dark: #f9fafb;
  --text-primary-light: #020617;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--bg-body-dark);
  color: var(--text-primary-dark);
  -webkit-font-smoothing: antialiased;
}

html.light body {
  background-color: var(--bg-body-light);
  color: var(--text-primary-light);
}

body.menu-open {
  overflow: hidden;
}

.app-shell {
  min-height: 100vh;
  /* Weniger Außenabstand, um mehr Höhe zu nutzen */
  padding: 0.35rem 0.35rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card {
  background-color: var(--bg-card-dark);
  border-radius: 16px;
  border: 1px solid var(--border-color-dark);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  padding: 0.8rem 0.9rem 0.9rem;
  /* Karte füllt in mobilen Layouts die verfügbare Höhe besser aus */
  display: flex;
  flex-direction: column;
}

html.light .card {
  background-color: var(--bg-card-light);
  border-color: var(--border-color-light);
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.15);
}

.card-header h1,
.card-header h2,
.card-header h3 {
  margin: 0;
  letter-spacing: -0.03em;
}

.card-header p {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  opacity: 0.8;
}

.card-body {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  /* Body darf wachsen und bei Bedarf scrollen */
  flex: 1 1 auto;
  min-height: 0;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}

.form-row label {
  font-size: 0.95rem;
}

.form-row input[type="range"] {
  width: 100%;
}

.range-value {
  font-size: 0.85rem;
  opacity: 0.9;
}

#players-config {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.player-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.player-row input[type="text"] {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border-color-dark);
  background: rgba(15, 23, 42, 0.8);
  color: inherit;
}

html.light .player-row input[type="text"] {
  background: #f9fafb;
  border-color: var(--border-color-light);
}

.player-row label {
  font-size: 0.8rem;
  white-space: nowrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: linear-gradient(135deg, #111827, #020617);
  color: #e5e7eb;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease-out;
}

.button:hover {
  border-color: rgba(249, 115, 22, 0.8);
  box-shadow: 0 10px 30px rgba(248, 113, 22, 0.35);
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
  box-shadow: none;
}

.button.primary-button {
  background: radial-gradient(circle at 10% 0, #f97316, #ea580c);
  border-color: rgba(248, 113, 22, 0.9);
  color: #0b1120;
}

html.light .button {
  background: linear-gradient(135deg, #f9fafb, #e5e7eb);
  color: #0f172a;
}

.button:disabled,
.button[disabled] {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

/* Top actions (Fullscreen, Menü) – angelehnt an G.Vocabulary */
.top-actions-zone {
  position: fixed;
  top: 0;
  right: 0;
  width: 90px;
  height: 70px;
  z-index: 1200;
}

.top-left-actions {
  position: fixed;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  gap: 0.4rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: all 0.2s ease-out;
  z-index: 1210;
}

.top-left-actions.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Wenn das Seitenmenü offen ist, sollen die Buttons verschwinden */
body.menu-open .top-left-actions {
  opacity: 0 !important;
  pointer-events: none !important;
  display: none !important;
}

body.menu-open .top-actions-zone {
  pointer-events: none !important;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.85);
  color: #e5e7eb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease-out;
}

.icon-button .icon {
  font-size: 1rem;
}

.icon-button svg.icon {
  width: 20px;
  height: 20px;
}

.icon-button:hover {
  background: rgba(30, 64, 175, 0.9);
  border-color: rgba(59, 130, 246, 0.9);
}

html.light .icon-button {
  background: rgba(248, 250, 252, 0.9);
  border-color: rgba(148, 163, 184, 0.7);
  color: #0f172a;
}

html.light .icon-button:hover {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.4);
}

.fullscreen-button.fullscreen-active {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.6);
}

/* Overlay & Seitenmenü – angelehnt an G.Vocabulary */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1090;
}

#menu {
  position: fixed;
  right: 0;
  top: 0;
  width: min(320px, 88vw);
  height: 100%;
  background: radial-gradient(circle at top left, #1e293b 0, #020617 55%, #020617 100%);
  color: #f9fafb;
  transform: translateX(100%);
  transition: transform 0.28s ease-out;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  padding-bottom: 1rem;
  overflow-y: auto;
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.6);
}

#menu.open {
  transform: translateX(0);
}

.side-menu-header {
  padding: 0.75rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.12), transparent);
  border-bottom: 1px solid rgba(55, 65, 81, 0.9);
  flex-shrink: 0;
}

.side-menu-header h3 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.03em;
}

.side-menu-header .header-actions {
  display: flex;
  gap: 0.45rem;
}

#menu .side-menu-header .icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

html.light #menu {
  background: radial-gradient(circle at top left, #eff6ff 0, #ffffff 45%, #f1f5f9 100%);
  color: #0f172a;
  border-left: 1px solid rgba(148, 163, 184, 0.6);
}

.buttonMenu {
  width: calc(100% - 1.6rem);
  margin: 0.4rem 0.8rem 0;
  border-radius: 10px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  background: radial-gradient(circle at top left, rgba(249, 115, 22, 0.16), rgba(15, 23, 42, 0.9));
  color: inherit;
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease-out;
}

.buttonMenu.menu-standalone {
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.22), rgba(15, 23, 42, 0.98));
}

.buttonMenu:hover {
  transform: translateY(-1px);
  border-color: rgba(249, 115, 22, 0.95);
  box-shadow: 0 10px 30px rgba(248, 113, 22, 0.4);
}

html.light .buttonMenu {
  background: linear-gradient(135deg, #f1f5f9, #e5e7eb);
  border-color: rgba(148, 163, 184, 0.9);
}

.menu-category {
  display: flex;
  flex-direction: column;
  margin-top: 0.6rem;
}

.menu-category-header {
  width: calc(100% - 1.6rem);
  margin: 0 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.75);
  background: linear-gradient(135deg, #f97316, #ec4899);
  color: #0b1120;
  padding: 0.6rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(248, 113, 22, 0.55);
}

.menu-category-header .menu-category-arrow {
  font-size: 0.9rem;
  transition: transform 0.18s ease-out;
}

.menu-category-arrow.expanded {
  transform: rotate(90deg);
}

.menu-submenu {
  display: none;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.25rem;
}

.menu-submenu.open {
  display: flex;
}

/* Settings-Overlay (vereinfacht) */
.settings-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.82);
  z-index: 1200;
}

.settings-overlay[hidden] {
  display: none !important;
}

.settings-content {
  width: min(480px, 92vw);
  max-height: 85vh;
  background: radial-gradient(circle at top left, #111827, #020617 60%);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.75);
  padding: 1rem 1.15rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

html.light .settings-content {
  background: linear-gradient(135deg, #f9fafb, #e5e7eb);
}

.settings-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.settings-body {
  margin-top: 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.settings-footer {
  margin-top: 0.6rem;
  display: flex;
  justify-content: flex-end;
}

/* Spiel-Layout */
.game-header-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.game-header-main h2 {
  font-size: 1.1rem;
}

.game-header-sub {
  margin-top: 0.25rem;
  font-size: 0.85rem;
  opacity: 0.8;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1 1 auto;
  min-height: 0;
}

.dice-section,
.score-options-section,
.scoreboard-section {
  padding: 0.6rem 0.4rem 0.1rem;
  border-radius: 12px;
  border: 1px solid rgba(31, 41, 55, 0.7);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 0.9), #020617);
}

.dice-section h3,
.score-options-section h3,
.scoreboard-section h3 {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.9;
}

html.light .dice-section,
html.light .score-options-section,
html.light .scoreboard-section {
  background: linear-gradient(145deg, #f9fafb, #e5e7eb);
  border-color: rgba(148, 163, 184, 0.8);
}

.dice-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.die {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  perspective: 600px; /* 3D-Raum für den Würfel */
}

.die-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.4s ease-out;
}

.die-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 600;
  color: #0f172a;
  background: radial-gradient(circle at 30% 20%, #f9fafb, #e5e7eb);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.9);
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.55);
}

.die-face.front {
  transform: translateZ(27px);
}

.die-face.back {
  transform: rotateY(180deg) translateZ(27px);
}

.die-face.right {
  transform: rotateY(90deg) translateZ(27px);
}

.die-face.left {
  transform: rotateY(-90deg) translateZ(27px);
}

.die-face.top {
  transform: rotateX(90deg) translateZ(27px);
}

.die-face.bottom {
  transform: rotateX(-90deg) translateZ(27px);
}

/* Endausrichtung je Augenzahl (sichtbare Vorderseite) */
.die-inner.value-1 {
  transform: rotateX(0deg) rotateY(0deg);
}

.die-inner.value-2 {
  transform: rotateY(-90deg);
}

.die-inner.value-3 {
  transform: rotateY(180deg);
}

.die-inner.value-4 {
  transform: rotateY(90deg);
}

.die-inner.value-5 {
  transform: rotateX(-90deg);
}

.die-inner.value-6 {
  transform: rotateX(90deg);
}

/* Hover-Effekt ohne Änderung der Orientierung/Zahl */
.die:hover .die-face {
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.75);
}

.die.held {
  /* Hervorhebung über äußeren Rahmen */
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.die-locked {
  opacity: 0.6;
  cursor: default;
}

.die-inner.rolling {
  /* 3D-Rotation, während gewürfelt wird – zeigt verschiedene Seiten */
  animation: dice-roll-3d 0.6s linear infinite;
}

@keyframes dice-roll-3d {
  0% {
    transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
  }
  25% {
    transform: rotateX(180deg) rotateY(90deg) rotateZ(15deg);
  }
  50% {
    transform: rotateX(360deg) rotateY(180deg) rotateZ(-10deg);
  }
  75% {
    transform: rotateX(540deg) rotateY(270deg) rotateZ(20deg);
  }
  100% {
    transform: rotateX(720deg) rotateY(360deg) rotateZ(0deg);
  }
}

.score-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 180px;
  overflow-y: auto;
}

.score-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.9);
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 0.96), #020617);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.16s ease-out;
  color: #e5e7eb;
}

.score-option:hover {
  border-color: rgba(249, 115, 22, 1);
  background: radial-gradient(circle at top left, rgba(249, 115, 22, 0.55), rgba(15, 23, 42, 0.98));
  transform: translateY(-1px);
}

.score-option.zero-score {
  opacity: 0.85;
}

.score-option .score-label {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.score-option .score-points {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.8;
}

/* Besserer Kontrast im Light-Mode */
html.light .score-option {
  background: linear-gradient(135deg, #f8fafc, #e5e7eb);
  border-color: rgba(148, 163, 184, 1);
  color: #020617;
}

html.light .score-option:hover {
  background: linear-gradient(135deg, #fed7aa, #f97316);
  border-color: #c2410c;
  color: #111827;
}

.scoreboard-wrapper {
  /* Mehr dynamische Höhe, nutzt verbleibenden Platz besser aus */
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.scoreboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.scoreboard th,
.scoreboard td {
  padding: 0.25rem 0.25rem;
  border-bottom: 1px solid rgba(31, 41, 55, 0.7);
  text-align: right;
  white-space: nowrap;
}

.scoreboard th:first-child,
.scoreboard td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: rgba(15, 23, 42, 0.98);
}

html.light .scoreboard th:first-child,
html.light .scoreboard td:first-child {
  background: #f9fafb;
}

.scoreboard thead th {
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.98);
  z-index: 1;
}

html.light .scoreboard thead th {
  background: #f9fafb;
}

.scoreboard .current-player-col {
  background: rgba(56, 189, 248, 0.12);
}

.scoreboard .category-taken {
  color: rgba(249, 250, 251, 0.85);
}

html.light .scoreboard .category-taken {
  color: #111827;
}

.scoreboard .summary-row {
  font-weight: 600;
  background: rgba(15, 23, 42, 0.9);
}

html.light .scoreboard .summary-row {
  background: #e5e7eb;
}

.scoreboard .winner-cell {
  background: rgba(34, 197, 94, 0.16);
  font-weight: 700;
}

/* Responsive */
@media (min-width: 768px) {
  .app-shell {
    padding: 0.75rem 0.75rem 0.9rem;
  }

  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr);
    grid-auto-rows: auto;
  }
}

@media (min-width: 1024px) {
  .game-layout {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    grid-template-areas:
      "dice scoreboard"
      "options scoreboard";
  }

  .dice-section {
    grid-area: dice;
  }

  .score-options-section {
    grid-area: options;
  }

  .scoreboard-section {
    grid-area: scoreboard;
  }
}

/* Print/PDF Export */
@media print {
  body {
    background: #ffffff;
  }

  .top-actions-zone,
  .top-left-actions,
  #menu,
  #overlay,
  .settings-overlay,
  #setup-screen {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .card {
    box-shadow: none;
    border-radius: 0;
    border: none;
  }

  .dice-section,
  .score-options-section {
    display: none;
  }

  .scoreboard-section {
    border: none;
    background: #ffffff;
  }

  .scoreboard-wrapper {
    max-height: none;
    overflow: visible;
  }
}

