/* 英文朗讀練習：共用樣式（手機優先，支援深色模式） */

:root {
  --bg: #fbf8f3;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #5f6b7a;
  --border: #e6dfd3;
  --accent: #2f7d6d;
  --accent-text: #ffffff;
  --accent-soft: #dcefe9;
  --highlight: #ffe9a8;
  --highlight-text: #1f2933;
  --shadow: 0 2px 10px rgba(31, 41, 51, 0.08);
  --bar-bg: rgba(255, 255, 255, 0.96);
  --cue-bg: #fff4d6;
  --cue-text: #6b4a00;
  --error: #c0392b;
  --gutter: 16px;
  --radius: 16px;
  --bar-height: 168px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --surface: #1d232a;
    --text: #e8ecf0;
    --muted: #a3adb8;
    --border: #2e3740;
    --accent: #5cc2a8;
    --accent-text: #0e1a17;
    --accent-soft: #1f3a33;
    --highlight: #5a4a14;
    --highlight-text: #fff6d8;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --bar-bg: rgba(29, 35, 42, 0.97);
    --cue-bg: #3d3214;
    --cue-text: #ffe39a;
    --error: #ff8a7a;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
    sans-serif;
  font-size: 18px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.status {
  color: var(--muted);
  text-align: center;
  padding: 32px 0;
}

.status.error {
  color: var(--error);
}

/* ---------- 首頁 ---------- */

.home-header {
  padding: 32px 0 8px;
}

.home-header h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.25;
}

.home-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.story-list {
  list-style: none;
  margin: 16px 0 40px;
  padding: 0;
  display: grid;
  gap: 16px;
}

.story-card {
  display: block;
  min-height: 96px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.1s ease;
}

.story-card:active {
  transform: scale(0.98);
}

.story-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.search-box {
  margin-top: 16px;
}

.search-box label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.search-box input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  /* 16px 以上才不會讓 iOS Safari 自動放大 */
  font: inherit;
  font-size: 18px;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.story-card .student-name {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.story-card-title {
  margin: 4px 0 10px;
  font-size: 17px;
  line-height: 1.35;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.story-list li[hidden] {
  display: none;
}

.story-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 16px;
}

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- 練習頁 ---------- */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0);
}

.top-bar .wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
}

.back-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  margin-left: -10px;
  border-radius: 12px;
  font-size: 17px;
  text-decoration: none;
}

.story-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.story-text {
  padding-top: 20px;
  /* 底部預留空間，避免被控制列擋住（實際高度由 player.js 量測後寫入 --bar-height） */
  padding-bottom: calc(var(--bar-height) + 48px);
}

.paragraph {
  margin: 0 0 28px;
  font-size: 22px;
  line-height: 1.75;
  overflow-wrap: break-word;
}

.sentence {
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 1px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color 0.15s ease;
}

.sentence:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.sentence.current {
  background: var(--highlight);
  color: var(--highlight-text);
}

@media (hover: hover) {
  .sentence:not(.current):hover {
    background: var(--accent-soft);
  }
}

/* ---------- 底部控制列 ---------- */

.control-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--bar-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
  padding-bottom: env(safe-area-inset-bottom, 0);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.control-bar .wrap {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  padding-bottom: 10px;
}

.cue {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--cue-bg);
  color: var(--cue-text);
  font-size: 20px;
  font-weight: 700;
}

.cue[hidden] {
  display: none;
}

.cue-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 17px;
}

.settings-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.segmented {
  flex: 1 1 auto;
  display: flex;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  border: 0;
  background: var(--surface);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
}

.segmented button + button {
  border-left: 1px solid var(--border);
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.toggle-btn {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 15px;
  line-height: 1.15;
  cursor: pointer;
  white-space: nowrap;
}

.toggle-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 700;
}

.transport-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.icon-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 52px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.1;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon-btn[hidden] {
  display: none;
}

.play-btn {
  min-width: 76px;
  min-height: 64px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}

.play-btn svg {
  width: 34px;
  height: 34px;
}

.load-state {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.load-state:empty {
  display: none;
}

.load-state.error {
  color: var(--error);
}

@media (min-width: 600px) {
  .paragraph {
    font-size: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-card,
  .sentence {
    transition: none;
  }
}
