:root {
  --bg: #f9f4ec;
  --card: #ffffff;
  --line: #eadfcd;
  --brown: #975a16;
  --brown-dark: #6b3f0f;
  --brown-soft: #fdf3e3;
  --text: #1a202c;
  --muted: #5a6778;
  --good: #2f855a;
  --bad: #c53030;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body { display: flex; flex-direction: column; height: 100dvh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; border: 0; background: none; font-weight: 800; font-size: 18px; padding: 0; }
#top-right { display: flex; align-items: center; gap: 10px; }
#solved { font-weight: 700; color: var(--muted); white-space: nowrap; }

#main { flex: 1 1 auto; overflow-y: auto; padding: 16px 16px 30px; }
.page { max-width: 1040px; margin: 0 auto; }
.intro h1 { margin: 0 0 4px; font-size: 28px; }
.intro p, .lead { margin: 0 0 16px; color: var(--muted); font-size: 16px; line-height: 1.45; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: #fff;
  transition: transform .1s;
}
.tile:active { transform: scale(.97); }
.tile-img { width: 100%; aspect-ratio: 5 / 4; display: grid; place-items: center; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #fff, #f3e9d8); overflow: hidden; }
.tile-img svg, .tile-img img { width: 100%; height: 100%; object-fit: cover; }
.tile-img svg { object-fit: contain; }
.tile-name { font-weight: 800; font-size: 15px; text-align: center; }
.tile-stars { color: #d69e2e; letter-spacing: 2px; }
.off { color: #e2e8f0; }
.tile.solved { border-color: #d6bc8b; }
.tile.add { justify-content: center; border-style: dashed; background: transparent; min-height: 200px; }
.tile.add .plus { font-size: 44px; }
.small { font-size: 12px; color: var(--muted); }

.inv-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.inv-head h1 { margin: 0; font-size: 26px; }
.inv-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.look { position: sticky; top: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.frame {
  width: 100%;
  aspect-ratio: 5 / 4;
  border-radius: 20px;
  border: 10px solid #8b5a2b;
  background: radial-gradient(circle at 50% 40%, #fff, #efe2cb);
  box-shadow: inset 0 0 0 3px #6b3f0f, 0 8px 22px rgba(0, 0, 0, .12);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.frame svg, .frame img { width: 100%; height: 100%; object-fit: contain; transition: transform .3s; }
.frame.zoomed { overflow: auto; touch-action: pan-x pan-y; }
.frame.zoomed svg, .frame.zoomed img { transform: scale(1.8); transform-origin: center; }
.prompt { margin: 0; color: var(--muted); font-weight: 600; text-align: center; line-height: 1.4; }

.ask h3 { margin: 0 0 8px; }
.ask h3 small { font-weight: 600; color: var(--muted); font-size: 13px; }
.qs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.q {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-weight: 700;
  font-size: 15px;
  text-align: left;
}
.q .qi { font-size: 22px; }
.q.asked { background: var(--brown-soft); border-color: #d6bc8b; color: var(--muted); }
.q:disabled:not(.asked) { opacity: .5; }
.clues { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.clue { padding: 10px 14px; border-radius: 14px; background: #fff; border-left: 6px solid var(--brown); animation: pop .2s ease-out; }
.clue p { margin: 4px 0 0; line-height: 1.4; }
.idea { display: block; margin: 14px 0 10px; font-weight: 800; }
.idea span { font-weight: 600; color: var(--muted); }
.idea textarea, .field input, .field textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
  font-weight: 400;
  resize: vertical;
}
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option { min-height: 60px; padding: 10px 14px; border: 3px solid var(--line); border-radius: 14px; background: #fff; font-weight: 800; font-size: 16px; }
.reveal { margin-top: 14px; padding: 16px; border-radius: 18px; background: #fff; border: 3px solid var(--good); animation: pop .25s ease-out; }
.reveal.no { border-color: #ed8936; }
.reveal h2 { margin: 4px 0 8px; }
.reveal p { line-height: 1.45; }
.reveal .name { font-size: 18px; }
.reveal .stars { font-size: 30px; color: #d69e2e; letter-spacing: 4px; }
.modern { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; background: #ebf8ff; margin: 8px 0; }
.modern .me { font-size: 32px; }
.fact { padding: 10px 14px; border-radius: 14px; background: #fffbea; margin: 8px 0; line-height: 1.4; }
.used { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

.go, .ghost {
  height: 50px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
}
.go { border: 0; background: var(--brown); color: #fff; box-shadow: 0 3px 0 var(--brown-dark); }
.go:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--brown-dark); }
.ghost { border: 2px solid var(--line); background: #fff; }
.ghost.danger { color: var(--bad); }
.go.danger { background: var(--bad); box-shadow: 0 3px 0 #9b2c2c; }
#topbar .ghost { height: 42px; font-size: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: block; font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.photo {
  display: grid;
  place-items: center;
  aspect-ratio: 5 / 4;
  margin-bottom: 12px;
  border: 3px dashed #d6bc8b;
  border-radius: 18px;
  background: #fff;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  overflow: hidden;
}
.photo input { display: none; }
.photo img { width: 100%; height: 100%; object-fit: contain; }
.form h3 { margin: 0 0 8px; }

#modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(26, 32, 44, .45); z-index: 50; }
#modal[hidden] { display: none; }
#modal-card { width: min(100%, 560px); max-height: 90dvh; overflow-y: auto; padding: 20px 22px; border-radius: 18px; background: #fff; }
#modal-card h2 { margin: 0 0 10px; }
.steps { padding-left: 20px; line-height: 1.5; }
.steps li { margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 14px; }
#modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(90%, 480px); padding: 10px 16px; border-radius: 12px; background: rgba(26, 32, 44, .9); color: #fff; font-weight: 700; text-align: center; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 60; }
#toast.show { opacity: 1; }

@media (max-width: 820px) {
  .brand span { display: none; }
  .inv-grid, .form-grid { grid-template-columns: 1fr; }
  .look { position: static; }
}
@media (max-width: 560px) {
  .qs, .options { grid-template-columns: 1fr; }
  #btn-tips { font-size: 0; padding: 0 12px; }
  #btn-tips::first-letter { font-size: 18px; }
}
