:root {
  --bg: #f6f1e9;
  --card: #fffdf9;
  --ink: #23262f;
  --muted: #8a8478;
  --accent: #d9734e;
  --line: #e6dfd3;
  --danger: #c4453a;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Helvetica Neue", sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen.active { display: flex; }

#home { justify-content: center; align-items: center; gap: 36px; padding-left: 24px; padding-right: 24px; }
.brand { text-align: center; }
.logo { width: 76px; height: 76px; color: var(--ink); }
h1 { font-size: 44px; margin: 6px 0 0; letter-spacing: -1px; }
.sub { margin: 2px 0 0; color: var(--muted); }
.menu { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }
.big { width: 100%; padding: 18px 20px; border-radius: 18px; background: var(--card); font-weight: 600; font-size: 19px;
  box-shadow: 0 1px 0 var(--line), 0 6px 18px rgba(60, 40, 10, .06); display: flex; justify-content: space-between; align-items: center; }
.big.primary { background: var(--ink); color: #fff; }
.big:active, .pillbtn:active { transform: scale(.98); }
.pill { font-size: 14px; font-weight: 600; color: var(--accent); }
.foot { color: var(--muted); font-size: 14px; text-align: center; max-width: 300px; margin: 0; }

.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 56px; }
.bar .title { flex: 1; text-align: center; font-weight: 700; line-height: 1.2; }
.bar .title .muted { font-weight: 400; font-size: 13px; }
.icon { width: 44px; height: 44px; font-size: 34px; line-height: 40px; text-align: center; border-radius: 22px; }
.lives { width: 72px; text-align: right; font-size: 18px; letter-spacing: 1px; color: var(--accent); }
.lives .gone { color: var(--line); }
.bar.bottom { justify-content: space-between; padding-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 4px 12px; }
canvas { touch-action: none; display: block; }

.pillbtn { padding: 10px 18px; border-radius: 999px; background: var(--card); font-weight: 600; font-size: 15px;
  box-shadow: 0 1px 0 var(--line); }
.pillbtn.danger { color: var(--danger); }
.pillbtn[disabled] { opacity: .45; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 16px 24px; }
.upload { display: block; text-align: center; padding: 22px; border: 2px dashed #d6ccbb; border-radius: 18px;
  font-weight: 600; color: var(--ink); background: var(--card); }
.upload input { display: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; margin-top: 14px; }
.grid .tile { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--line); }
.grid .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .tile .badge { position: absolute; right: 6px; bottom: 6px; background: rgba(255,255,255,.9); border-radius: 10px;
  font-size: 11px; padding: 2px 7px; font-weight: 600; }
.grid .tile .badge.done { color: #2f7d4f; }

.pv-controls { display: flex; flex-direction: column; gap: 12px; align-items: center; padding: 8px 16px 16px; }
.pv-controls .big { max-width: 360px; justify-content: center; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { padding: 8px 16px; border-radius: 10px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.modal { position: fixed; inset: 0; background: rgba(35, 38, 47, .45); display: none; align-items: center; justify-content: center; padding: 24px; z-index: 10; }
.modal.show { display: flex; }
.modal .card { background: var(--card); border-radius: 24px; padding: 24px; width: 100%; max-width: 340px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.2); animation: pop .25s ease-out; }
.modal img { width: 100%; border-radius: 16px; display: none; margin-bottom: 12px; max-height: 50vh; object-fit: cover; }
.modal h2 { margin: 0 0 4px; }
.modal p { margin: 0 0 18px; }
.modal .row .pillbtn.primary { background: var(--ink); color: #fff; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; opacity: 0;
  transition: opacity .2s; pointer-events: none; z-index: 20; white-space: nowrap; }
.toast.show { opacity: 1; }
