:root {
  --cream: #f3e4c6;
  --wood: #6b4a2e;
  --ink: #2a1e17;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #241b13;
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #241b13;
  transition: opacity .45s ease;
}
#loader.hidden { opacity: 0; pointer-events: none; }
.loader-box { text-align: center; width: min(80vw, 340px); }
.loader-title { font-family: Georgia, 'Times New Roman', serif; font-size: 27px; color: #e8b85a; margin-bottom: 18px; }
.loader-track { height: 14px; background: #3d2f22; border: 1px solid #6b4a2e; border-radius: 999px; overflow: hidden; }
#loader-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #e8b85a, #c96f4a); transition: width .2s ease; }
.loader-sub { margin-top: 10px; font-size: 12px; color: #9c8763; letter-spacing: .04em; }

/* ---- Title screen ---- */
#title {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(20px, 7vh, 84px) 24px 24px;
  background:
    radial-gradient(circle at 50% 34%, #4a3524 0%, #2c211700 60%),
    linear-gradient(#2f2417, #1f1710);
}
#title.hidden { display: none; }
.title-inner { display: flex; flex-direction: column; align-items: center; gap: 20px; text-align: center; max-width: 92vw; }
.title-logo { width: min(78vw, 520px); height: auto; image-rendering: pixelated; filter: drop-shadow(0 8px 20px rgba(0,0,0,0.5)); }
.title-portrait {
  width: 150px; height: 150px; border-radius: 50%; object-fit: cover; object-position: 50% 22%;
  border: 4px solid #e8b85a; background: #2f241a;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); image-rendering: pixelated;
}
.title-buttons { display: flex; gap: 14px; margin-top: 4px; flex-wrap: wrap; justify-content: center; }
.title-buttons button {
  font-family: Georgia, 'Times New Roman', serif; font-weight: 700; font-size: 18px;
  padding: 12px 36px; border: none; border-radius: 999px; cursor: pointer;
}
#title-start { background: linear-gradient(#ecc06a, #d99f3e); color: #2a1e17; box-shadow: 0 4px 0 #a9762a; }
#title-start:hover { background: linear-gradient(#f2cd7a, #e2aa4b); }
#title-start:active { transform: translateY(2px); box-shadow: 0 2px 0 #a9762a; }
#title-credits { background: #3d2f22; color: var(--cream); border: 1px solid #6b4a2e; box-shadow: 0 4px 0 #241b13; }
#title-credits:hover { background: #4a3a2a; }
#title-credits:active { transform: translateY(2px); box-shadow: 0 2px 0 #241b13; }
.title-hint { margin: 4px 0 0; color: #cbb68f; font-family: Georgia, 'Times New Roman', serif; font-size: 16px; font-style: italic; }
.title-sound { margin: 0; color: #9a8a68; font-family: Georgia, 'Times New Roman', serif; font-size: 12px; }

/* ---- Credits (stub) ---- */
#credits {
  position: fixed; inset: 0; z-index: 46;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(#2f2417, #1f1710);
}
#credits.hidden { display: none; }
.credits-inner { text-align: center; color: var(--cream); max-width: 480px; }
.credits-inner h1 { font-family: Georgia, serif; color: #e8b85a; font-size: 34px; margin: 0 0 12px; }
.credits-inner p { color: #cbb68f; line-height: 1.5; }
#credits-back {
  margin-top: 18px; font-family: Georgia, serif; font-weight: 700; font-size: 16px;
  padding: 10px 30px; border: 1px solid #6b4a2e; border-radius: 999px; cursor: pointer;
  background: #3d2f22; color: var(--cream); box-shadow: 0 4px 0 #241b13;
}
#credits-back:active { transform: translateY(2px); box-shadow: 0 2px 0 #241b13; }

#topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(#2f241a, #241b13);
  border-bottom: 1px solid #3d2f22;
}
#logo { display: flex; align-items: center; gap: 8px; }
#logo .logo-mark { font-size: 22px; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4)); }
#logo .logo-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: .01em;
  background: linear-gradient(#ffe9a8, #f0b64e 55%, #e07a3c);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.35));
}
#admin-btn {
  background: #3d2f22;
  color: #cbb68f;
  border: 1px solid #6b4a2e;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
#admin-btn:hover { background: #4a3a2a; color: var(--cream); }
#topbar-actions { display: flex; align-items: center; gap: 8px; }
#credits-btn {
  background: #3d2f22;
  color: #cbb68f;
  border: 1px solid #6b4a2e;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
#credits-btn:hover { background: #4a3a2a; color: var(--cream); }
#mute-btn {
  background: #3d2f22;
  color: #cbb68f;
  border: 1px solid #6b4a2e;
  border-radius: 999px;
  width: 30px;
  height: 26px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
#mute-btn:hover { background: #4a3a2a; }
#mute-btn[aria-pressed="true"] { color: #e8918a; border-color: #8a4a3a; }

#stage {
  position: relative;
  height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
}
#collect-hint {
  margin: 0;
  color: #b09a72;
  font-size: 13px;
  text-align: center;
  letter-spacing: .01em;
}

#game {
  display: block;
  background: #000;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  touch-action: none;
  image-rendering: pixelated;
}

/* iPhone held sideways: hide the chrome and let the scene fill the whole screen. */
body.iphone-landscape #topbar { display: none; }
body.iphone-landscape #collect-hint { display: none; }
body.iphone-landscape #stage {
  height: 100vh;
  height: 100dvh;
  padding: 4px;
  gap: 0;
}
body.iphone-landscape #game { border-radius: 6px; }

/* ---- Admin screen (developer tools) ---- */
#admin {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #241b13;
  overflow-y: auto;
}
#admin.hidden { display: none; }
#admin-inner { max-width: 1100px; margin: 0 auto; padding: 16px 18px 48px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.admin-head h1 { font-family: Georgia, serif; color: #e8b85a; font-size: 24px; margin: 0; }
#admin-close { background: #3d2f22; color: var(--cream); border: 1px solid #6b4a2e; border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
#admin-close:hover { background: #4a3a2a; }
.admin-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.atab { background: #2f241a; color: #cbb68f; border: none; border-radius: 8px; padding: 8px 16px; font-size: 14px; cursor: pointer; }
.atab.active { background: #3d2f22; color: var(--cream); font-weight: 700; }
.admin-panel.hidden { display: none; }
#scene-name { font-size: 16px; margin: 14px 0 6px; color: var(--cream); }
.hint { font-size: 12px; line-height: 1.45; color: #cbb68f; }

.nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.nav button, #reset, #overlay-close {
  background: var(--wood);
  color: var(--cream);
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}
.nav button:hover, #reset:hover, #overlay-close:hover { background: #855f3b; }
.nav button.active { background: #c96f4a; }

#asset-list { font-size: 13px; }
.asset-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid #3d2f22;
}
.asset-row .cat { color: #9c8763; font-size: 11px; }
.asset-row.done .name::before { content: "✓ "; color: #8fa968; }
.section-label { margin-top: 10px; color: #e8b85a; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

#progress { margin: 12px 0; font-size: 13px; color: #cbb68f; }
#reset { margin-top: 6px; font-size: 12px; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18,11,6,0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  border-radius: 10px;
}
#overlay.hidden { display: none; }
#overlay-card {
  position: relative;
  background: linear-gradient(#f6e9cf, #e7d1a8);
  color: #33261a;
  border: 3px solid #e8b85a;
  box-shadow: 0 0 0 3px #6b4a2e, 0 20px 44px rgba(0,0,0,0.55);
  border-radius: 18px;
  padding: 22px 26px 20px;
  max-width: min(90vw, 480px);
  text-align: center;
  animation: pop-in .22s cubic-bezier(.2,1.3,.5,1);
}
/* Wide, clean white card for the trophy-shelf popup so the shelf graphic reads well. */
#overlay-card.wide { width: min(94vw, 700px); max-width: 700px; background: #fffdf8; padding: 16px 18px 14px; }
#overlay-card.wide #overlay-body { margin-bottom: 8px; }
@keyframes pop-in { from { transform: scale(.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#overlay-title { font-family: Georgia, 'Times New Roman', serif; font-size: 23px; font-weight: 700; margin-bottom: 10px; color: #7a4a24; text-transform: capitalize; }
#overlay-body { font-size: 15px; line-height: 1.5; margin-bottom: 18px; color: #3a2c1e; }
#overlay-close {
  background: linear-gradient(#ecc06a, #d99f3e);
  color: #2a1e17;
  font-weight: 700;
  font-size: 15px;
  padding: 10px 30px;
  border-radius: 999px;
  box-shadow: 0 3px 0 #a9762a;
}
#overlay-close:hover { background: linear-gradient(#f2cd7a, #e2aa4b); }
#overlay-close:active { transform: translateY(2px); box-shadow: 0 1px 0 #a9762a; }

/* Item card + shelf popup */
.item-img { width: 136px; height: 136px; margin: 0 auto 12px; background: #fff8e8; border: 2px solid #cbb68f; border-radius: 14px; box-shadow: inset 0 2px 10px rgba(0,0,0,0.12); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.item-img img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.item-img.empty::after { content: '(item image)'; color: #b09a72; font-size: 11px; }
.item-img.memory { width: min(88vw, 320px); height: auto; aspect-ratio: 4 / 3; }
.video-box { width: min(88vw, 360px); aspect-ratio: 16 / 9; margin: 0 auto 12px; background: #2a1e17; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #f3e4c6; gap: 6px; padding: 8px; text-align: center; }
.video-box small { color: #b09a72; font-size: 11px; }
.video-player { margin: 0 auto 12px; display: flex; justify-content: center; }
.video-player video { max-width: min(78vw, 300px); max-height: 58vh; border-radius: 12px; background: #000; box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.video-foot { color: #6b4a2e; font-weight: 600; line-height: 1.4; }
.bonus-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 16px; }
.bonus-btn { font-weight: 700; font-size: 15px; padding: 10px 24px; border: none; border-radius: 999px; cursor: pointer; background: #e9dcc2; color: #5a432c; box-shadow: 0 3px 0 #b7a37c; }
.bonus-btn.primary { background: linear-gradient(#ecc06a, #d99f3e); color: #2a1e17; box-shadow: 0 3px 0 #a9762a; }
.bonus-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b7a37c; }
.shelf-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 520px; margin: 0 auto; }
.shelf-slot { width: 96px; height: 96px; border: 2px solid #6b4a2e; border-radius: 8px; background: #3d2f22; color: #f3e4c6; font-size: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 4px; text-align: center; }
.shelf-slot img { width: 46px; height: 46px; object-fit: contain; image-rendering: pixelated; }
.shelf-slot span { text-transform: capitalize; }
/* Stardew-style trophy shelf display: the wooden hutch image with item icons resting on its shelves. */
.shelf-display { position: relative; width: 100%; max-width: 680px; margin: 0 auto 4px; }
.shelf-bg { display: block; width: 100%; height: auto; image-rendering: pixelated; border-radius: 16px; }
.shelf-row { position: absolute; left: 19%; right: 19%; height: 14%; display: flex; justify-content: center; align-items: flex-end; gap: 3%; }
.shelf-item { background: none; border: none; padding: 0; margin: 0; cursor: pointer; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.shelf-item img { max-height: 100%; max-width: 100%; width: auto; object-fit: contain; image-rendering: pixelated; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35)); transition: transform 0.1s ease; }
.shelf-item:hover img, .shelf-item:focus img { transform: translateY(-3px) scale(1.07); }
#shelf-desc { margin-top: 6px; min-height: 0; font-size: 13px; color: #5a4636; }

/* Characters tab */
#characters-view { flex: 1 1 auto; overflow-y: auto; padding: 4px 4px 20px; }
#char-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 10px;
}
.char-sec {
  background: #2a2016;
  border-radius: 12px;
  padding: 12px 14px;
}
.char-sec h3 {
  margin: 0 0 8px;
  font-family: Georgia, serif;
  color: #f3e4c6;
  text-transform: capitalize;
}
.char-sec h3 small { color: #b89b73; font-weight: 400; font-size: 0.68em; margin-left: 8px; }
.pgroup { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.plabel {
  width: 44px; flex: 0 0 44px; align-self: center;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #b89b73;
}
.ptile { margin: 0; width: 92px; text-align: center; }
.ptile img {
  width: 92px; height: 92px; object-fit: contain; image-rendering: pixelated;
  background: #1d1610 repeating-linear-gradient(45deg, #241b13 0 8px, #1d1610 8px 16px);
  border-radius: 8px;
}
.ptile figcaption { font-size: 10px; color: #9c8763; margin-top: 3px; }
.ptile.missing img { display: none; }
.ptile.missing { position: relative; }
.ptile.missing::before {
  content: 'n/a'; display: flex; align-items: center; justify-content: center;
  width: 92px; height: 92px; border-radius: 8px;
  background: #1d1610; color: #6b5a3f; font-size: 11px;
}
.char-card {
  background: #2f241a;
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.char-card .thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #1d1610 repeating-linear-gradient(45deg, #241b13 0 8px, #1d1610 8px 16px);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 8px;
}
.char-card .thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.char-card .thumb .missing { font-size: 12px; color: #7d6a4d; padding: 8px; }
.char-card .cname { font-size: 13px; font-weight: 700; }
.char-card .crole { font-size: 11px; color: #9c8763; }

/* Items tab */
#items-view { flex: 1 1 auto; overflow-y: auto; padding: 4px 4px 20px; }
#item-grid { display: flex; flex-direction: column; gap: 16px; margin-top: 10px; }
.admin-item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.admin-item {
  margin: 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #241b13;
  border-radius: 10px;
  padding: 8px;
}
.admin-item-thumb {
  flex: 0 0 64px;
  width: 64px; height: 64px;
  border-radius: 8px;
  background: #1d1610 repeating-linear-gradient(45deg, #241b13 0 8px, #1d1610 8px 16px);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.admin-item-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.admin-item.missing .admin-item-thumb img { display: none; }
.admin-item.missing .admin-item-thumb::before { content: 'n/a'; color: #6b5a3f; font-size: 11px; }
.admin-item figcaption { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.admin-item-name { font-size: 13px; font-weight: 700; color: #f3e4c6; }
.admin-item-mem { font-size: 10px; font-weight: 600; color: #e8b85a; margin-left: 6px; }
.admin-item-desc { font-size: 11px; color: #b89b73; line-height: 1.35; }
.admin-item-id { font-family: ui-monospace, monospace; font-size: 10px; color: #6b5a3f; margin-top: 2px; }

/* ---- Style guide tab ---- */
#style-view { flex: 1 1 auto; overflow-y: auto; padding: 4px 16px 32px; }
#style-guide { max-width: 900px; }
#style-guide h1 { font-family: Georgia, serif; font-size: 26px; margin: 12px 0 6px; }
#style-guide h2 { font-family: Georgia, serif; font-size: 18px; margin: 26px 0 6px; color: var(--cream); border-bottom: 1px solid #4a3524; padding-bottom: 4px; }
#style-guide .sg-lead { font-size: 14px; color: #cbb68f; line-height: 1.5; max-width: 680px; }
#style-guide .sg-note { font-size: 12px; color: #9c8763; line-height: 1.5; margin: 4px 0 10px; }
#style-guide code { background: #1d1610; padding: 1px 5px; border-radius: 4px; font-size: 12px; color: #e8b85a; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.swatch { background: #2f241a; border-radius: 8px; overflow: hidden; }
.swatch .chip { height: 60px; }
.swatch .sw-name { font-size: 12px; font-weight: 600; padding: 6px 8px 0; }
.swatch .sw-hex { font-family: ui-monospace, monospace; font-size: 11px; color: #9c8763; padding: 0 8px 8px; }

.type-specs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.type-card { background: #2f241a; border-radius: 10px; padding: 12px 14px; }
.type-card .type-sample { font-size: 26px; color: var(--cream); margin-bottom: 8px; }
.type-card .type-meta { font-size: 12px; color: #9c8763; line-height: 1.5; }
.type-card .type-meta b { color: #cbb68f; }

.sg-rules { margin: 4px 0; padding-left: 18px; }
.sg-rules li { font-size: 13px; color: #cbb68f; line-height: 1.55; margin-bottom: 6px; }
.sg-rules b { color: var(--cream); }

@media (max-width: 820px) {
  #scenes-view { flex-direction: column; }
  #panel { flex-basis: auto; max-height: 34vh; }
}
