:root {
  --ink: #17130e;
  --ink-soft: #3a3128;
  --paper: #f3e7cd;
  --paper-2: #e8d8b6;
  --paper-3: #dcc79c;
  --accent: #b0452f;
  --accent-2: #3f6ea8;
  --gold: #c9932c;
  --shadow: 0 6px 0 rgba(23, 19, 14, 0.18), 0 12px 24px rgba(23, 19, 14, 0.22);
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #cbb98f;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#stage.grabbing { cursor: grabbing; }
#stage.pointing { cursor: pointer; }

#grain, #vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
#grain { mix-blend-mode: multiply; opacity: 0.42; background-repeat: repeat; background-size: 320px 320px; }
#vignette {
  background:
    radial-gradient(120% 90% at 50% 42%, rgba(255, 245, 220, 0) 52%, rgba(60, 42, 20, 0.30) 100%);
}

/* ---------------- HUD ---------------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0 12px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

#brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(15px, 3.6vw, 24px);
  line-height: 0.98;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 1px 2px 0 var(--paper);
}
#brand h1 span { color: var(--accent); }
#brand .sub {
  margin: 3px 0 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.75;
}

#hud-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

#counter {
  display: flex;
  align-items: baseline;
  gap: 2px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 12px 10px 13px 11px;
  padding: 4px 10px 3px;
  box-shadow: var(--shadow);
  font-family: var(--serif);
  font-weight: bold;
  transform: rotate(-1.2deg);
}
#counter #foundN { font-size: 22px; color: var(--accent); }
#counter i { font-style: normal; opacity: 0.5; margin: 0 1px; }
#counter #totalN { font-size: 15px; opacity: 0.7; }
#counter em { font-style: normal; font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; margin-left: 4px; opacity: 0.6; }

.inkbtn {
  font-family: var(--serif);
  font-weight: bold;
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 11px 9px 12px 10px;
  padding: 7px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, background 0.15s;
}
.inkbtn:hover { background: #fff7e4; }
.inkbtn:active { transform: translateY(2px) rotate(0.5deg); box-shadow: 0 3px 0 rgba(23,19,14,0.18); }
.inkbtn.icon { font-size: 16px; padding: 6px 10px; }
.inkbtn.small { font-size: 11px; padding: 5px 9px; }
.inkbtn.off { opacity: 0.45; text-decoration: line-through; }

/* ---------------- checklist ---------------- */
.panel {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  right: 12px;
  z-index: 12;
  width: min(330px, calc(100vw - 24px));
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px 13px 17px 14px;
  box-shadow: var(--shadow);
  padding: 12px 14px 12px;
  transform-origin: top right;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.panel[hidden] { display: block; }
.panel.closed { transform: scale(0.9) translateY(-6px); opacity: 0; pointer-events: none; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.panel-head h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.x {
  border: none; background: none; font-size: 22px; line-height: 1;
  color: var(--ink); cursor: pointer; padding: 0 2px; opacity: 0.6;
}
.x:hover { opacity: 1; }
#list { list-style: none; margin: 6px 0 8px; padding: 0; max-height: min(46vh, 360px); overflow: auto; }
#list li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 2px;
  border-bottom: 1.5px dashed rgba(23, 19, 14, 0.22);
  font-size: 13px;
}
#list li:last-child { border-bottom: none; }
#list .tick {
  flex: 0 0 auto;
  width: 19px; height: 19px;
  border: 2.5px solid var(--ink);
  border-radius: 5px 4px 6px 4px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: bold;
  background: #fff;
}
#list li.done .tick { background: var(--accent); color: var(--paper); }
#list .nm { font-family: var(--serif); font-weight: bold; }
#list li:not(.done) .nm { opacity: 0.55; }
#list .hn { display: block; font-size: 11px; opacity: 0.6; font-family: var(--sans); font-weight: normal; }
.panel-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tiny { font-size: 10px; opacity: 0.6; }

