/* Patternly — quiet, wood-toned, unhurried.
   Warm neutrals, one walnut accent + one ochre accent, light + dark via prefers-color-scheme. */

:root {
  --bg: oklch(96.5% 0.012 75);
  --surface: oklch(98.5% 0.007 75);
  --text: oklch(27% 0.025 55);
  --muted: oklch(53% 0.03 55);
  --line: oklch(87% 0.022 70);
  --accent: oklch(48% 0.085 45);
  --accent-soft: oklch(92.5% 0.028 60);
  --accent2: oklch(50% 0.085 95);
  --accent2-soft: oklch(92.5% 0.03 95);
  --good: oklch(46% 0.07 145);
  --bad: oklch(47% 0.1 30);
  --good-cell: oklch(56% 0.09 145);
  --bad-cell: oklch(56% 0.1 30);
  --dot-on: oklch(27% 0.025 55);
  --shadow: 0 1px 2px rgba(60,42,24,.07), 0 8px 22px rgba(60,42,24,.09);
  --radius: 11px;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Lora", Georgia, "Iowan Old Style", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(21% 0.017 50);
    --surface: oklch(25.5% 0.018 50);
    --text: oklch(92% 0.018 70);
    --muted: oklch(66% 0.025 60);
    --line: oklch(33% 0.02 50);
    --accent: oklch(74% 0.08 55);
    --accent-soft: oklch(31% 0.035 55);
    --accent2: oklch(76% 0.08 95);
    --accent2-soft: oklch(31% 0.035 95);
    --good: oklch(68% 0.09 145);
    --bad: oklch(68% 0.1 30);
    --good-cell: oklch(60% 0.09 145);
    --bad-cell: oklch(60% 0.1 30);
    --dot-on: oklch(92% 0.018 70);
    --shadow: 0 1px 2px rgba(0,0,0,.32), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 460px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
}

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  cursor: pointer;
  background: none; border: none; color: var(--text);
  font-family: var(--serif);
  text-decoration: none;
}
.nav-link { text-decoration: none; }
a.arch-item { text-decoration: none; }
.community-empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 15px; }
.sort-row { display: flex; align-items: center; gap: 8px; margin: 22px 0 14px; flex-wrap: wrap; }
.sort-btn {
  padding: 7px 14px; font-size: 13px; font-weight: 600; font-family: inherit;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); cursor: pointer;
}
.sort-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.submit-link { margin-left: auto; font-size: 14px; }
.arch-item .ai-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.arch-item .ai-author { color: var(--accent); }
.brand span { color: var(--accent); }
.header-btns { display: flex; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  min-width: 40px;
  min-height: 40px;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- screens ---------- */
main { flex: 1; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; flex-direction: column; padding: 24px 0; }
.screen.active { display: flex; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- home ---------- */
.home-top { text-align: center; margin-bottom: 28px; }
.home-date { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .08em; }
.home-streak { margin-top: 10px; font-size: 15px; }
.home-streak b { font-size: 17px; }
.tagline { color: var(--muted); font-size: 15px; margin-top: 6px; }

.mode-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform .12s ease, border-color .12s ease;
}
.mode-card:hover { transform: translateY(-1px); border-color: var(--accent); }
.mode-card .mc-left { display: flex; flex-direction: column; gap: 3px; }
.mode-card .mc-title { font-size: 20px; font-weight: 600; font-family: var(--serif); }
.mode-card .mc-sub { font-size: 13px; color: var(--muted); }
.mode-card .mc-status { font-size: 26px; }
.mode-card.solved { border-color: var(--good); }
.mode-card.failed { border-color: var(--line); opacity: .85; }
.mc-badge {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 9px; border-radius: 999px; color: var(--accent); background: var(--accent-soft);
}
.mc-badge.hard { color: var(--accent2); background: var(--accent2-soft); }

.home-foot { margin-top: auto; text-align: center; padding-top: 20px; }
.link-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-family: inherit; font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--accent); }

/* ---------- puzzle ---------- */
.puzzle-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.back { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; font-family: inherit; padding: 6px 0; }
.back:hover { color: var(--accent); }
.lives { display: flex; gap: 8px; align-items: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--dot-on); transition: all .3s ease; }
.dot.lost { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }

.examples { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 8px; }
.eqrow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 26px;
  padding: 9px 0;
}
.eqrow .in { text-align: right; }
.eqrow .out { text-align: left; font-weight: 700; }
.eqrow .arrow { color: var(--muted); font-size: 20px; }
.eqrow.question { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 18px; }
.eqrow.question .out { color: var(--accent); }

