.access-gate {
  position: fixed;
  z-index: 10000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  overflow: auto;
  background:
    radial-gradient(circle at 12% 15%, rgb(255 200 61 / 42%) 0 9rem, transparent 9.1rem),
    radial-gradient(circle at 88% 80%, rgb(66 211 173 / 30%) 0 11rem, transparent 11.1rem),
    linear-gradient(145deg, #f5f2ff, #fff8ed);
}

html.access-session-pending .access-gate {
  visibility: hidden;
}

.access-gate[hidden] {
  display: none;
}

body.access-locked {
  overflow: hidden;
}

body.access-locked > :not(.access-gate):not(script) {
  visibility: hidden;
}

.access-gate-card {
  width: min(100%, 28rem);
  padding: clamp(1.35rem, 6vw, 2.25rem);
  border: 2px solid rgb(98 82 245 / 18%);
  border-radius: 2rem;
  background: rgb(255 255 255 / 94%);
  box-shadow: 0 1.75rem 5rem rgb(61 48 135 / 20%);
  color: #18213d;
  text-align: center;
}

.access-gate-icon {
  display: grid;
  place-items: center;
  width: 5.5rem;
  aspect-ratio: 1;
  margin: 0 auto 1rem;
  border-radius: 1.6rem;
  background: linear-gradient(145deg, #ebe8ff, #fff1c7);
  font-size: 3rem;
}

.access-gate-card h1 {
  margin: 0;
  color: #18213d;
  font-size: clamp(1.8rem, 8vw, 2.65rem);
  line-height: 1.02;
}

.access-gate-card p {
  margin: 0.85rem 0 1.2rem;
  color: #68708b;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.45;
}

.access-gate-card label {
  display: block;
  margin-bottom: 0.5rem;
  color: #333b59;
  font-weight: 900;
}

#access-code-input {
  width: min(100%, 13rem);
  padding: 0.85rem 1rem;
  border: 2px solid #c9c5ff;
  border-radius: 1rem;
  background: white;
  color: #18213d;
  font: inherit;
  font-size: 1.7rem;
  font-weight: 950;
  letter-spacing: 0.4em;
  text-align: center;
}

#access-code-input:focus {
  border-color: #6252f5;
  outline: 4px solid rgb(98 82 245 / 16%);
}

#access-gate-error {
  min-height: 1.5em;
  margin: 0.65rem 0;
  color: #be123c;
  font-size: 0.9rem;
  font-weight: 850;
}

#access-gate-submit {
  width: 100%;
}

.parent-setting-card {
  margin: 1.25rem 0;
  padding: 1rem;
  border: 1px solid #c8c2ff;
  border-radius: 1.15rem;
  background: #f6f4ff;
  text-align: left;
}

.parent-setting-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.8rem;
  align-items: start;
}

.parent-setting-icon {
  font-size: 2rem;
  line-height: 1;
}

.parent-setting-card h3 {
  margin: 0;
  color: var(--app-ink);
  font-size: 1.1rem;
  font-weight: 950;
}

.parent-setting-card p {
  margin: 0.25rem 0 0;
  color: var(--app-muted);
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.35;
}

.timer-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6rem;
  gap: 0.65rem;
  align-items: end;
  margin-top: 0.9rem;
}

.timer-controls label {
  color: var(--app-ink);
  font-size: 0.86rem;
  font-weight: 850;
}

#play-timer-minutes {
  grid-row: 1 / span 2;
  grid-column: 2;
  width: 100%;
  padding: 0.72rem 0.55rem;
  border: 2px solid var(--app-line);
  border-radius: 0.85rem;
  background: var(--app-surface-solid);
  color: var(--app-ink);
  font: inherit;
  font-size: 1.2rem;
  font-weight: 950;
  text-align: center;
}

.timer-controls .action-button {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 0.1rem;
}

.access-lock-button {
  width: 100%;
  margin-top: 0.9rem;
}

.parent-setting-card .parent-control-status {
  min-height: 1.4em;
  margin-top: 0.7rem;
  color: #166534;
  font-weight: 800;
  text-align: center;
}

.adventure-concept {
  display: inline-flex;
  margin: 0 auto 1rem;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 0.85rem;
  font-weight: 850;
}