/* ---------------- toast + hint line ---------------- */
#toast {
  position: absolute;
  left: 50%;
  top: calc(78px + env(safe-area-inset-top));
  transform: translateX(-50%) translateY(-14px) rotate(-1deg);
  z-index: 14;
  background: var(--accent);
  color: #fff4dd;
  font-family: var(--serif);
  font-weight: bold;
  font-size: clamp(13px, 3.4vw, 17px);
  padding: 9px 18px;
  border: 3px solid var(--ink);
  border-radius: 14px 11px 15px 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-1deg); }

#hintline {
  position: absolute;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(243, 231, 205, 0.88);
  border: 2.5px solid var(--ink);
  border-radius: 12px 10px 13px 11px;
  padding: 6px 14px;
  font-size: clamp(10px, 2.9vw, 12.5px);
  font-family: var(--serif);
  box-shadow: var(--shadow);
  max-width: 92vw;
  text-align: center;
  transition: opacity 0.4s;
}
#hintline.fade { opacity: 0.0; }

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(80% 70% at 50% 40%, rgba(60, 44, 22, 0.35), rgba(30, 22, 12, 0.72));
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }

.card {
  width: min(560px, 94vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 20px 16px 22px 18px;
  box-shadow: 0 10px 0 rgba(23,19,14,0.25), 0 26px 50px rgba(0,0,0,0.4);
  padding: clamp(18px, 4vw, 34px) clamp(18px, 4.5vw, 40px);
  text-align: center;
  transform: rotate(-0.4deg);
}
.card::after {
  content: "";
  display: block;
  position: absolute;
}
.kicker {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: bold;
}
.card .big {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(30px, 8.5vw, 56px);
  line-height: 0.96;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}
.lede {
  font-family: var(--serif);
  font-size: clamp(13px, 3.5vw, 16px);
  line-height: 1.5;
  margin: 14px auto 10px;
  max-width: 42ch;
  opacity: 0.9;
}
.how {
  list-style: none;
  margin: 12px auto 18px;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 13px;
  max-width: 34ch;
  text-align: left;
}
.how li {
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 9px 7px 10px 8px;
  padding: 7px 11px;
}
.bigbtn {
  font-family: var(--serif);
  font-weight: bold;
  font-size: clamp(16px, 4.4vw, 21px);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--paper);
  background: var(--accent);
  border: 3.5px solid var(--ink);
  border-radius: 15px 12px 16px 13px;
  padding: 12px 30px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(23,19,14,0.35);
  transition: transform 0.08s ease;
}
.bigbtn:hover { background: #c04f36; }
.bigbtn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(23,19,14,0.35); }
.card .tiny { margin-top: 14px; }

.board { margin: 12px auto 6px; max-width: 34ch; text-align: left; }
.board h3 {
  font-family: var(--serif);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 6px;
  text-align: center;
  color: var(--accent);
}
.board ol { margin: 0; padding-left: 22px; font-family: var(--serif); font-size: 14px; }
.board li { padding: 2px 0; }
.board li.me { font-weight: bold; color: var(--accent); }

/* ---------------- loader ---------------- */
.loader { text-align: center; color: var(--paper); font-family: var(--serif); }
.loader .pencil {
  width: 54px; height: 12px;
  margin: 0 auto 14px;
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 3px;
  transform-origin: 0 50%;
  animation: scribble 0.9s ease-in-out infinite alternate;
}
@keyframes scribble { from { transform: rotate(-24deg); } to { transform: rotate(24deg); } }
.loader p { font-size: 15px; letter-spacing: 0.06em; }

/* ---------------- small screens ---------------- */
@media (max-width: 720px) {
  #brand .sub { display: none; }
  .panel {
    top: auto;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    border-radius: 18px 18px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    transform-origin: bottom center;
    max-height: 70vh;
  }
  .panel.closed { transform: translateY(100%); }
  #list { max-height: 52vh; }
  #hintline { bottom: calc(10px + env(safe-area-inset-bottom)); }
}

@media (max-height: 480px) and (orientation: landscape) {
  #brand h1 { font-size: 15px; }
  #counter { font-size: 12px; padding: 2px 8px 1px; }
  #counter #foundN { font-size: 17px; }
  .panel { top: 52px; max-height: 74vh; }
  #list { max-height: 50vh; }
  #hintline { display: none; }
}
