/* 英文小幫手：大字、高對比、按鈕夠大，方便長輩用手指點 */
:root {
  --read: 26px;            /* 文章的字體大小，按「字大一點／字小一點」會改這個值 */
  --bg: #F6F1E7;
  --card: #FFFFFF;
  --ink: #1B1F24;
  --muted: #4A5361;
  --line: #DDD3C1;
  --primary: #1F5FA8;
  --primary-dark: #174A84;
  --primary-soft: #E2ECF8;
  --zh-ink: #4E3B26;
  --zh-bg: #FBF5E9;
  --zh-line: #E2C58D;
  --reading: #FFF0A8;      /* 正在念的句子 */
  --speaking: #FFCF3F;     /* 正在念的單字 */
  --active: #CFE0F7;       /* 剛剛點的單字 */
  --danger: #B42318;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(40, 30, 10, 0.08);
  --font-en: "Atkinson Hyperlegible", "Segoe UI", Arial, sans-serif;
  --font-ui: "Atkinson Hyperlegible", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Heiti TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.6;
  touch-action: manipulation; /* 連點兩下不會把畫面放大 */
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
#translateBtn:disabled { opacity: 0.6; cursor: wait; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #E8A33D; outline-offset: 2px; }

/* ---------- 頂端列 ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--card);
  border-bottom: 2px solid var(--line);
}
.title { margin: 0; font-size: 1.35rem; }
.tools { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ---------- 版面 ---------- */
.page { max-width: 880px; margin: 0 auto; padding: 1rem 1rem 9rem; }
body.card-open .page { padding-bottom: 75vh; } /* 單字卡打開時，讓最後幾行也能捲到卡片上方 */

.card {
  padding: 1rem;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.step { display: block; margin-bottom: 0.5rem; font-weight: 700; }
.num {
  display: inline-grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  margin-right: 0.35em;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.85em;
}
.num.light { background: #fff; color: var(--primary); }

textarea {
  display: block;
  width: 100%;
  min-height: 8em;
  padding: 0.7rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #FFFDF8;
  line-height: 1.6;
  resize: vertical;
}
textarea:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }

/* ---------- 按鈕 ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.8rem; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  min-height: 2.8rem;
  padding: 0.35rem 1.1rem;
  border: 2px solid var(--primary);
  border-radius: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: var(--card); color: var(--primary); }
@media (hover: hover) {
  .btn.primary:hover { background: var(--primary-dark); }
  .btn.ghost:hover { background: var(--primary-soft); }
  .chip:hover { border-color: var(--primary); }
}
.btn:active { transform: translateY(1px); }
.btn.wide { width: 100%; }
#translateBtn { flex: 1 1 10rem; font-size: 1.1rem; }

.chip {
  min-height: 2.3rem;
  padding: 0.2rem 0.85rem;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.85rem;
  font-weight: 700;
}

/* ---------- 翻譯結果 ---------- */
.result { margin-top: 1.3rem; }
.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.tip { margin: 0; color: var(--muted); font-weight: 700; }
.tip.notice {
  margin-bottom: 0.8rem;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  background: #FFF4D6;
  color: #6B4E00;
}

.pairs { font-size: var(--read); }
.pair {
  margin-bottom: 0.8em;
  padding: 0.6em 0.9em 0.8em;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.para-play { display: block; margin: 0 0 0.4rem auto; }
.en { margin: 0; font-family: var(--font-en); line-height: 1.85; overflow-wrap: break-word; }
.zh {
  margin: 0.6em 0 0;
  padding: 0.45em 0.75em;
  border-left: 5px solid var(--zh-line);
  border-radius: 8px;
  background: var(--zh-bg);
  color: var(--zh-ink);
  font-size: 0.88em;
  line-height: 1.75;
}
.pairs.hide-zh .zh { display: none; }
.pending { color: var(--muted); font-style: italic; }
.failed { color: var(--danger); font-weight: 700; }

.w { border-radius: 0.2em; cursor: pointer; transition: background-color 0.15s; }
@media (hover: hover) { .w:hover { background: var(--primary-soft); } }
.sent.reading {
  background: var(--reading);
  border-radius: 0.2em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.w.speaking { background: var(--speaking); }
.w.active { background: var(--active); box-shadow: 0 0 0 2px var(--primary); }
@media (pointer: coarse) {
  /* 手機、平板上長按不會跳出「選取文字」的選單，避免長輩誤觸 */
  .en { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  /* iPhone 的 Safari 要有 cursor: pointer，點空白處才會觸發「收起單字卡」 */
  main { cursor: pointer; -webkit-tap-highlight-color: transparent; }
}

/* ---------- 底部朗讀列 ---------- */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.97);
  border-top: 2px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}
.player .play { flex: 1 1 auto; max-width: 15rem; font-size: 1.1rem; }

/* ---------- 單字卡 ---------- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-height: 62vh;
  overflow-y: auto;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 2px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
}
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: 1.2rem;
    width: 640px;
    border: 2px solid var(--line);
    border-radius: 22px;
    transform: translateX(-50%);
  }
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.wc-word {
  font-family: var(--font-en);
  font-size: 2.3rem;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.wc-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.5rem;
  margin: 0.9rem 0;
}
.wc-label { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.wc-main { margin: 0.1rem 0 0.8rem; font-size: 1.5rem; font-weight: 700; }
.wc-sentence {
  margin: 0.2rem 0 0;
  padding: 0.5rem 0.75rem;
  border-left: 5px solid var(--zh-line);
  border-radius: 8px;
  background: var(--zh-bg);
  color: var(--zh-ink);
}

/* ---------- 設定、讀過的文章、查過的單字（彈出視窗） ---------- */
.panel {
  width: min(640px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.2rem 1.3rem;
  border: none;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  color: var(--ink);
}
.panel::backdrop { background: rgba(0, 0, 0, 0.4); }
.panel h2 { margin: 0 0 0.6rem; font-size: 1.3rem; }
.panel > .tip { margin-bottom: 0.8rem; }
.setting-block { margin-bottom: 1.2rem; padding-bottom: 1rem; border-bottom: 2px solid var(--line); }
.font-sample { margin: 0.6rem 0 0; font-size: var(--read); font-weight: 700; }
.account { margin: 0 0 0.6rem; }

.list { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #FFFDF8;
}
.item-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.15rem;
  padding: 0;
  border: none;
  background: none;
  text-align: left;
}
.item-title { font-family: var(--font-en); font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.item-sub { color: var(--zh-ink); }
.item-note { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.item-delete { flex: none; }

/* ---------- 登入頁 ---------- */
.login-card { max-width: 460px; margin: 10vh auto 0; }
.login-card .title { margin-bottom: 0.3rem; }
.login-card .tip { margin-bottom: 1rem; }
.login-error { margin: 0 0 0.8rem; }
input[type="text"],
input[type="password"] {
  display: block;
  width: 100%;
  min-height: 2.8rem;
  margin-bottom: 0.9rem;
  padding: 0.4rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #FFFDF8;
}
input[type="text"]:focus,
input[type="password"]:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.show-password { display: flex; align-items: center; gap: 0.5rem; margin: -0.2rem 0 1.1rem; font-weight: 700; }
.show-password input { width: 1.3rem; height: 1.3rem; }
select {
  width: 100%;
  min-height: 2.8rem;
  margin-bottom: 0.6rem;
  padding: 0.3rem 0.6rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.voice-help {
  margin: 1rem 0;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--zh-bg);
  font-size: 0.92rem;
}
.voice-help p { margin: 0.3rem 0; }
.voice-help ol { margin: 0.3rem 0; padding-left: 1.3em; }

/* ---------- 提示訊息（放在最上面，不會擋到下面的單字卡和朗讀列） ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(0.8rem + env(safe-area-inset-top));
  z-index: 30;
  width: max-content; /* 不然 left: 50% 會讓長訊息只用到半個螢幕寬，擠成細長一條 */
  max-width: 90vw;
  padding: 0.7rem 1.1rem;
  border-radius: 14px;
  background: #222;
  color: #fff;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  html { font-size: 18px; }
  .page { padding: 0.75rem 0.75rem 9rem; }
  .wc-buttons > :last-child { grid-column: 1 / -1; } /* 手機上一行放兩顆，第三顆「念這一句」自己一整行 */
}
