: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; }

#tabs {
  display: flex;
  gap: 6px;
  padding: 8px 12px 0;
}
.tab {
  background: #2f241a;
  color: #cbb68f;
  border: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}
.tab.active { background: #3d2f22; color: var(--cream); font-weight: 700; }

#app {
  display: flex;
  height: calc(100vh - 44px);
  gap: 12px;
  padding: 0 12px 12px;
}

#scenes-view { display: flex; flex: 1 1 auto; gap: 12px; min-width: 0; }
#scenes-view.hidden, #characters-view.hidden, #style-view.hidden { display: none; }

#stage {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

#game {
  width: 100%;
  height: auto;
  max-width: 1200px;
  max-height: min(100%, 800px);
  aspect-ratio: 3 / 2;
  background: #000;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  touch-action: none;
  image-rendering: pixelated;
}

#panel {
  flex: 0 0 300px;
  overflow-y: auto;
  background: #2f241a;
  border-radius: 10px;
  padding: 14px 16px;
}

#panel h2 { font-size: 15px; margin: 12px 0 6px; }
.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-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; }

/* ---- 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; }
}