.adventure-progress-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1rem;
  margin: -0.45rem 0 0.85rem;
  color: var(--app-muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.adventure-stage {
  width: min(100%, 48rem);
  min-height: 22rem;
  margin: 0 auto;
  padding: clamp(0.9rem, 3vw, 1.35rem);
  border: 2px solid #d9d5ff;
  border-radius: 1.4rem;
  background:
    radial-gradient(circle at 8% 4%, rgb(255 200 61 / 15%) 0 5rem, transparent 5.1rem),
    radial-gradient(circle at 96% 95%, rgb(66 211 173 / 12%) 0 6rem, transparent 6.1rem),
    var(--app-surface-soft);
}

.adventure-visual {
  min-height: 3.5rem;
  font-size: clamp(2.8rem, 12vw, 5.25rem);
  line-height: 1.15;
}

.adventure-prompt {
  max-width: 38rem;
  margin: 0.6rem auto 1rem;
  color: var(--app-ink);
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  font-weight: 950;
  line-height: 1.2;
}

.adventure-interaction {
  width: min(100%, 42rem);
  margin: 0 auto;
}

.adventure-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.adventure-choice {
  display: grid;
  place-items: center;
  gap: 0.25rem;
  min-height: 4.5rem;
  padding: 0.65rem;
  border: 2px solid #bfdbfe;
  border-radius: 1rem;
  background: var(--app-surface-solid);
  color: var(--app-ink);
  box-shadow: 0 0.25rem 0 #dbeafe;
  font: inherit;
  font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  font-weight: 900;
  cursor: pointer;
}

.adventure-choice-emoji {
  font-size: clamp(1.8rem, 8vw, 2.7rem);
}

.adventure-choice.shadow .adventure-choice-emoji {
  filter: brightness(0);
}

.adventure-choice.correct {
  border-color: #10b981;
  background: #d1fae5;
  color: #065f46;
  box-shadow: 0 0.25rem 0 #6ee7b7;
}

.adventure-choice.incorrect {
  border-color: #fb7185;
  background: #ffe4e6;
  color: #9f1239;
  box-shadow: 0 0.25rem 0 #fecdd3;
  animation: wrong-shake 280ms ease;
}

.adventure-choice:focus-visible,
.adventure-control-button:focus-visible,
.market-stepper button:focus-visible,
.order-card:focus-visible {
  outline: 4px solid #fbbf24;
  outline-offset: 2px;
}

.speak-challenge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
  padding: 0.55rem 0.85rem;
  border: 0;
  border-radius: 999px;
  background: #ede9fe;
  color: #5b21b6;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.path-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9rem;
  gap: 1rem;
  align-items: center;
}

.path-board {
  display: grid;
  grid-template-columns: repeat(var(--path-size), minmax(0, 1fr));
  gap: clamp(0.15rem, 0.7vw, 0.3rem);
  width: min(100%, 28rem);
  margin: 0 auto;
  padding: 0.45rem;
  border: 3px solid #a5b4fc;
  border-radius: 1.15rem;
  background: #e0e7ff;
}

.path-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: clamp(0.25rem, 1vw, 0.55rem);
  background: white;
  font-size: clamp(1rem, 4vw, 1.75rem);
  box-shadow: inset 0 0 0 1px rgb(99 102 241 / 13%);
}

.path-cell.obstacle {
  background: #cbd5e1;
}

.path-cell.visited {
  background: #dcfce7;
}

.path-controls {
  display: grid;
  grid-template-columns: repeat(3, 2.75rem);
  grid-template-rows: repeat(3, 2.75rem);
  gap: 0.35rem;
  justify-content: center;
}

.adventure-control-button {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0.8rem;
  background: #6252f5;
  color: white;
  box-shadow: 0 0.25rem 0 #4338ca;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 950;
  cursor: pointer;
}

.adventure-control-button[data-direction="up"] {
  grid-column: 2;
  grid-row: 1;
}

.adventure-control-button[data-direction="left"] {
  grid-column: 1;
  grid-row: 2;
}

.adventure-control-button[data-direction="right"] {
  grid-column: 3;
  grid-row: 2;
}

.adventure-control-button[data-direction="down"] {
  grid-column: 2;
  grid-row: 3;
}

.path-status {
  grid-column: 1 / -1;
  margin-top: 0.55rem;
  color: var(--app-muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-align: center;
}

.market-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.market-item {
  padding: 0.7rem 0.35rem;
  border: 2px solid #fed7aa;
  border-radius: 1rem;
  background: var(--app-surface-solid);
}

.market-item-emoji {
  display: block;
  font-size: 2.6rem;
}

.market-item-name,
.market-item-price {
  display: block;
  font-size: 0.76rem;
  font-weight: 850;
}

.market-item-price {
  color: var(--app-muted);
}

.market-stepper {
  display: grid;
  grid-template-columns: 2.25rem minmax(1.5rem, 1fr) 2.25rem;
  gap: 0.25rem;
  align-items: center;
  margin-top: 0.5rem;
}

.market-stepper button {
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0.65rem;
  background: #ffedd5;
  color: #9a3412;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 950;
  cursor: pointer;
}

.market-count {
  color: var(--app-ink);
  font-size: 1.2rem;
  font-weight: 950;
}

.check-adventure-answer {
  width: min(100%, 18rem);
  margin-top: 0.85rem;
}

.order-pool,
.order-answer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  min-height: 5.2rem;
  padding: 0.65rem;
  border: 2px dashed #c4b5fd;
  border-radius: 1rem;
}