.guess-display {
  font-family: var(--mono);
  font-size: 30px;
  text-align: center;
  min-height: 46px;
  padding: 6px;
  color: var(--accent);
  letter-spacing: .04em;
}
.guess-display.empty { color: var(--line); }
.guess-display.shake { animation: shake .4s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.wrong-list { text-align: center; min-height: 22px; margin-bottom: 6px; font-family: var(--mono); font-size: 14px; color: var(--muted); }
.wrong-list span { text-decoration: line-through; margin: 0 5px; }

.pad-wrap { margin-top: auto; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  padding: 16px 0;
  font-size: 22px;
  font-family: var(--mono);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  transition: background .1s ease, transform .05s ease;
}
.key:hover { background: var(--accent-soft); }
.key:active { transform: scale(.96); }
.key.util { font-size: 15px; color: var(--muted); font-family: var(--sans); }

.guess-btn {
  width: 100%;
  margin-top: 10px;
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .12s ease, background .12s ease;
}
.guess-btn:disabled { opacity: .4; cursor: default; }
.guess-btn.confirm { background: var(--good); }

/* ---------- result ---------- */
.result-inner { text-align: center; display: flex; flex-direction: column; gap: 0; }
.result-emoji { font-size: 48px; margin-top: 8px; }
.result-title { font-size: 26px; font-weight: 600; font-family: var(--serif); margin-top: 6px; }
.result-title.win { color: var(--good); }
.result-title.lose { color: var(--bad); }
.result-sub { color: var(--muted); font-size: 15px; margin-top: 4px; }

.reveal-card {
  margin: 22px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  animation: reveal .5s cubic-bezier(.2,.7,.3,1);
}
@keyframes reveal { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.reveal-label { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.reveal-rule { font-size: 22px; font-weight: 600; font-family: var(--serif); margin: 8px 0 14px; }
.reveal-eq { font-family: var(--mono); font-size: 22px; }
.reveal-eq b { color: var(--accent); }
.solve-rate { margin-top: 14px; font-size: 14px; color: var(--muted); }
.solve-rate b { color: var(--text); }

.stat-strip { display: flex; justify-content: center; gap: 26px; margin: 6px 0 22px; }
.stat-strip .s { display: flex; flex-direction: column; }
.stat-strip .num { font-size: 26px; font-weight: 800; }
.stat-strip .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.share-btn {
  width: 100%; padding: 16px; font-size: 17px; font-weight: 700;
  border: none; border-radius: 12px; background: var(--accent); color: #fff;
  cursor: pointer; font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.share-btn:active { transform: scale(.98); }
.countdown { margin-top: 18px; color: var(--muted); font-size: 14px; }
.countdown b { font-family: var(--mono); color: var(--text); }
.report-row { margin-top: 14px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.overlay.active { display: flex; animation: fade .2s ease; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 26px 24px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow); position: relative;
  max-height: 88dvh; overflow-y: auto;
}
.modal h2 { font-size: 20px; font-weight: 600; font-family: var(--serif); margin-bottom: 4px; }
.modal .close { position: absolute; top: 12px; right: 14px; }
.modal p.mut { color: var(--muted); font-size: 14px; margin-bottom: 16px; }

.dist-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 14px; }
.dist-row .k { width: 58px; color: var(--muted); }
.dist-bar { height: 24px; background: var(--accent); border-radius: 6px; min-width: 26px; color: #fff;
  display: flex; align-items: center; justify-content: flex-end; padding: 0 8px; font-weight: 700; font-family: var(--mono); font-size: 13px; }
.dist-bar.fail { background: var(--muted); }

.stats-auth { color: var(--muted); font-size: 13px; margin: 2px 0 16px; }
.stats-auth .auth-link { font-size: 13px; padding: 0; color: var(--muted); background: none; border: none; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-family: inherit; }
.stats-auth .auth-link:hover { color: var(--accent); }
.stats-auth #signInForm { margin-top: 8px; }
.stats-auth .report-input { font-size: 14px; padding: 10px; margin: 0 0 8px; }
.stats-auth .modal-btn { padding: 10px; font-size: 14px; }
.stats-auth .auth-btn-row { display: flex; gap: 8px; }
.stats-auth .auth-btn-row .modal-btn { flex: 1; }
.stats-auth .modal-btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }

.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 4px; margin: 8px 0 22px; text-align: center; }
.stats-grid .num { font-size: 24px; font-weight: 800; }
.stats-grid .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.report-opt {
  display: block; width: 100%; text-align: left; padding: 14px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
  cursor: pointer; font-family: inherit; font-size: 15px;
}
.report-opt:hover { border-color: var(--accent); background: var(--accent-soft); }
.report-opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.report-opt .rt { font-weight: 700; }
.report-opt .rd { font-size: 13px; color: var(--muted); margin-top: 2px; }
.report-input {
  width: 100%; padding: 12px; font-size: 16px; font-family: var(--mono);
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); margin: 4px 0 14px;
}
.report-input:focus { outline: none; border-color: var(--accent); }
.modal-btn {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 700; border: none;
  border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer; font-family: inherit;
}
.modal-btn:disabled { opacity: .4; cursor: default; }

.how-step { display: flex; gap: 12px; margin: 14px 0; align-items: flex-start; }
.how-num { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.how-step .ht { font-size: 15px; }
.how-step .ht b { color: var(--accent); }
.mono-inline { font-family: var(--mono); }

/* ---------- archive ---------- */
.archive-list { display: flex; flex-direction: column; gap: 8px; }
.arch-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 5px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  cursor: pointer; font-family: inherit; color: inherit; text-align: left;
}
.arch-item:hover { border-color: var(--accent); }
.arch-item .ai-eq { font-family: var(--mono); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.arch-section-title { font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 18px 0 8px; }
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 60; opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.toast.show { opacity: 1; }
