/* Script: calm, typographic, paper-like. System fonts only. */

:root {
  --paper: #f5f2ea;
  --ink: #16150f;
  --muted: #5c594d;
  --line: #d9d4c5;
  --line-strong: #a39e8d;
  --tint: #e8e3d4;
  --field: #fbf9f4;
  --danger: #9b2c1d;
  --focus: #1d5fd1;
  --script-size: 24px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12120f;
    --ink: #ece8dc;
    --muted: #a8a393;
    --line: #2f2e27;
    --line-strong: #6b6759;
    --tint: #24231d;
    --field: #1a1a16;
    --danger: #f0998a;
    --focus: #8fb8ff;
  }
}

:root[data-text-size="0"] { --script-size: 20px; }
:root[data-text-size="1"] { --script-size: 24px; }
:root[data-text-size="2"] { --script-size: 28px; }

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

em, i, cite, address, dfn, var { font-style: normal; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  font-style: normal;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

h1, h2, p, ul, ol, fieldset, legend { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }

a { color: inherit; text-underline-offset: 3px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
h1[tabindex="-1"]:focus { outline: none; }

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

.view {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 38rem;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

.noscript {
  max-width: 38rem;
  margin: 0 auto;
  padding: 16px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.top h1 {
  min-width: 0;
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
}
.top-links { flex: none; }
.top-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
}

h2 {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
}
h2.label, legend {
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
legend { margin-bottom: 8px; }

.hint, .meta { color: var(--muted); font-size: 0.9375rem; }

.credit {
  margin-top: auto;
  padding-top: 24px;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}

/* ---------- notice ---------- */

#notice {
  position: fixed;
  z-index: 20;
  top: calc(8px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  max-width: 36rem;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9375rem;
  font-weight: 500;
}
#notice:empty { display: none; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--tint); }
.btn.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}
.btn.primary:hover { background: var(--ink); }
.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}
.btn.small {
  padding: 6px 14px;
  font-size: 0.9375rem;
}
.btn.big {
  width: 100%;
  min-height: 56px;
  font-size: 1.125rem;
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn:disabled:hover { background: transparent; }

.form-actions, .row-actions, .toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

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

.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 24px;
  padding-top: 8px;
}
.method {
  display: flex;
  flex-direction: column;
  gap: 10px;
  counter-reset: step;
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 1.4;
}
.method li {
  position: relative;
  padding-left: 2rem;
  counter-increment: step;
}
.method li::before {
  content: counter(step) ".";
  position: absolute;
  left: 0;
  color: var(--muted);
}

.banner {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--tint);
  font-size: 0.9375rem;
}
.banner a {
  display: inline-block;
  padding: 10px 0;
  font-weight: 600;
}

.scripts {
  display: flex;
  flex-direction: column;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
}
.card:last-child { border-bottom: 1px solid var(--line); }

.sections { display: flex; flex-direction: column; }
.section-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 0;
  border-top: 1px dotted var(--line-strong);
  text-decoration: none;
}
.section-name {
  min-width: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.section-progress {
  flex: none;
  color: var(--muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.confirm-text { flex: 1 1 100%; font-weight: 600; }

/* ---------- forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label { font-weight: 600; }

input[type="text"], textarea {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}
textarea {
  min-height: 42vh;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.5;
  resize: vertical;
}

input[type="file"] {
  max-width: 100%;
  min-height: 44px;
  color: var(--muted);
  font: inherit;
  font-size: 0.9375rem;
}
input[type="file"]::file-selector-button {
  min-height: 44px;
  margin-right: 12px;
  padding: 8px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.count [data-count] { color: var(--ink); font-weight: 600; }

.chips, .section-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  position: relative;
  display: inline-flex;
}
.chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chip span, .chip-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
}
.chip input:checked + span, .chip-link[aria-current="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}
.chip input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
.check input {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--ink);
}

.estimate {
  font-family: var(--serif);
  font-size: 1.25rem;
}
.warn {
  padding: 12px 14px;
  border-left: 3px solid var(--danger);
  background: var(--tint);
  font-size: 0.9375rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.confirm-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--danger);
  border-radius: 10px;
}

/* ---------- train ---------- */

.view-train {
  gap: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.train-top {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.train-top h1 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.stats [data-stat="reads"] { color: var(--ink); font-weight: 600; }

#script-view {
  flex: 1 0 auto;
  padding: 24px 0 40px;
  font-family: var(--serif);
  font-size: var(--script-size);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: default;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#script-view[data-state="train"] [data-kind="word"] { cursor: pointer; }

#script-view [data-kind="cue"] {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.75em;
  letter-spacing: 0.02em;
}

/* A hidden word. Its width comes from JS; the height sits inside the line box so lines never jump. */
.bar {
  display: inline-block;
  max-width: 100%;
  height: 0.9em;
  border-radius: 3px;
  background: currentColor;
  vertical-align: -0.14em;
  cursor: pointer;
}
.bar.peek {
  height: auto;
  background: var(--tint);
  line-height: 1.25;
  text-align: center;
  vertical-align: baseline;
}

.actions {
  position: sticky;
  z-index: 5;
  bottom: 0;
  margin: 0 -16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.actions-inner {
  display: grid;
  gap: 8px;
}
.actions-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.actions-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.actions-row .btn, .actions-pair .btn {
  width: 100%;
  padding-left: 8px;
  padding-right: 8px;
}
.actions-row .btn {
  border-color: var(--line);
  font-weight: 500;
}

@media (min-width: 48rem) {
  .view { padding-top: 40px; }
  .view-train { padding-top: 0; }
  .train-top { padding-top: 16px; }
  #script-view { padding-top: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
