:root {
  --paper: #faf7f1;
  --surface: #fffdf8;
  --surface-2: #f3ede2;
  --ink: #241f19;
  --ink-2: #5f564a;
  --ink-3: #8d8172;
  --line: #e7ddcc;
  --accent: #b45309;
  --accent-ink: #8a3f06;
  --accent-wash: #fdf1e0;
  --green: #3f7d5a;
  --green-solid: #4b8b63;
  --gold-solid: #c9973c;
  --grey-solid: #c9c1b4;
  --shadow: 0 2px 8px rgba(36,25,25,.07), 0 1px 3px rgba(36,25,25,.05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --paper: #12100e; --surface: #1a1714; --surface-2: #221d19;
  --ink: #f2ece1; --ink-2: #b6aa9a; --ink-3: #8a7e6f;
  --line: #2e2822; --accent: #e8a33d; --accent-ink: #f0b661; --accent-wash: #2a2016;
  --green-solid: #4f8f66; --gold-solid: #b8912f; --grey-solid: #494136;
  --shadow: 0 2px 8px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app { max-width: 620px; margin: 0 auto; padding: 22px 18px calc(28px + env(safe-area-inset-bottom)); min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-ink));
  color: #fff; font-family: var(--serif); font-weight: 700; font-size: 16px;
  box-shadow: var(--shadow);
}
h1 { font-family: var(--serif); font-size: 21px; margin: 0; letter-spacing: -.01em; font-weight: 600; }
.sub { margin: 1px 0 0; font-size: 12px; color: var(--ink-3); letter-spacing: .03em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- verse ---------- */
.verse-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 22px 18px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.verse {
  font-family: var(--serif); font-size: 19px; line-height: 1.72; margin: 0 0 12px; color: var(--ink);
}
.blank {
  display: inline-block; border-bottom: 2px solid var(--gold-solid);
  color: var(--ink-3); letter-spacing: .12em; font-family: var(--sans);
  font-size: 15px; padding: 0 2px; min-width: 3ch; text-align: center;
}
.ref { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- grid ---------- */
.grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.row { display: flex; gap: 8px; justify-content: center; }
.tile {
  flex: 1 1 0; max-width: 62px; aspect-ratio: 1;
  display: grid; place-items: center;
  border: 1.5px solid var(--line); border-radius: 9px; background: var(--surface);
  font-family: var(--sans); font-weight: 700; font-size: 20px; text-transform: uppercase;
  color: var(--ink); transition: transform .1s;
}
.tile.filled { border-color: var(--ink-3); }
.tile.green { background: var(--green-solid); border-color: var(--green-solid); color: #fff; }
.tile.gold  { background: var(--gold-solid);  border-color: var(--gold-solid);  color: #fff; }
.tile.grey  { background: var(--grey-solid);  border-color: var(--grey-solid);  color: #fff; }
.row.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- entry ---------- */
.entry { display: flex; gap: 8px; margin-bottom: 8px; }
.entry input {
  flex: 1; padding: 13px 15px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 16px; font-family: inherit;
  text-transform: lowercase;
}
.entry input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 20px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 14.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); }
.hint { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-3); text-align: center; min-height: 18px; }

/* ---------- reveal ---------- */
.reveal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px 22px; box-shadow: var(--shadow); animation: pop .25s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.reveal-head { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.badge {
  display: inline-flex; padding: 4px 11px; border-radius: 999px;
  background: var(--accent-wash); color: var(--accent-ink); font-size: 12px; font-weight: 700;
}
.badge.ghost { background: var(--surface-2); color: var(--ink-2); }
:root[data-theme="dark"] .badge { color: var(--accent); }
.verse-full { font-family: var(--serif); font-size: 17.5px; line-height: 1.7; margin: 0 0 14px; }
.verse-full mark { background: var(--accent-wash); color: var(--accent-ink); padding: 0 3px; border-radius: 3px; }
.teaching {
  font-size: 15px; line-height: 1.65; color: var(--ink-2);
  border-left: 3px solid var(--gold-solid); padding-left: 14px; margin: 0 0 18px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- footer ---------- */
.foot { margin-top: auto; padding-top: 26px; text-align: center; color: var(--ink-3); font-size: 12.5px; }
.foot p { margin: 0 0 4px; }
.foot .tiny { font-size: 11px; opacity: .75; }

/* ---------- modal + toast ---------- */
.modal-wrap {
  position: fixed; inset: 0; background: rgba(20,16,12,.45); z-index: 50;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(430px, 100%); background: var(--surface); border-radius: 16px;
  padding: 22px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal h2 { font-family: var(--serif); font-size: 20px; margin: 0 0 14px; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.stat { text-align: center; }
.stat .n { font-family: var(--serif); font-size: 24px; font-weight: 700; line-height: 1; }
.stat .l { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-top: 4px; }
.dist-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; font-size: 12.5px; }
.dist-row .label { width: 12px; color: var(--ink-3); }
.dist-row .bar { height: 18px; background: var(--grey-solid); border-radius: 4px; min-width: 18px; }
.dist-row .bar span { display: block; color: #fff; font-weight: 700; font-size: 11px; padding-left: 6px; line-height: 18px; }
.dist-row.now .bar { background: var(--green-solid); }
.modal .actions { margin-top: 18px; justify-content: flex-end; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; z-index: 60;
}

@media (max-width: 420px) {
  .tile { font-size: 17px; border-radius: 7px; }
  .row { gap: 6px; }
  .verse { font-size: 17.5px; }
}

/* flex fix: let the input shrink so the button stays on screen */
.entry input { min-width: 0; }
.entry { width: 100%; }
