:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #2b2620;
  --ink-2: #6b6256;
  --ink-3: #b3a999;
  --line: #e4dccd;
  --accent: #8a5a2b;
  --accent-bg: #f1e4d2;
  --ok: #2b2620;
  --bad: #c0392b;
  --bad-bg: #fbe3df;
  --compose: #8a5a2b;
  --radius: 14px;
  --serif: "Gowun Batang", "Nanum Myeongjo", "AppleMyungjo", serif;
  --sans: "Gowun Dodum", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --paper: #262320;
    --ink: #efe8dc;
    --ink-2: #b5ab9c;
    --ink-3: #6e665b;
    --line: #3a352f;
    --accent: #e0b07a;
    --accent-bg: #3b2f22;
    --ok: #efe8dc;
    --bad: #ff8a7a;
    --bad-bg: #4a2722;
    --compose: #e0b07a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 640px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 20px 8px;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
.streak {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-bg); color: var(--accent);
  padding: 4px 12px; border-radius: 999px; font-size: 14px;
}
.streak svg { width: 16px; height: 16px; fill: currentColor; }

main { max-width: 640px; margin: 0 auto; padding: 8px 20px 24px; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.h1 { font-family: var(--serif); font-size: 24px; font-weight: 700; line-height: 1.4; margin: 16px 0 8px; }
.lead { color: var(--ink-2); margin: 0 0 20px; }
.center { text-align: center; }
.hint { color: var(--ink-2); font-size: 13px; margin: 8px 0 0; }
.msg { font-size: 14px; color: var(--accent); min-height: 1.4em; margin: 12px 0 0; }
.msg.error { color: var(--bad); }

.meta-row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 12px; }
.date { color: var(--ink-2); font-size: 14px; }
.tag { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--accent-bg); color: var(--accent); }

.paper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px 18px;
}
.paper.small { margin: 20px 0; }
.quote {
  font-family: var(--serif);
  font-size: 21px;
  line-height: 2.15em;
  margin: 0;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(2.15em - 1px), var(--line) calc(2.15em - 1px), var(--line) 2.15em);
}
.quote.plain { font-size: 18px; color: var(--ink); }
.quote .c { color: var(--ink-3); transition: color .12s; }
.quote .c.ok { color: var(--ok); }
.quote .c.bad { color: var(--bad); background: var(--bad-bg); border-radius: 3px; text-decoration: underline wavy var(--bad); text-underline-offset: 4px; }
.quote .c.composing { color: var(--compose); text-decoration: underline; text-underline-offset: 4px; }
.quote .c.next { box-shadow: inset 0 -2px 0 var(--accent); }
.quote .nl { font-family: var(--sans); font-size: 14px; color: var(--bad); }
.byline { text-align: right; color: var(--ink-2); font-size: 14px; margin: 10px 0 0; }

.typing {
  width: 100%;
  margin-top: 16px;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.8;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  resize: vertical;
  outline: none;
}
.typing:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.typing.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.status-row { display: flex; gap: 12px; align-items: center; font-size: 14px; color: var(--ink-2); margin-top: 8px; }
.status-row .wrong { color: var(--bad); }
.status-row .link { margin-left: auto; }

.btn {
  font: inherit; font-size: 16px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 12px; padding: 12px 18px; cursor: pointer; width: 100%;
}
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn:active { transform: scale(0.98); }
.link { font: inherit; font-size: 14px; background: none; border: none; color: var(--accent); cursor: pointer; padding: 4px; }
.actions { display: grid; gap: 10px; margin-top: 20px; }
.actions.tight { margin-top: 14px; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.field-label { font-weight: 700; margin-bottom: 8px; display: block; }
.dial {
  position: relative;
  display: grid; grid-template-columns: 0.9fr 1fr 1fr;
  height: 220px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
.dial::before {
  content: ""; position: absolute; left: 8px; right: 8px; top: 88px; height: 44px;
  background: var(--accent-bg); border-radius: 10px; pointer-events: none;
}
.dial-col {
  position: relative;
  overflow-y: scroll; overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  padding: 88px 0;
  scrollbar-width: none;
  outline: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 30%, #000 70%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 30%, #000 70%, transparent);
}
.dial-col::-webkit-scrollbar { display: none; }
.dial-col:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 10px; }
.dial-item {
  height: 44px; line-height: 44px; text-align: center;
  scroll-snap-align: center;
  font-family: var(--serif); font-size: 18px; color: var(--ink-3);
  cursor: pointer; transition: color .12s, font-size .12s;
}
.dial-item.sel { color: var(--ink); font-size: 22px; font-weight: 700; }
.dial-summary { text-align: center; color: var(--accent); font-size: 14px; margin-top: 8px; }
.time-select { font: inherit; font-size: 18px; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.row-between { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; color: var(--ink-2); }
.pill { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--bg); color: var(--ink-2); }
.pill.on { background: var(--accent-bg); color: var(--accent); }
.steps { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 14px; }

.done-mark { width: 64px; height: 64px; margin: 24px auto 0; border-radius: 50%; background: var(--accent-bg); display: grid; place-items: center; }
.done-mark svg { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 18px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-n { font-family: var(--serif); font-size: 28px; font-weight: 700; }
.stat-l { color: var(--ink-2); font-size: 13px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.history .h-date { font-size: 13px; color: var(--ink-2); }
.history .h-text { font-family: var(--serif); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { color: var(--ink-2); text-align: center; margin-top: 32px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 0 1 120px; display: grid; justify-items: center; gap: 2px;
  font: inherit; font-size: 12px; color: var(--ink-2);
  background: none; border: none; padding: 6px; cursor: pointer; border-radius: 10px;
}
.tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--accent); background: var(--accent-bg); }
body.onboarding .tabs { display: none; }
