:root {
  --bg: #faf6ef;
  --card: #ffffff;
  --ink: #1f1b16;
  --muted: #5a5248;
  --line: #d9cfc0;
  --mic: #c62828;
  --mic-on: #8e0000;
  --listen: #1565c0;
  --clear: #6d4c41;
  --save: #2e7d32;
  --focus: #ff9800;
  --story: #6a1b9a;
  --story-soft: #f3e5f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --card: #26231f;
    --ink: #f5efe6;
    --muted: #c9bfb1;
    --line: #4a443c;
    --story-soft: #3a2a40;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
textarea, button { font-family: inherit; }
html { font-size: 20px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
header { text-align: center; margin-bottom: 12px; }
h1 { font-size: 2rem; margin: 8px 0 0; }
h2 { font-size: 1.4rem; margin: 32px 0 12px; }
.today { font-size: 1.1rem; color: var(--muted); margin: 4px 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

textarea {
  width: 100%;
  min-height: 220px;
  font-size: 1.35rem;
  line-height: 1.6;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
}
textarea:focus, button:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }

.status { font-size: 1.15rem; text-align: center; min-height: 1.6em; margin: 12px 0; color: var(--muted); }
.status.live { color: var(--mic); font-weight: 600; }
.status.error { color: var(--mic); }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 8px; }
.btn {
  min-height: 92px;
  padding: 6px 4px;
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer;
}
.btn svg { width: 38px; height: 38px; fill: currentColor; }
.btn-mic { background: var(--mic); }
.btn-mic[aria-pressed="true"] { background: var(--mic-on); animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(198,40,40,.6); }
  70% { box-shadow: 0 0 0 18px rgba(198,40,40,0); }
  100% { box-shadow: 0 0 0 0 rgba(198,40,40,0); }
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-listen { background: var(--listen); }
.btn-clear { background: var(--clear); }
.btn-save { background: var(--save); }

.undo {
  margin-top: 12px; padding: 12px 16px;
  border-radius: 12px; background: var(--card); border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 1.1rem;
}
.undo button {
  font-size: 1.1rem; font-weight: 600; padding: 10px 18px; border-radius: 10px;
  border: 2px solid var(--listen); background: transparent; color: var(--listen); cursor: pointer;
}

.entries { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.entry { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.entry time { display: block; color: var(--muted); font-size: .95rem; margin-bottom: 6px; }
.entry p { margin: 0 0 12px; font-size: 1.2rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry-actions { display: flex; gap: 10px; }
.entry-actions button {
  flex: 1; min-height: 56px; font-size: 1.05rem; font-weight: 600;
  border-radius: 10px; border: none; color: #fff; cursor: pointer;
}
.entry-actions .e-listen { background: var(--listen); }
.entry-actions .e-delete { background: var(--clear); }
.empty { color: var(--muted); font-size: 1.1rem; }

.count { color: var(--muted); font-weight: 400; font-size: 1.1rem; }
.more, .install {
  display: block; width: 100%; margin-top: 12px; min-height: 56px; font-size: 1.1rem; font-weight: 600;
  border-radius: 12px; border: 2px solid var(--listen); background: transparent; color: var(--listen); cursor: pointer;
}
.install { margin: 12px auto 0; max-width: 420px; background: var(--listen); color: #fff; }

.story { margin-top: 8px; padding-top: 4px; border-top: 3px dashed var(--line); }
.hint { color: var(--muted); font-size: 1.05rem; margin: 0 0 12px; }
.styles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.style-opt { position: relative; }
.style-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.style-opt span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 64px; padding: 6px;
  border: 3px solid var(--line); border-radius: 14px; background: var(--card); font-size: 1.05rem; font-weight: 600;
}
.style-opt input:checked + span { border-color: var(--story); background: var(--story-soft); color: var(--ink); }
.style-opt input:focus-visible + span { outline: 4px solid var(--focus); outline-offset: 2px; }
.story-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.story-actions .btn span:first-child { font-size: 1.7rem; line-height: 1; }
.btn-story { background: var(--story); }
.btn-pdf { background: var(--listen); }
.btn-mp3 { background: var(--save); }
.story-box { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 16px; margin-top: 8px; }
.story-box h3 { font-size: 1.5rem; margin: 0 0 4px; text-align: center; }
.story-meta { color: var(--muted); font-size: .95rem; text-align: center; margin: 0 0 12px; }
.story-box audio { width: 100%; margin-bottom: 8px; }
.dl-link { display: block; text-align: center; font-size: 1.1rem; font-weight: 600; color: var(--listen); margin-bottom: 12px; }
.reset {
  display: block; width: 100%; margin-top: 28px; min-height: 60px; font-size: 1.1rem; font-weight: 600;
  border-radius: 12px; border: 2px solid var(--mic); background: transparent; color: var(--mic); cursor: pointer;
}
.reset:disabled { opacity: .5; }
.story-body p { font-size: 1.2rem; line-height: 1.7; margin: 0 0 14px; text-align: justify; }

@media (max-width: 420px) {
  html { font-size: 17px; }
  .wrap { padding-left: 12px; padding-right: 12px; }
  .actions, .story-actions, .styles { gap: 8px; }
  .btn { min-height: 84px; font-size: 1rem; }
  .btn svg { width: 32px; height: 32px; }
  .style-opt span { font-size: .95rem; }
}
