/* Book - read on a phone first, on a tablet second, on a computer when it happens. */

:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #23201b;
  --muted: #7a7266;
  --line: #e4dccd;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
  --now: rgba(138, 90, 43, 0.13);
  --panel: #efe7d8;
  --danger: #a33a2a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1b1a17;
    --card: #24221e;
    --ink: #ece5d8;
    --muted: #9d9486;
    --line: #37332c;
    --accent: #d59a5c;
    --accent-ink: #1b1a17;
    --now: rgba(213, 154, 92, 0.16);
    --panel: #2a2722;
    --danger: #e0715f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ----------------------------------------------------------------- frame */

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: 0.2px; }
.top .title { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent; cursor: pointer;
}
.icon:active { background: var(--now); }
.icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.content { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px calc(24px + var(--safe-bottom)); }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
}
.button.quiet { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.button:disabled { opacity: 0.55; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-size: 16px;
}
textarea.input { min-height: 120px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.note { color: var(--muted); font-size: 14px; line-height: 1.45; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }

/* --------------------------------------------------------------- sign in */

.welcome { max-width: 420px; margin: 0 auto; padding: calc(48px + var(--safe-top)) 20px 32px; }
.welcome h1 { font-family: var(--serif); font-size: 40px; margin: 0 0 6px; }
.welcome p { margin: 0 0 28px; }

/* --------------------------------------------------------------- library */

.add { display: flex; gap: 8px; margin-bottom: 18px; }
.add .input { flex: 1; min-width: 0; }
.books { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .books { grid-template-columns: 1fr 1fr; } }
.book {
  display: flex; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--card); cursor: pointer; text-align: left; width: 100%;
}
.book:active { background: var(--now); }
.book img, .book .cover {
  flex: none; width: 112px; height: 63px; border-radius: 10px; object-fit: cover; background: var(--panel);
}
.book .about { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.book .name { font-weight: 600; font-size: 15px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .by { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: auto; }
.bar span { display: block; height: 100%; background: var(--accent); }
.state { font-size: 13px; color: var(--accent); }
.state.failed { color: var(--danger); }
.row-actions { display: flex; gap: 8px; margin-top: 6px; }
.row-actions .button { min-height: 34px; padding: 0 12px; font-size: 14px; }
.empty { text-align: center; padding: 48px 12px; }

/* ------------------------------------------------------------------ reader */

.reader { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--paper); }
.reader .top { position: relative; }
.progress-line { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--accent); transition: width 0.4s linear; }
.page {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 24px 20px 50vh;
  font-family: var(--serif); font-size: var(--reading-size, 21px); line-height: 1.62;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: pan-y;
  transition: flex-basis 0.32s ease;
}
.page .inner { max-width: 680px; margin: 0 auto; }
.page p { margin: 0 0 1em; text-indent: 1.4em; }
.page p:first-child { text-indent: 0; }
.s { border-radius: 4px; transition: background-color 0.25s, color 0.25s; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.s.past { color: var(--ink); }
.s.now { background: var(--now); }
.page.inspecting .s { cursor: pointer; }
.both .pair { margin: 0 0 0.9em; }
.both .pair .t { display: block; font-family: var(--sans); font-size: 0.74em; line-height: 1.45; color: var(--muted); margin-top: 0.15em; }
.both .pair.now .s { background: var(--now); }
.word-hit { background: var(--accent); color: var(--accent-ink); border-radius: 3px; }

.panel {
  position: absolute; left: 0; right: 0; bottom: 0; height: 50%;
  display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(105%); transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 6;
}
.panel.shown { transform: translateY(0); }
.panel .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; flex: none; }
.panel .lang { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 8px 20px 0; }
.panel .body { flex: 1; overflow-y: auto; padding: 8px 20px calc(96px + var(--safe-bottom)); font-family: var(--serif); font-size: 19px; line-height: 1.55; }
.panel .body .t.now { background: var(--now); border-radius: 4px; }
.panel .body .t { opacity: 0.6; }
.panel .body .t.now { opacity: 1; }

.play {
  position: absolute; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 8;
  width: 68px; height: 68px; margin-left: -34px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}
.play.hidden { transform: scale(0.6); opacity: 0; pointer-events: none; }
.play svg { width: 30px; height: 30px; fill: currentColor; margin-left: 4px; }
.hint {
  position: absolute; left: 16px; right: 16px; bottom: calc(104px + var(--safe-bottom)); z-index: 7;
  text-align: center; font-size: 13px; color: var(--muted); pointer-events: none;
}
.waiting { text-align: center; padding: 40px 20px; color: var(--muted); font-family: var(--sans); font-size: 15px; }

.sheet-back { position: absolute; inset: 0; z-index: 9; background: rgba(0, 0, 0, 0.25); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.sheet-back.shown { opacity: 1; pointer-events: auto; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 10; max-height: 78%;
  display: flex; flex-direction: column;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
  transform: translateY(105%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.shown { transform: translateY(0); }
.sheet .head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 6px 20px; }
.sheet .head .word { flex: 1; min-width: 0; }
.sheet .head .word b { font-family: var(--serif); font-size: 26px; }
.sheet .head .word span { display: block; color: var(--muted); font-size: 15px; }
.sheet .body { overflow-y: auto; padding: 4px 20px calc(24px + var(--safe-bottom)); line-height: 1.5; }
.sheet .translation { font-size: 17px; font-weight: 600; color: var(--accent); margin: 2px 0 10px; }
.sheet .part { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.sheet ol { margin: 0; padding-left: 20px; }
.sheet li { margin-bottom: 10px; }
.sheet .meaning-native { color: var(--accent); font-size: 15px; }
.sheet .example { color: var(--muted); font-style: italic; font-size: 15px; margin-top: 2px; }
.speak { flex: none; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; }
.choice input { margin-top: 3px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.choice b { display: block; font-size: 15px; }
.choice span { color: var(--muted); font-size: 13px; }
.link-box { display: flex; gap: 8px; margin-top: 10px; }
.link-box .input { flex: 1; min-width: 0; font-size: 13px; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.people li div { flex: 1; min-width: 0; }
.people small { display: block; color: var(--muted); }
.saved { font-size: 13px; color: var(--accent); min-height: 18px; }
