@font-face { font-family: "Courier Prime"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/courier-prime-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Courier Prime"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/courier-prime-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Courier Prime"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/courier-prime-latin-700-normal.woff2") format("woff2"); }
:root {
  --bg: #fdf4e8; --card: #fffaf2; --ink: #17302c; --muted: #516761; --line: #ead9c4;
  --accent: #f58a2c; --accent-ink: #24120a; --link: #a84a0e;
  --green: #2c7a64; --yellow: #8f5a00; --red: #b3261e;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --type: "Courier Prime", "Courier New", Courier, monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1633; --card: #281f47; --ink: #f1ecf8; --muted: #b6acca; --line: #40356a;
          --accent: #ff9f6e; --accent-ink: #2a1208; --link: #c9baff;
          --green: #7fd6b0; --yellow: #f2c46b; --red: #ffa3a3; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

button { font: inherit; color: inherit; }
.link { background: none; border: 0; color: var(--link); padding: 10px 8px; min-height: 44px; font-size: 1rem; cursor: pointer; }
.big { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; font-size: 1.15rem; min-height: 56px; cursor: pointer; }
.big small { display: block; margin-top: 4px; color: var(--muted); font-size: .9rem; }
.big.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.big.primary small { color: inherit; opacity: .85; }
.big:disabled { opacity: .55; cursor: default; }
.soon { font-size: .75rem; color: var(--muted); margin-left: 6px; }
button.primary { border: 1px solid var(--accent); border-radius: 10px; padding: 10px 18px; min-height: 44px; font-size: 1rem; cursor: pointer; }
.danger { color: var(--red); }

.home-head { padding: 8vh 24px 8px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.home-head h1 { font-family: var(--font); font-size: clamp(30px, 8vw, 40px); line-height: 1.1; margin: 0; }
/* Alpha-mask sketch, drawn in the ink colour so it follows light and dark mode (same technique as Whistle:Staff). */
.hero { width: min(100%, 320px); aspect-ratio: 720 / 434; margin: 18px 0 8px; background: var(--ink);
        -webkit-mask: url("icons/logo-sketch.png") center / contain no-repeat; mask: url("icons/logo-sketch.png") center / contain no-repeat; }
@media (forced-colors: active) { .hero { background: CanvasText; } }
.tag { color: var(--muted); margin: 6px 0 0; }
.home-actions { padding: 24px; display: grid; gap: 12px; width: 100%; max-width: 608px; margin: 0 auto; }
.home-actions .big { border-radius: 22px; padding: 22px 24px; min-height: 92px; font-size: 1.15rem; display: flex; flex-direction: column; justify-content: center; box-shadow: 0 6px 18px rgb(0 0 0 / .12); }
.home-actions .big small { margin-top: 6px; }
.home-foot { margin-top: auto; padding: 12px 16px; text-align: center; }
.note { color: var(--muted); font-size: .9rem; padding: 0 24px; }
#screen-home .note { text-align: center; }

.bar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px; padding: 4px 8px; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 5; }
.bar h2 { margin: 0; font-size: 1.05rem; text-align: center; font-weight: 600; }
.title-input { width: 100%; border: 0; background: transparent; font: 600 1.05rem var(--ui); color: var(--ink); text-align: center; padding: 10px 4px; min-width: 0; }
.title-input:focus { outline: none; }
.choose { padding: 24px; display: grid; gap: 12px; }

.menu { position: absolute; right: 8px; top: calc(52px + env(safe-area-inset-top)); background: var(--card); border: 1px solid var(--line); border-radius: 12px; display: grid; min-width: 220px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.menu button { background: none; border: 0; text-align: left; padding: 14px 16px; min-height: 48px; font-size: 1rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.menu button:last-child { border-bottom: 0; }

.guided-bar { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.guided-bar label { display: grid; gap: 2px; font-size: .75rem; color: var(--muted); flex: 1; min-width: 0; }
.guided-bar input { font: 1rem var(--ui); padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); width: 100%; min-width: 0; }

.page { flex: 1; overflow-y: auto; padding: 12px 16px 120px; }
/* The writing sheet is always faded papyrus with dark ink, in light and dark mode. */
.editor-wrap { position: relative; background: #fbf6dc; border: 1px solid #ebe0b4; border-radius: 6px;
               box-shadow: 0 1px 2px rgba(60, 45, 10, .08), 0 6px 18px rgba(60, 45, 10, .08);
               color-scheme: light; --ink: #2b2718; --muted: #6b6247; --accent: #c46a1c;
               --green: #2c7a64; --yellow: #8f5a00; --red: #b3261e; }
.editor-wrap .text::placeholder { color: #8c8262; }
.text, .mirror { font: 1.15rem/1.7 var(--type); letter-spacing: 0; padding: 14px 4.2rem 14px 16px; white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; tab-size: 4; margin: 0; border: 0; width: 100%; }
.text { position: relative; display: block; background: transparent; color: var(--ink); resize: none; overflow: hidden; min-height: 40vh; caret-color: var(--accent); }
.text:focus { outline: none; }
.mirror { position: absolute; inset: 0; pointer-events: none; color: transparent; }
.mirror .ln { display: block; position: relative; min-height: 1.7em; }
.mirror .badge { position: absolute; right: -4.0rem; top: 0; width: 3.8rem; text-align: right; font: .72rem/1.7rem var(--ui); font-variant-numeric: tabular-nums; }
.badge.green { color: var(--green); } .badge.yellow { color: var(--yellow); } .badge.red { color: var(--red); font-weight: 700; }
.mirror .ln.red { text-decoration: underline wavy var(--red); text-decoration-thickness: 1px; text-decoration-color: transparent; }
.editor-wrap.freewrite .mirror { display: none; }
.editor-wrap.freewrite .text { padding-right: 16px; }

.readings { margin-top: 20px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: .9rem; }
.readings h3 { margin: 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.readings-note { margin: 4px 0 10px; color: var(--muted); }
.readings-list { display: grid; gap: 8px; }
.reading { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.reading-word { font-family: var(--font); font-size: 1.05rem; min-width: 6rem; }
.reading button { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; min-height: 40px; cursor: pointer; }
.reading button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.footer-card { margin-top: 28px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); display: grid; gap: 10px; font-size: .9rem; color: var(--muted); }
.footer-card label { display: grid; gap: 2px; }
.footer-card input { font: 1rem var(--ui); padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); min-height: 40px; }
.revised { margin: 0; }

.rhyme-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; z-index: 8; }
.hint { color: var(--muted); font-size: .85rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 70dvh; overflow-y: auto; background: var(--card); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); z-index: 15; box-shadow: 0 -8px 24px rgba(0,0,0,.18); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet .note { padding: 0; margin: 4px 0; }
.sheet h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; min-height: 44px; font: 1rem var(--font); cursor: pointer; }
.empty-chip { color: var(--muted); font-size: .9rem; }

.lib-tools { padding: 8px 12px; }
.lib-tools input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: 1rem var(--ui); }
.lib-list { list-style: none; margin: 0; padding: 0 12px 24px; display: grid; gap: 8px; }
.lib-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; text-align: left; width: 100%; }
.lib-item .t { font: 600 1.05rem var(--font); }
.lib-item .s { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.lib-item .p { color: var(--muted); font: .95rem var(--font); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.settings { padding: 16px; display: grid; gap: 16px; }
.settings label { display: grid; gap: 6px; color: var(--muted); font-size: .9rem; }
.settings input, .settings select { font: 1rem var(--ui); padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.settings .note { padding: 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; z-index: 30; font-size: .9rem; max-width: 90vw; }

.badge .lt { color: var(--link); font-weight: 700; margin-right: 2px; }

.badge .lt.warn { color: var(--red); }

.mirror mark.miss { background: color-mix(in srgb, var(--red) 28%, transparent); color: transparent; border-radius: 4px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--red) 28%, transparent); }

.guided-bar .wide { flex: 1 1 100%; }
.guided-bar select { font: 1rem var(--ui); padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); width: 100%; min-height: 40px; }
.guided-bar label.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--ink); }
.guided-bar label.check input { width: 20px; height: 20px; }
.g-note { margin: 0; font-size: .85rem; color: var(--muted); }

