:root {
  color-scheme: light;
  --bg: #efe7d6;
  --surface: #fffaf0;
  --paper: #fbf5e6;
  --paper-edge: #e6dcc4;
  --ink: #2a2220;
  --ink-2: #5a4c44;
  --muted: #8c7d70;
  --line: rgba(42, 34, 32, 0.12);
  --bar: rgba(42, 34, 32, 0.26);
  --bar-pick: rgba(42, 34, 32, 0.4);
  --accent: #7a2331;
  --accent-2: #a8394a;
  --gold: #e0a526;
  --glow: rgba(224, 165, 38, 0.22);
  --shadow: rgba(60, 40, 20, 0.16);
  --r: 18px;
  --serif: Fraunces, Georgia, "Times New Roman", serif;
  --sans: "Petrov Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #16120f;
    --surface: #221c17;
    --paper: #2b241d;
    --paper-edge: #3a3128;
    --ink: #f3e9d8;
    --ink-2: #d4c6b2;
    --muted: #9a8b7a;
    --line: rgba(255, 240, 220, 0.1);
    --bar: rgba(243, 233, 216, 0.22);
    --bar-pick: rgba(243, 233, 216, 0.36);
    --accent: #e0788a;
    --accent-2: #f08fa0;
    --glow: rgba(224, 165, 38, 0.2);
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
h1 { margin: 0; font: 650 32px/1 var(--serif); letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.logo {
  width: 30px; height: 24px; position: relative;
  background: linear-gradient(90deg, var(--paper) 0 47%, var(--accent) 47% 53%, var(--paper) 53%);
  border: 2.5px solid var(--accent); border-radius: 3px 3px 6px 6px;
}
.sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.loading { color: var(--muted); text-align: center; margin: 60px 0; }

button { font: inherit; cursor: pointer; }
button.icon {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 700 18px var(--serif);
}
button.primary {
  border: 0; border-radius: 999px; padding: 11px 26px; background: var(--accent); color: #fff;
  font: 700 16px var(--sans); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 60%, #000);
}
button.primary:disabled { opacity: 0.5; box-shadow: none; cursor: default; }
button.primary.big { display: block; width: min(100%, 300px); margin: 6px auto 0; padding: 15px 26px; font-size: 19px; letter-spacing: 0.02em; }
button.primary.big.stop { background: var(--gold); color: #2a2220; box-shadow: 0 3px 0 #a87408; }
a.link { color: var(--ink-2); text-underline-offset: 3px; padding: 6px; font-size: 14px; display: inline-block; }
[hidden] { display: none !important; }

.book { display: flex; gap: 14px; align-items: center; background: var(--surface); border-radius: var(--r); padding: 12px 14px; box-shadow: 0 4px 16px var(--shadow); }
.book { border: 2px solid transparent; transform-origin: center; }
.book.now { border-color: var(--gold); box-shadow: 0 0 0 3px var(--glow), 0 4px 16px var(--shadow); }
.book.flick { animation: shelf 0.1s ease-out; }
@keyframes shelf {
  from { transform: translateY(-3px); }
  to { transform: none; }
}
.book.landed { animation: landed 0.45s ease-out; }
.book > div { min-width: 0; }
.book.now .title { min-height: 2.4em; }
.book .title { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book img { width: 52px; height: 78px; object-fit: cover; border-radius: 3px 6px 6px 3px; box-shadow: 2px 3px 8px var(--shadow); flex: none; background: var(--paper-edge); }
.kicker { margin: 0; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.12em; }
.title { margin: 2px 0 0; font: 600 20px/1.2 var(--serif); }
.author { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }

.stages { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0; margin: 14px 0; }
.stages li {
  text-align: center; padding: 6px 4px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0;
}
.stages small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.stages b { font: 600 15px/1.3 var(--serif); min-height: 1.3em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stages li.now { border-color: var(--gold); box-shadow: 0 0 0 2px var(--glow); }
.stages li.done b { color: var(--accent); }

.desk { text-align: center; margin-top: 14px; }
.sheet {
  position: relative; margin: 0 auto 4px; width: min(100%, 440px);
  border-radius: 3px 10px 10px 3px; background: var(--paper);
  box-shadow: 3px 3px 0 -1px var(--paper), 3px 3px 0 0 var(--paper-edge), 6px 6px 0 -1px var(--paper), 6px 6px 0 0 var(--paper-edge), 0 10px 26px var(--shadow);
  transform-origin: left center;
}
.sheet.flick { animation: flick 0.12s ease-out; }
@keyframes flick {
  from { transform: perspective(900px) rotateY(-9deg) translateX(-3px); filter: brightness(0.97); }
  to { transform: none; filter: none; }
}
.sheet.landed { animation: landed 0.45s ease-out; }
@keyframes landed {
  0% { transform: scale(1); }
  35% { transform: scale(1.025); }
  100% { transform: scale(1); }
}
canvas { display: block; width: 100%; border-radius: inherit; }
.reel {
  margin: 12px 0 0; min-height: 1.3em; font: 600 34px/1.3 var(--serif); color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reel:empty { display: none; }
.reel.landed { color: var(--accent); animation: landed 0.45s ease-out; }
.hint { margin: 10px 0 4px; color: var(--ink-2); min-height: 1.45em; }

.result { margin-top: 16px; background: var(--surface); border-radius: var(--r); padding: 18px 16px; text-align: center; box-shadow: 0 6px 22px var(--shadow); }
.word { margin: 4px 0 0; font: 650 44px/1.1 var(--serif); color: var(--accent); overflow-wrap: anywhere; }
.root { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.root:empty { display: none; }
.meanings { text-align: left; margin: 12px auto 0; max-width: 420px; padding-left: 1.4em; }
.meanings li { margin-bottom: 6px; }
.meanings i { color: var(--muted); font-style: italic; margin-right: 4px; }
.context {
  margin: 14px auto 0; max-width: 440px; padding: 10px 14px; text-align: left;
  font: 400 16px/1.55 var(--serif); color: var(--ink-2);
  background: var(--paper); border-left: 3px solid var(--accent); border-radius: 4px 10px 10px 4px;
}
.context mark { background: var(--glow); color: var(--accent); font-weight: 650; padding: 0 3px; border-radius: 4px; box-shadow: 0 0 0 1px var(--gold); }
.found { color: var(--ink-2); margin: 12px 0; font-size: 14px; }
.limerick { margin: 16px auto 14px; max-width: 440px; text-align: left; padding: 14px; border-radius: 14px; background: var(--paper); border: 1px solid var(--paper-edge); }
.limerick h2 { margin: 0; font: 650 19px/1.25 var(--serif); }
.lim-hint { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
.lim-hint b { color: var(--accent); }
.lines { display: grid; gap: 6px; }
.lines input {
  width: 100%; font: 400 16px/1.3 var(--serif); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
}
.lines input.short { width: calc(100% - 28px); margin-left: 28px; }
.lines input:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: transparent; }
.lines input::placeholder { color: var(--muted); font-style: italic; }
.written { margin: 0; font: 400 16px/1.55 var(--serif); color: var(--ink); white-space: pre-line; }
.written span { display: block; }
.written span.short { padding-left: 1.6em; }
.limerick button { display: block; margin: 12px auto 0; }
.lim-msg { margin: 8px 0 0; text-align: center; color: var(--ink-2); font-size: 13.5px; }
.lim-msg:empty { display: none; }
.lim-msg.bad { color: var(--accent); }
.lim-msg a { color: inherit; }
.toast { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; min-height: 0; }
.links { margin: 6px 0 0; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.credit { text-align: center; color: var(--muted); font-size: 12px; margin-top: 22px; }
.credit a { color: inherit; }

dialog { border: 0; border-radius: var(--r); padding: 20px 22px; max-width: 520px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
dialog::backdrop { background: rgba(20, 12, 8, 0.5); }
dialog h2 { margin: 0 0 8px; font: 650 24px var(--serif); }
dialog li { margin-bottom: 6px; }
dialog .keys { color: var(--muted); font-size: 13px; }
dialog form { text-align: center; margin-top: 12px; }
