:root {
  --bg: #0f1115;
  --bg-elev: #181b22;
  --bg-card: #1e222c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f1ea;
  --muted: #9a978f;
  --accent: #e8c07a;
  --accent-dim: rgba(232, 192, 122, 0.16);
  --danger: #e08b7a;
  --ok: #8fbf9f;
  --radius: 16px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 100dvh;
}

.view.active {
  display: flex;
}

/* author CSS の display が [hidden] を上書きしないようにする */
[hidden] {
  display: none !important;
}

/* モード切替はクラスでも強制（キャッシュ差異にも強くする） */
#view-reader.mode-rsvp #text-stage,
#view-reader.mode-rsvp #text-controls,
#view-reader.mode-rsvp #text-pane {
  display: none !important;
}

#view-reader.mode-text #rsvp-stage,
#view-reader.mode-text #rsvp-controls {
  display: none !important;
}

#view-reader.mode-rsvp-text #text-stage {
  display: flex !important;
}

#view-reader.mode-rsvp-text #text-pane {
  display: block !important;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 1.15rem;
  font-weight: 650;
  margin: 0;
  letter-spacing: 0.02em;
}

.topbar .spacer {
  flex: 1;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text);
}

.icon-btn:active {
  background: var(--bg-elev);
}

.primary-btn,
.ghost-btn,
.danger-btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 600;
}

.primary-btn {
  background: var(--accent);
  color: #1a1408;
}

.ghost-btn {
  background: var(--bg-card);
  border: 1px solid var(--line);
}

.danger-btn {
  background: rgba(224, 139, 122, 0.14);
  color: var(--danger);
}

.library-body {
  padding: 16px 16px calc(28px + var(--safe-bottom));
}

.hint {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
  margin: 0 0 16px;
}

.book-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.book-card-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  align-items: stretch;
}

.book-card-wrap .delete-btn {
  align-self: center;
  color: var(--muted);
}

.book-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  text-align: left;
  width: 100%;
}

.book-card .title {
  font-weight: 650;
  font-size: 1.02rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card .meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.82rem;
}

.progress-track {
  grid-column: 1 / -1;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0;
}

.empty {
  text-align: center;
  padding: 48px 12px;
  color: var(--muted);
}

.empty strong {
  display: block;
  color: var(--text);
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.add-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(16px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.add-bar .primary-btn {
  width: 100%;
}

.import-body {
  padding: 24px 16px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drop {
  border: 1.5px dashed rgba(232, 192, 122, 0.35);
  background: var(--accent-dim);
  border-radius: 20px;
  padding: 40px 16px;
  text-align: center;
}

.drop p {
  margin: 8px 0 0;
  color: var(--muted);
}

.status-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  display: none;
}

.status-box.visible {
  display: block;
}

.status-box .label {
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 99px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s ease;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

.reader {
  background: radial-gradient(1200px 500px at 50% 20%, #1a1d26 0%, var(--bg) 60%);
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.reader-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 20px 8px;
  min-height: 0;
  overflow: hidden;
}

.rsvp-word {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 8vw, 3.2rem);
  line-height: 1.35;
  letter-spacing: 0.04em;
  text-align: center;
  min-height: 1.4em;
  max-width: 100%;
  word-break: break-word;
}

.rsvp-word.is-punct {
  color: var(--muted);
}

.reader-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 28px;
  text-align: center;
}

.reader-controls {
  flex-shrink: 0;
  padding: 8px 16px calc(18px + var(--safe-bottom));
}

.control-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.ctl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}

.ctl.play {
  width: 64px;
  height: 64px;
  background: var(--accent);
  color: #1a1408;
  border: 0;
  font-size: 1.4rem;
}

.speed {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 12px 14px 14px;
}

.speed header {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.speed header strong {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.speed-ends {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.modal.open {
  display: flex;
}

.sheet {
  width: min(560px, 100%);
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(20px + var(--safe-bottom));
}

.sheet h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.sheet p {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 0.92rem;
}

.sheet-actions {
  display: flex;
  gap: 8px;
}

.sheet-actions button {
  flex: 1;
}

.mode-toggle {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.85rem;
  border-radius: 12px;
}

.text-stage {
  flex: 1;
  min-height: 0;
  height: auto;
  align-items: stretch;
  justify-content: flex-start;
  padding: 8px 16px 12px;
  overflow: hidden;
}

.text-pane {
  width: min(640px, 100%);
  margin-inline: auto;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.95;
  letter-spacing: 0.03em;
  padding: 12px 4px 24px;
  -webkit-overflow-scrolling: touch;
}

.text-unit {
  display: inline;
  margin: 0;
  padding: 0 1px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  vertical-align: baseline;
}

.text-unit.current {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.text-ellipsis {
  color: var(--muted);
}

.text-hint {
  text-align: center;
  margin: 0;
}

#view-reader.mode-rsvp-text #rsvp-stage {
  flex: 0 0 27%;
  padding-block: 4px;
}

#view-reader.mode-rsvp-text #rsvp-stage .rsvp-word {
  font-size: clamp(1.5rem, 6vw, 2.5rem);
}

#view-reader.mode-rsvp-text .text-stage {
  flex: 1 1 0;
  min-height: 0;
  padding-top: 0;
}

#view-reader.mode-rsvp-text .text-pane {
  width: min(640px, 100%);
  border-top: 1px solid var(--line);
}

.jump-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

.jump-field input {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  padding: 0 14px;
  color: var(--text);
}

@media (min-width: 720px) {
  .library-body,
  .import-body,
  .reader-controls,
  .text-stage {
    width: min(640px, 100%);
    margin-inline: auto;
  }

  .modal {
    align-items: center;
  }

  .sheet {
    border-radius: 20px;
  }
}
