:root {
  --game-stage-gap: 1.5rem;
}

/* Unified game detail layout */
.game-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.game-layout__header {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 2vw, 1.75rem);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.game-layout__header--with-media {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(240px, 1fr);
  gap: clamp(1rem, 2vw, 1.5rem);
  align-items: start;
}

.game-layout__header-content {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.game-layout__eyebrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.game-layout__title {
  margin: 0;
  font-size: clamp(1.4rem, 2.4vw, 1.9rem);
  color: var(--color-primary-dark);
}

.game-layout__description {
  margin: 0.15rem 0 0;
  color: var(--color-muted);
}

.game-layout__chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0;
  margin: 0.35rem 0 0;
  list-style: none;
}

.game-layout__chip-row .chip {
  margin: 0;
}

.game-layout__meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 0.4rem;
}

.game-layout__meta-item {
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.game-layout__meta-item dt {
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.game-layout__meta-item dd {
  margin: 0.15rem 0 0;
  font-weight: 700;
  color: var(--color-text);
}

.game-layout__media {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.45), rgba(78, 205, 196, 0.18));
  box-shadow: var(--shadow-soft);
  aspect-ratio: 16 / 9;
}

.game-layout__media video,
.game-layout__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.game-layout__stage {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--game-stage-gap);
  align-items: flex-start;
}

.game-layout__stage-play,
.game-layout__stage-control {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 2vw, 1.75rem);
  box-shadow: var(--shadow-soft);

  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.game-layout__stage-play {
  min-height: 400px;
}

.stage-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  border: 1px solid #d7e3f7;
  background: linear-gradient(180deg, #eef4ff 0%, #f8fbff 60%, #eef4ff 100%);
  box-shadow: inset 0 8px 18px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.game-layout__stage-control {
  position: sticky;
  top: 96px;

  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.game-layout__stage-control .control-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.game-layout__stage-control .control-wrapper[hidden] {
    display: none;
  }
  
.game-layout__stage-control .button-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }


.game-layout__stage-control button {
  border: none;
  border-radius: 16px;
  padding: 0.65rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  transition: transform 0.2s ease, background 0.2s ease;
}
.game-layout__stage-control button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }
.game-layout__stage-control button:hover,
.game-layout__stage-control button:focus-visible {
  transform: translateY(-2px);
  background: var(--color-primary-dark);
  outline: none;
}

.game-layout__stage-control button.button-secondary {
	color: var(--color-primary);
    background: transparent;
    border: 1px solid rgba(15, 23, 42, 0.15);
}



.game-layout__stage-control .slider {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.game-layout__stage-control .slider label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-layout__stage-control .slider input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
}

.game-layout__stage-control .slider-value {
    font-size: 0.9rem;
    color: var(--fraction-chart-accent-strong);
  }



.game-layout__stage-control .check-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
}

.game-layout__stage-control .check-option input[type="checkbox"],
.game-layout__stage-control .check-option input[type="radio"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--color-primary);
  cursor: pointer;
}


.game-layout__stage-control .toggle {
    display: inline-flex;
    gap: 0.35rem;
    background: #eef0fc;
    padding: 0.35rem;
    border-radius: 999px;
    width: fit-content;
  }
.game-layout__stage-control .toggle button {
    border: none;
    background: transparent;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    color: var(--fraction-chart-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
  }
.game-layout__stage-control .toggle button.is-active {
    background: #fff;
    color: var(--fraction-chart-accent-strong);
    box-shadow: 0 4px 12px rgba(66, 84, 180, 0.2);
  }


.game-layout__text {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.6rem;
  align-items: stretch;
}

.game-layout__text .game-layout__text-card {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(15, 23, 42, 0.08);
  padding: clamp(1.35rem, 2vw, 1.9rem);
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  scroll-margin-top: 6rem;
  overflow: hidden;
}

.game-layout__text .game-layout__text-card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--color-primary), rgba(84, 104, 255, 0.3));
  pointer-events: none;
  z-index: 0;
}

.game-layout__text .game-layout__text-card h2,
.game-layout__text .game-layout__text-card h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

.game-layout__text .game-layout__text-card h2 {
  font-size: clamp(1.2rem, 2.1vw, 1.55rem);
  color: var(--color-primary-dark);
  text-transform: none;
}

.game-layout__text .game-layout__text-card h2::after {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  border-radius: 999px;
  margin-top: 0.55rem;
  background: rgba(66, 84, 180, 0.35);
}

.game-layout__text .game-layout__text-card h3 {
  font-size: clamp(1.05rem, 1.9vw, 1.3rem);
  color: var(--fraction-chart-accent-strong);
  text-transform: none;
  letter-spacing: 0.04em;
}

.game-layout__text .game-layout__text-card h3::after {
  content: "";
  display: inline-block;
  width: 32px;
  height: 2px;
  border-radius: 999px;
  margin-left: 0.65rem;
  background: rgba(15, 23, 42, 0.2);
  vertical-align: middle;
}

