:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #66707f;
  --primary: #1a5fb4;
  --primary-dark: #144a8f;
  --accent: #e8f0fb;
  --border: #dde3ec;
  --danger: #c0392b;
  --highlight: #fff3c4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --card: #1e242e;
    --text: #e8ecf2;
    --muted: #98a2b0;
    --primary: #4a8fe0;
    --primary-dark: #77aef0;
    --accent: #24303f;
    --border: #333c48;
    --danger: #e06555;
    --highlight: #4c4320;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.app-header { text-align: center; padding: 8px 0 16px; }
.app-header h1 { font-size: 1.25rem; margin: 0 0 4px; }
.subtitle { color: var(--muted); font-size: 0.85rem; margin: 0; }

.add-buttons { display: flex; gap: 10px; margin-bottom: 20px; }

.btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 14px 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--card); color: var(--primary); border: 2px solid var(--primary); }
.btn-note { display: block; font-size: 0.72rem; font-weight: 400; opacity: 0.85; margin-top: 2px; }

.btn-dict {
  width: 100%;
  border: 1px dashed var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 11px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 20px;
}
.btn-dict-note { color: var(--muted); font-weight: 400; font-size: 0.78rem; }

.dict-note {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.7;
  background: var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 16px;
}
.dict-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.dict-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
}
.dict-arrow { color: var(--muted); flex-shrink: 0; }
.dict-test, .dict-delete {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--accent);
  cursor: pointer;
  font-size: 0.95rem;
}
.dict-delete { color: var(--danger); background: transparent; }
.dict-add { margin: 6px 0 16px; }
#view-dict .btn { width: 100%; }

.script-list { display: flex; flex-direction: column; gap: 12px; }

.folder-header {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 4px 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.folder-toggle { color: var(--muted); font-size: 0.75rem; }
.folder-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  margin-left: auto;
}
.folder-body { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }

.script-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.script-card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.script-meta { color: var(--muted); font-size: 0.78rem; margin: 0 0 12px; }
.script-actions { display: flex; gap: 8px; }
.script-actions button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.act-play { background: var(--primary); color: #fff; flex: 1.6; }
.act-edit { background: var(--accent); color: var(--primary-dark); flex: 1; }
.act-delete { background: transparent; color: var(--danger); flex: 0.8; }

.empty-message { text-align: center; color: var(--muted); line-height: 1.9; margin-top: 48px; }

.sub-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 14px;
}
.sub-header h2 { font-size: 1.05rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-back {
  border: none;
  background: var(--accent);
  color: var(--primary-dark);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}

.edit-form { display: flex; flex-direction: column; gap: 8px; }
.edit-form label { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-top: 6px; }
.edit-form input, .edit-form textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
}
.edit-form textarea { min-height: 45vh; line-height: 1.8; resize: vertical; }
.edit-form .btn { margin-top: 12px; }

.player-text {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  line-height: 2;
  font-size: 1.02rem;
  margin-bottom: 190px;
}
.player-text .sentence {
  cursor: pointer;
  border-radius: 6px;
  padding: 1px 2px;
}
.player-text .sentence.active {
  background: var(--highlight);
  font-weight: 600;
}
.player-text .para-break { display: block; height: 0.9em; }

.player-controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
}
.player-controls .control-row {
  max-width: 608px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.control-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; white-space: nowrap; min-width: 72px; }
#speed-slider { flex: 1; accent-color: var(--primary); }
#voice-select {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.88rem;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.buttons-row { justify-content: center; gap: 18px; margin-bottom: 0 !important; }
.btn-round {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--text);
}
.btn-play {
  width: 64px; height: 64px;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1.5rem;
}
.btn-toggle.on { background: var(--primary); color: #fff; border-color: var(--primary); }

.voice-warning { color: var(--danger); font-size: 0.82rem; text-align: center; margin: 8px 0 0; }

.backup-box {
  margin-top: 36px;
  border-top: 1px dashed var(--border);
  padding-top: 18px;
}
.backup-note {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.8;
  background: var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
}
.backup-buttons { display: flex; gap: 10px; }
.backup-buttons .btn { font-size: 0.85rem; padding: 11px 6px; }
