:root {
  --bg: #1a1210;
  --panel: #2a1e18;
  --panel2: #3a2a22;
  --ink: #f3e6d4;
  --muted: #b9a48c;
  --accent: #e0a84a;
  --accent2: #c47a3a;
  --found: #7dba7a;
  --danger: #c45c4a;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  overscroll-behavior: none;
}
body { min-height: 100dvh; }

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
  min-height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px 8px;
  background: linear-gradient(180deg, #241814, transparent);
}
.title-block h1 {
  margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; font-weight: 700;
}
.title-block .sub { margin: 2px 0 0; font-size: 0.75rem; color: var(--muted); }
.stats { display: flex; align-items: center; gap: 10px; }
#found-count {
  font-variant-numeric: tabular-nums; font-weight: 700;
  background: var(--panel); padding: 6px 12px; border-radius: 999px;
  border: 1px solid #4a382c;
}

.stage-wrap {
  position: relative;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 0 10px;
  min-height: 0;
}
#game {
  width: 100%;
  max-width: min(100%, 520px);
  height: auto;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45), 0 0 0 1px #4a3428;
  background: #0d0908;
  touch-action: manipulation;
  cursor: crosshair;
}
#fx {
  pointer-events: none; position: absolute; inset: 0;
  display: flex; justify-content: center; align-items: flex-start;
}
#fx .fx-anchor {
  position: relative; width: 100%; max-width: min(100%, 520px);
  aspect-ratio: 3 / 4;
}
.spark {
  position: absolute; width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle, #fff6c8, #e0a84a 50%, transparent 70%);
  animation: pop 0.7s ease-out forwards;
}
@keyframes pop {
  0% { transform: translate(0,0) scale(0.4); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

.sidebar {
  background: var(--panel);
  border-top: 1px solid #4a382c;
  border-radius: 20px 20px 0 0;
  padding: 12px 14px 16px;
  max-height: 42vh;
  display: flex; flex-direction: column; gap: 10px;
}
.sidebar-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.sidebar-head h2 { margin: 0; font-size: 0.95rem; }
.seed {
  font-size: 0.68rem; color: var(--muted); font-family: ui-monospace, monospace;
  max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.item-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  overflow-y: auto; flex: 1; min-height: 0;
}
.item-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px;
  background: var(--panel2); border: 1px solid #4a382c;
  font-size: 0.82rem; transition: opacity 0.25s, background 0.25s;
}
.item-list li.found {
  opacity: 0.45; text-decoration: line-through; color: var(--found);
  background: #243222;
}
.item-list .swatch {
  width: 28px; height: 28px; border-radius: 6px; object-fit: contain;
  background: #1a1210; flex-shrink: 0;
}

.actions { display: flex; gap: 8px; }
.btn {
  flex: 1; border: 1px solid #5a4436; background: var(--panel2); color: var(--ink);
  border-radius: 12px; padding: 12px 14px; font-size: 0.92rem; font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: #1a1008; border-color: #f0c878;
}
.btn.ghost {
  flex: 0; padding: 6px 12px; font-size: 0.8rem;
  background: transparent; border-color: #5a4436; color: var(--accent);
}
.debug {
  margin: 0; font-size: 0.65rem; color: var(--muted);
  font-family: ui-monospace, monospace; line-height: 1.35;
  word-break: break-word;
}

@media (min-width: 820px) {
  #app {
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr;
    max-width: 1100px; gap: 0 12px; padding: 12px;
    min-height: calc(100dvh - 0px);
  }
  .topbar { grid-column: 1 / -1; }
  .stage-wrap { grid-column: 1; align-items: center; }
  .sidebar {
    grid-column: 2; grid-row: 2;
    max-height: none; height: 100%;
    border-radius: var(--radius); border: 1px solid #4a382c;
  }
  #game { max-width: 560px; }
}