/* Segments: per-range scheme and meter */
.bar:has(#ed-mode:not([hidden])) { grid-template-columns: auto 1fr auto auto; }
.seg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.g-range { font-size: .8rem; color: var(--muted); margin-right: auto; }
.seg-actions button, .edit-actions button { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 40px; font-size: .9rem; cursor: pointer; }
.edit-actions button:disabled { opacity: .45; cursor: default; }

/* Text and mirror get the same wider gutter, so they stay aligned and line heights do not change. */
.editor-wrap.segmented .text, .editor-wrap.segmented .mirror { padding-left: 3.6rem; }
.mirror .seg-tag { position: absolute; left: calc(-3.6rem + 8px); top: 0; width: calc(3.6rem - 14px); color: var(--accent);
                   font: 700 .62rem/calc(1.15rem * 1.7) var(--ui); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mirror .ln.seg-start::before { content: ""; position: absolute; left: -3.6rem; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: 0 2px 2px 0; }

/* Edit mode: the mirror takes taps instead of the read-only textarea. */
.editor-wrap.editing .mirror { pointer-events: auto; z-index: 1; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.editor-wrap.editing .text { caret-color: transparent; }
.mirror .ln.sel { background: color-mix(in srgb, var(--accent) 20%, transparent); border-radius: 3px; }
.edit-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); z-index: 9; display: grid; gap: 6px; }
.edit-info { margin: 0; font-size: .85rem; color: var(--muted); }
.edit-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-field { display: grid; gap: 4px; margin: 10px 0 14px; font-size: .85rem; color: var(--muted); }
.seg-field input, .seg-field select { font: 1rem var(--ui); padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); min-height: 44px; }
