:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6560;
  --border: #e5e0d8;
  --accent: #2d5a4a;
  --accent-soft: #e8f0ed;
  --input-bg: #fffef9;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

.header {
  flex-shrink: 0;
  padding: 0.55rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.top-quote {
  margin: 0 auto;
  padding: 0.6rem 1.25rem;
  max-width: 52rem;
  font-family: var(--font);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--muted);
  text-align: center;
  border: none;
  line-height: 1.4;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: 52rem;
  margin: 0 auto;
}

.brand {
  margin: 0;
  font-size: 0.78rem;
  font-family: var(--font);
  font-style: italic;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.brand a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.12em;
  font-weight: 600;
}

.brand a:hover {
  text-decoration-thickness: 2px;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.nav button,
.actions button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

.nav button:hover,
.actions button:hover,
.storage-controls button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.actions button:disabled:hover {
  background: var(--surface);
  border-color: var(--border);
}

.storage-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.storage-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.storage-toggle input {
  width: 0.9rem;
  height: 0.9rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.storage-controls button {
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  color: var(--muted);
  white-space: nowrap;
}

.storage-controls button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.position {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 4.5rem;
  text-align: center;
  font-size: 0.8rem;
}

.main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 2rem 1.5rem 2.5rem;
}

.statement-panel {
  width: 100%;
  max-width: 42rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.active-pill-slot {
  min-height: 2.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.active-pill {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  font-size: 0.8rem;
  font-style: italic;
  line-height: 1.3;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(45, 90, 74, 0.12);
  border-radius: 999px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

.active-pill.is-visible {
  visibility: visible;
  opacity: 1;
}

.statement-card {
  width: 100%;
  min-width: 0;
  padding: 2.75rem 3rem;
  background: #fff;
  border-radius: 4px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  cursor: text;
}

.statement {
  font-family: var(--font);
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  line-height: 1.8;
  color: var(--text);
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
  word-wrap: break-word;
  outline: none;
  cursor: text;
}

.statement .blank-wrap {
  display: inline;
}

/* Empty blanks: ghost suggestion inline in the sentence */
.statement .blank:not(.has-text):not(:focus) {
  background: rgba(45, 90, 74, 0.06);
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.statement .blank:not(.has-text)::after {
  content: attr(data-placeholder);
  color: #b5aea4;
  font-style: italic;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.statement .blank:not(.has-text):focus::after {
  opacity: 0;
}

.statement .blank {
  display: inline;
  vertical-align: baseline;
  outline: none;
  color: var(--text);
  caret-color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 0.05em 0.1em;
  margin: 0 -0.05em;
  border: none;
  border-radius: 3px;
  -webkit-user-modify: read-write-plaintext-only;
  user-modify: read-write-plaintext-only;
  transition: background 0.25s ease;
}

/* Typing: selection-like tint, no box jump */
.statement .blank:focus {
  outline: none;
  background: rgba(45, 90, 74, 0.12);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Filled: your words — distinct from static prose, still inline */
.statement .blank.has-text {
  background: transparent;
  padding: 0;
  margin: 0;
  font-style: italic;
  text-decoration: underline;
  text-decoration-color: rgba(45, 90, 74, 0.38);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.14em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.statement .blank.has-text:focus {
  text-decoration-color: rgba(45, 90, 74, 0.55);
}

.statement-card.view-original {
  cursor: default;
}

.statement.statement-readonly .placeholder-preview {
  font-style: italic;
  color: #b5aea4;
  background: rgba(45, 90, 74, 0.06);
  border-radius: 2px;
  padding: 0.05em 0.1em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

#btn-toggle-prompt[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.example-strip {
  width: 100%;
  margin-top: 1rem;
}

.example-strip-inner {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.example-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  line-height: 1.7;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.example-text {
  font-family: var(--font);
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text);
  margin: 0;
  flex: 1;
  min-width: 0;
}

.example-text .ex-segment {
  transition: background 0.15s ease;
  border-radius: 2px;
  padding: 0.05em 0;
}

.example-text .ex-segment.is-active {
  background: rgba(45, 90, 74, 0.14);
}

.example-rotate {
  flex-shrink: 0;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  width: 1.6rem;
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--muted);
  line-height: 1;
}

.example-rotate:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.confidence-field {
  margin: 1.5rem 0 0;
  padding: 0;
  border: 0;
  width: 100%;
  text-align: center;
}

.confidence-field legend {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.confidence-options {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  -webkit-overflow-scrolling: touch;
}

.confidence-option {
  position: relative;
  flex: 0 0 auto;
}

.confidence-option input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.confidence-option span {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}

.confidence-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.confidence-option input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.confidence-field:disabled .confidence-option span,
.confidence-option input:disabled + span {
  opacity: 0.45;
  cursor: not-allowed;
}

.confidence-option input:disabled {
  cursor: not-allowed;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.5rem;
  justify-content: center;
}

.actions button {
  font-size: 0.9rem;
}

.toast {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-align: center;
  width: 100%;
}

.footer {
  flex-shrink: 0;
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.footer p {
  margin: 0;
}

@media (max-width: 800px) {
  .header {
    padding: 0.55rem 1rem;
  }

  .header-inner {
    flex-wrap: wrap;
    justify-content: center;
  }

  .brand {
    order: 1;
    flex: 1 1 100%;
    text-align: center;
  }

  .nav {
    order: 2;
  }

  .storage-controls {
    order: 3;
  }

  .main {
    padding: 1.5rem 1rem 2rem;
  }

  .statement-card {
    padding: 2rem 1.5rem;
  }
}
