:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: light;
  font-family: system-ui, sans-serif;
  background: #f5ead8;
  color: #34261d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
}

button {
  min-block-size: 44px;
  min-inline-size: 44px;
  border: 1px solid #72513c;
  border-radius: 0.75rem;
  padding: 0.55rem 0.75rem;
  background: #fffaf0;
  color: inherit;
  font: inherit;
  line-height: 1.2;
  overflow-wrap: anywhere;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid #1f6a62;
  outline-offset: 2px;
}

button[disabled] {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-auto-rows: auto;
  gap: 0.75rem;
  width: min(100%, 64rem);
  height: 100svh;
  min-height: 0;
  margin-inline: auto;
  padding:
    max(0.75rem, var(--safe-top))
    max(0.75rem, var(--safe-right))
    max(0.75rem, var(--safe-bottom))
    max(0.75rem, var(--safe-left));
}

.app-header,
.app-tools,
.station-nav,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-header {
  justify-content: space-between;
}

.app-title {
  margin: 0;
  font-size: clamp(1.2rem, 5vw, 1.75rem);
}

.app-tools {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.game-stage {
  position: relative;
  min-height: 18rem;
  overflow: hidden;
  border-radius: 1rem;
  background: #d4b58c;
  box-shadow: inset 0 0 0 1px rgb(52 38 29 / 18%);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 18rem;
  contain: size;
  touch-action: none;
}

.recovery-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: rgb(52 38 29 / 92%);
  color: #fffaf0;
  text-align: center;
}

.recovery-overlay[hidden] {
  display: none;
}

.recovery-overlay p {
  max-width: 32rem;
  margin: 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.station-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.alternative-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.station-nav button[aria-selected="true"] {
  border-color: #1f6a62;
  background: #dff1e9;
  font-weight: 700;
}

.finish-button {
  width: 100%;
  background: #1f6a62;
  color: white;
  font-weight: 700;
}

.restart-button,
.onion-amount-control {
  width: 100%;
}

.onion-amount-control {
  display: grid;
  gap: 0.35rem;
  padding: 0.4rem 0.1rem;
  font-weight: 700;
}

.onion-amount-control input {
  min-block-size: 44px;
}

.view-panel {
  min-height: 0;
  overflow: auto;
  border: 1px solid rgb(52 38 29 / 18%);
  border-radius: 1rem;
  padding: clamp(1rem, 4vw, 1.5rem);
  background: #fffaf0;
}

.view-panel[hidden] {
  display: none;
}

.result-panel,
.collection-panel {
  display: grid;
  gap: 1rem;
}

.result-panel h2,
.result-panel h3,
.result-panel p,
.collection-panel h2,
.collection-panel h3,
.collection-panel p {
  margin: 0;
}

.eyebrow {
  color: #72513c;
  font-weight: 700;
}

.result-title {
  font-size: clamp(1.5rem, 7vw, 2.4rem);
}

.overall-score {
  font-size: 1.25rem;
  font-weight: 800;
}

.score-list,
.score-row {
  display: grid;
  gap: 0.4rem;
}

.score-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.score-bar {
  grid-column: 1 / -1;
  height: 0.75rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e1d1bc;
}

.score-bar-fill {
  display: block;
  width: var(--score, 0%);
  height: 100%;
  background: #1f6a62;
}

.result-actions,
.collection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.result-actions a {
  color: #1f6a62;
  overflow-wrap: anywhere;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.collection-card {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  border: 1px solid #cdb597;
  border-radius: 0.8rem;
  padding: 0.85rem;
  background: #fff;
  overflow-wrap: anywhere;
}

.collection-card.is-locked {
  background: #eee5d8;
  color: #5e5249;
}

.collection-card dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.2rem 0.75rem;
  margin: 0;
}

.collection-card dd {
  margin: 0;
  font-weight: 700;
}

dialog {
  width: min(calc(100% - 2rem), 30rem);
  max-height: calc(100svh - var(--safe-top) - var(--safe-bottom) - 2rem);
  border: 0;
  border-radius: 1rem;
  padding: 0;
  color: inherit;
}

dialog::backdrop {
  background: rgb(35 23 16 / 58%);
}

.dialog-card {
  padding: 1.25rem;
}

.dialog-card h2 {
  margin-block: 0 0.75rem;
}

.dialog-card p {
  margin-block: 0 1rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.dialog-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.dialog-skip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-block: 0 1rem;
}

.dialog-skip input {
  min-block-size: 1.25rem;
  min-inline-size: 1.25rem;
}

.save-disclosure {
  color: #5e5249;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 34rem) {
  .app-header {
    align-items: flex-start;
  }

  .app-tools button {
    flex: 1 1 auto;
  }

  .game-stage,
  #game-canvas {
    min-height: 0;
  }
}

@media (prefers-reduced-transparency: reduce) {
  dialog::backdrop {
    background: #34261d;
  }
}
