:root {
  --bg: #2b2320;
  --panel: #3a2f2a;
  --text: #f7efe6;
  --muted: #d9c9b8;
  --accent: #f2b880;
  --accent-text: #2b2320;
  --focus: #ffe08a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 1.125rem;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 0.75rem) 1rem calc(env(safe-area-inset-bottom) + 1.5rem);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 { font-size: 1.6rem; margin: 0.5rem 0 0.75rem; line-height: 1.25; }
h2 { font-size: 1.25rem; margin: 1.25rem 0 0.5rem; }
h1:focus, p:focus { outline: none; }

p { margin: 0 0 0.85rem; }
.muted { color: var(--muted); }

.topbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  min-height: 3rem;
}
.topbar .back { justify-self: start; }
.topbar .center { justify-self: center; }
.topbar .right { justify-self: end; }

.bottombar {
  margin-top: auto;
  padding-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.bottombar .spacer { flex: 1; }

button, .file-label {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 2px solid #5a4a42;
  border-radius: 0.8rem;
  padding: 0.8rem 1rem;
  min-height: 3rem;
  cursor: pointer;
  text-align: left;
}
.topbar button, .bottombar button {
  padding: 0.5rem 0.9rem;
  min-height: 2.75rem;
  text-align: center;
}
.stack { display: flex; flex-direction: column; gap: 0.6rem; margin: 0.5rem 0 1rem; }
.stack button { width: 100%; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

label { display: block; margin: 1rem 0 0.35rem; font-weight: 600; }
input[type="text"], select {
  font: inherit;
  width: 100%;
  padding: 0.7rem;
  border-radius: 0.6rem;
  border: 2px solid #5a4a42;
  background: #1f1916;
  color: var(--text);
}
fieldset { border: 2px solid #5a4a42; border-radius: 0.8rem; margin: 1rem 0; padding: 0.5rem 1rem 1rem; }
legend { font-weight: 600; padding: 0 0.3rem; }
.radio, .check { display: flex; align-items: center; gap: 0.75rem; margin: 0.6rem 0; font-weight: normal; }
.radio input, .check input { width: 1.5rem; height: 1.5rem; }
.error { color: #ffb4a8; font-weight: 600; }

.story p { font-size: 1.15rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

#scene { max-width: 40rem; margin: 0 auto; padding-top: env(safe-area-inset-top); }
#scene canvas { display: block; width: 100%; border-radius: 0 0 0.8rem 0.8rem; }
#scene:not([hidden]) + main { padding-top: 0.5rem; }
.story-art, .treasure-art { position: relative; margin: 0.5rem 0 0.25rem; }
.story-art img { width: 100%; display: block; border-radius: 0.8rem; }
.story-art img.friend { position: absolute; width: 26%; right: 4%; bottom: 3%; border-radius: 0; filter: drop-shadow(0 4px 6px rgba(40,25,10,0.35)); }
.treasure-art img { width: 45%; max-width: 14rem; display: block; margin: 0 auto; }