.order-answer {
  margin-bottom: 0.7rem;
  border-style: solid;
  background: rgb(237 233 254 / 55%);
}

.order-card {
  display: grid;
  place-items: center;
  width: min(7.1rem, 29vw);
  min-height: 4.7rem;
  padding: 0.5rem;
  border: 2px solid #bfdbfe;
  border-radius: 0.85rem;
  background: var(--app-surface-solid);
  color: var(--app-ink);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 850;
  cursor: pointer;
}

.order-card-emoji {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 1.75rem;
}

.rhythm-sequence {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  min-height: 4rem;
  margin-bottom: 0.7rem;
}

.rhythm-beat {
  display: grid;
  place-items: center;
  width: 3.4rem;
  aspect-ratio: 1;
  border-radius: 0.9rem;
  background: #ede9fe;
  font-size: 2rem;
  transition: transform 100ms ease, background 100ms ease;
}

.rhythm-beat.active {
  background: #fef3c7;
  transform: scale(1.16);
}

.rhythm-beat.hidden-beat {
  color: transparent;
  background: #e2e8f0;
}

.rhythm-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}

.rhythm-button {
  min-height: 4rem;
  padding: 0.4rem;
  border: 2px solid #c4b5fd;
  border-radius: 0.9rem;
  background: var(--app-surface-solid);
  font: inherit;
  font-size: 2rem;
  cursor: pointer;
}

#adventure-message {
  display: grid;
  place-items: center;
  width: min(100%, 48rem);
  min-height: 3.35rem;
  margin: 0.65rem auto 0;
  padding: 0.2rem 0.5rem;
  color: #08744b;
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.35;
}

.adventure-reward {
  display: grid;
  place-items: center;
  min-height: 18rem;
  font-size: clamp(7rem, 30vw, 13rem);
}

html[data-theme="dark"] .access-gate {
  background:
    radial-gradient(circle at 12% 15%, rgb(255 200 61 / 15%) 0 9rem, transparent 9.1rem),
    radial-gradient(circle at 88% 80%, rgb(66 211 173 / 12%) 0 11rem, transparent 11.1rem),
    linear-gradient(145deg, #171326, #111b2e);
}

html[data-theme="dark"] .access-gate-card {
  border-color: #343a5b;
  background: #1a1e37;
  color: #f7f7ff;
}

html[data-theme="dark"] .access-gate-card h1,
html[data-theme="dark"] .access-gate-card label {
  color: #f7f7ff;
}

html[data-theme="dark"] .access-gate-card p {
  color: #b3bad3;
}

html[data-theme="dark"] #access-code-input {
  border-color: #343a5b;
  background: #111426;
  color: #f7f7ff;
}

html[data-theme="dark"] .parent-setting-card,
html[data-theme="dark"] .adventure-card,
html[data-theme="dark"] .adventure-stage,
html[data-theme="dark"] .adventure-choice,
html[data-theme="dark"] .market-item,
html[data-theme="dark"] .order-card,
html[data-theme="dark"] .rhythm-button {
  border-color: var(--app-line);
  background: var(--app-surface-solid);
  color: var(--app-ink);
}

html[data-theme="dark"] .adventure-card-icon {
  background: color-mix(in srgb, var(--adventure-color) 28%, #1a1e37);
}

html[data-theme="dark"] .adventure-concept,
html[data-theme="dark"] .speak-challenge {
  background: #292650;
  color: #d7d3ff;
}

html[data-theme="dark"] .path-board {
  border-color: #4f4a7a;
  background: #252846;
}

html[data-theme="dark"] .path-cell {
  background: #1a1e37;
}

html[data-theme="dark"] .path-cell.obstacle {
  background: #475569;
}

html[data-theme="dark"] .path-cell.visited {
  background: #14532d;
}

html[data-theme="dark"] .market-stepper button {
  background: #4a2b1c;
  color: #fed7aa;
}

html[data-theme="dark"] .order-answer {
  background: rgb(76 70 132 / 30%);
}

@media (max-width: 46rem) {
  .adventure-stage {
    min-height: 20rem;
    padding: 0.75rem;
  }

  .path-layout {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }

  .path-controls {
    grid-template-columns: repeat(3, 2.55rem);
    grid-template-rows: repeat(3, 2.55rem);
  }

  .market-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 26rem) {
  .pause-setting-heading {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .pause-setting-state {
    grid-column: 1 / -1;
    justify-self: stretch;
    text-align: center;
  }
}

@media (max-width: 23rem) {
  .adventure-choice-grid {
    grid-template-columns: 1fr;
  }

  .market-grid {
    gap: 0.45rem;
  }

  .market-item {
    padding-inline: 0.25rem;
  }

  .rhythm-buttons {
    gap: 0.35rem;
  }

  .rhythm-button {
    font-size: 1.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .adventure-card,
  .rhythm-beat {
    transition: none;
  }
}