.game-layout__text .game-layout__text-card > * {
  position: relative;
  z-index: 1;
}

.game-layout__text .game-layout__text-card > :not(h2):not(h3) {
  margin: 0;
  max-width: 65ch;
  width: min(100%, 65ch);
  line-height: 1.7;
  color: var(--color-text);
}

.game-layout__text .game-layout__text-card > * + * {
  margin-top: 0.9rem;
}

.game-layout__text .game-layout__text-card p:last-child {
  margin-bottom: 0;
}

.game-layout__text .game-layout__text-card ul,
.game-layout__text .game-layout__text-card ol {
  padding-left: 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.game-layout__text .word-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  line-height: 1.6;
}

.game-layout__text .word-table td,
.game-layout__text .word-table th {
  padding: 0.1rem 0.1rem;
  text-align: left;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.game-layout__text .word-table tr:last-child td {
  border-bottom: none;
}

.game-layout__text .word-table-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-layout__text .word-table-clip {
  max-height: 15rem;
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1) 70%, rgba(0, 0, 0, 0.05));
}

.game-layout__text .word-table-wrap.is-open .word-table-clip {
  max-height: none;
  mask-image: none;
}

.game-layout__text .word-table-toggle {
  align-self: flex-start;
  border: 1px solid rgba(15, 23, 42, 0.15);
  background: #fff;
  color: var(--color-primary-dark);
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(15, 23, 42, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.game-layout__text .word-table-toggle:hover,
.game-layout__text .word-table-toggle:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.12);
  outline: none;
}

.game-layout__text .game-layout__text-card--full {
  grid-column: 1 / -1;
}

.game-layout__text .game-layout__text-card .card-grid {
  margin-top: 0.5rem;
}

/* Reusable dice face styles */
.dice-face {
  --dice-face-size: clamp(42px, 8vw, 56px);
  --dice-face-bg: #fff;
  --dice-face-border-color: rgba(12, 24, 32, 0.1);
  --dice-face-shadow: 0 8px 16px rgba(15, 23, 42, 0.15);
  --dice-face-padding: 6px;
  --dice-face-pip-color: #3645c5;

  width: var(--dice-face-size);
  height: var(--dice-face-size);
  border-radius: 14px;
  background: var(--dice-face-bg);
  border: 2px solid var(--dice-face-border-color);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: var(--dice-face-padding);
  box-shadow: var(--dice-face-shadow);
  position: relative;
}

.dice-face[data-size="compact"] {
  --dice-face-size: clamp(34px, 6vw, 40px);
  --dice-face-padding: 4px;
  border-radius: 12px;
}

.dice-face .pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dice-face-pip-color);
  opacity: 0;
  transition: opacity 0.1s ease;
  justify-self: center;
  align-self: center;
}

.dice-face .pip.pip--tl { grid-area: 1 / 1; }
.dice-face .pip.pip--tr { grid-area: 1 / 3; }
.dice-face .pip.pip--ml { grid-area: 2 / 1; }
.dice-face .pip.pip--center { grid-area: 2 / 2; }
.dice-face .pip.pip--mr { grid-area: 2 / 3; }
.dice-face .pip.pip--bl { grid-area: 3 / 1; }
.dice-face .pip.pip--br { grid-area: 3 / 3; }

.dice-face[data-value="1"] .pip.pip--center,
.dice-face[data-value="3"] .pip.pip--center,
.dice-face[data-value="5"] .pip.pip--center {
  opacity: 1;
}

.dice-face[data-value="2"] .pip.pip--tl,
.dice-face[data-value="3"] .pip.pip--tl,
.dice-face[data-value="4"] .pip.pip--tl,
.dice-face[data-value="5"] .pip.pip--tl,
.dice-face[data-value="6"] .pip.pip--tl,
.dice-face[data-value="4"] .pip.pip--br,
.dice-face[data-value="5"] .pip.pip--br,
.dice-face[data-value="6"] .pip.pip--br {
  opacity: 1;
}

.dice-face[data-value="2"] .pip.pip--br,
.dice-face[data-value="3"] .pip.pip--br,
.dice-face[data-value="4"] .pip.pip--tr,
.dice-face[data-value="5"] .pip.pip--tr,
.dice-face[data-value="6"] .pip.pip--tr,
.dice-face[data-value="4"] .pip.pip--bl,
.dice-face[data-value="5"] .pip.pip--bl,
.dice-face[data-value="6"] .pip.pip--bl {
  opacity: 1;
}

.dice-face[data-value="6"] .pip.pip--ml,
.dice-face[data-value="6"] .pip.pip--mr {
  opacity: 1;
}

@media (max-width: 1024px) {
  .game-layout__stage {
    grid-template-columns: 1fr;
  }

  .game-layout__stage-control {
    position: static;
  }

  .game-layout__header--with-media {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .game-layout__header {
    padding: 1rem;
    border-radius: var(--radius-md);
  }

  .game-layout__meta-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

}
