:root {
  --page-bg: #E4E4E9;

  --ios-bg: #F2F2F7;
  --ios-bg-elevated: #FFFFFF;
  --ios-label: #1C1C1E;
  --ios-secondary: #6E6E73;
  --ios-tertiary: #AEAEB2;
  --ios-separator: #DCDCE1;
  --ios-blue: #007AFF;
  --ios-red: #FF3B30;
  --ios-green: #248A3D;
  --ios-fill: #E9E9EE;
  --ios-navbar-bg: rgba(249, 249, 251, 0.82);
  --ios-backdrop: rgba(0, 0, 0, 0.32);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Helvetica Neue", Arial, sans-serif;
  --serif: "New York", ui-serif, Georgia, "Songti TC", "PMingLiU", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page-bg: #0B0B0D;
    --ios-bg: #000000;
    --ios-bg-elevated: #1C1C1E;
    --ios-label: #F2F2F2;
    --ios-secondary: #98989D;
    --ios-tertiary: #6E6E73;
    --ios-separator: #38383A;
    --ios-blue: #0A84FF;
    --ios-red: #FF453A;
    --ios-green: #32D74B;
    --ios-fill: #2C2C2E;
    --ios-navbar-bg: rgba(20, 20, 22, 0.78);
    --ios-backdrop: rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --page-bg: #0B0B0D;
  --ios-bg: #000000;
  --ios-bg-elevated: #1C1C1E;
  --ios-label: #F2F2F2;
  --ios-secondary: #98989D;
  --ios-tertiary: #6E6E73;
  --ios-separator: #38383A;
  --ios-blue: #0A84FF;
  --ios-red: #FF453A;
  --ios-green: #32D74B;
  --ios-fill: #2C2C2E;
  --ios-navbar-bg: rgba(20, 20, 22, 0.78);
  --ios-backdrop: rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: var(--ios-label);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
button, input { font-family: inherit; }
a { color: inherit; }
svg { display: block; }

/* ---------------- app shell ---------------- */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--ios-bg);
  display: flex;
  flex-direction: column;
  position: relative;
}
@media (min-width: 640px) {
  .app-shell {
    box-shadow: 0 0 0 1px var(--ios-separator), 0 20px 50px -20px rgba(0, 0, 0, 0.35);
  }
}

/* ---------------- nav bar ---------------- */
.navbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ios-navbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--ios-separator);
  padding: calc(env(safe-area-inset-top, 0px) + 0.7rem) 0.9rem 0.6rem;
}
.nav-row { display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
.nav-back {
  display: flex; align-items: center; gap: 0.1rem; text-decoration: none;
  background: none; border: none; color: var(--ios-blue);
  font-size: 0.95rem; font-weight: 500; cursor: pointer; padding: 0.1rem 0.1rem 0.1rem 0;
}
.nav-inline-title { font-size: 1.02rem; font-weight: 600; color: var(--ios-label); }
.nav-action {
  background: var(--ios-fill); border: none; color: var(--ios-blue);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
}
.large-title {
  font-size: 2rem; font-weight: 700; color: var(--ios-label);
  margin-top: 0.5rem; letter-spacing: -0.02em; text-wrap: balance;
}

/* ---------------- content / lists ---------------- */
.content { padding-bottom: 6rem; }
.section-label {
  font-size: 0.78rem; font-weight: 600; color: var(--ios-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 1.1rem 1.1rem 0.4rem;
}

.ios-list {
  margin: 0 0.9rem;
  background: var(--ios-bg-elevated);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 1px rgba(0,0,0,0.03);
}
.ios-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-bottom: 0.5px solid var(--ios-separator);
  width: 100%; text-align: left; color: inherit;
}
.ios-row:last-child { border-bottom: none; }
a.ios-row { cursor: pointer; text-decoration: none; }
.row-link {
  display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0;
  text-decoration: none; color: inherit; cursor: pointer;
}
.row-icon {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
  font-family: var(--serif); font-size: 1rem;
}
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-size: 0.98rem; font-weight: 500; color: var(--ios-label); }
.row-sub { display: block; font-size: 0.8rem; color: var(--ios-secondary); margin-top: 0.1rem; }
.row-chevron { color: var(--ios-tertiary); flex-shrink: 0; }
.row-num { font-family: var(--serif); font-size: 0.85rem; color: var(--ios-tertiary); width: 1.6em; flex-shrink: 0; }

/* ---------------- book header (toc) ---------------- */
.book-header { padding: 0.4rem 1.1rem 1.2rem; }
.book-cover {
  width: 88px; height: 122px; border-radius: 8px; margin-bottom: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px -8px rgba(0,0,0,0.35);
}
.book-cover span { font-family: var(--serif); color: rgba(255,255,255,0.94); font-size: 2rem; }
.book-header h1 { font-family: var(--serif); font-size: 1.5rem; margin: 0 0 0.15rem; color: var(--ios-label); text-wrap: balance; }
.book-header .meta { font-size: 0.85rem; color: var(--ios-secondary); }

/* ---------------- reader ---------------- */
.reader-content { padding: 0.9rem 1.2rem 3rem; }
.chapter-title { font-family: var(--serif); font-size: 1.4rem; margin: 0 0 1.2rem; color: var(--ios-label); }
.prose { font-family: var(--serif); font-size: 1.08rem; line-height: 1.8; color: var(--ios-label); max-width: 46ch; }
.prose p { margin: 0 0 1.1rem; }
.hint-chip {
  display: flex; gap: 0.5rem; align-items: flex-start;
  font-size: 0.78rem; color: var(--ios-secondary);
  background: var(--ios-fill); border-radius: 10px; padding: 0.55rem 0.7rem;
  margin-bottom: 1.3rem;
}
.word { cursor: pointer; border-bottom: 1.5px dotted var(--ios-blue); }
.word:active, .word.active { background: var(--ios-fill); }
.word.saved { border-bottom-color: var(--ios-red); border-bottom-style: solid; }

.reader-footer-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1.5rem; padding-top: 1rem; border-top: 0.5px solid var(--ios-separator);
  font-size: 0.85rem;
}
.reader-footer-nav a { color: var(--ios-blue); font-weight: 500; text-decoration: none; }
.reader-footer-nav a:hover { text-decoration: underline; }

/* ---------------- segmented control ---------------- */
.segmented {
  display: flex; background: var(--ios-fill); border-radius: 9px; padding: 2px;
  margin: 0 1.1rem 1rem; gap: 2px; overflow-x: auto;
}
.segmented a {
  flex: 1; text-align: center; text-decoration: none; white-space: nowrap;
  padding: 0.4rem 0.6rem; font-size: 0.82rem; font-weight: 500; color: var(--ios-label); border-radius: 7px;
}
.segmented a[aria-current="true"] {
  background: var(--ios-bg-elevated); box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  font-weight: 600;
}

.fc-row { align-items: flex-start; }
.fc-main { flex: 1; min-width: 0; }
.fc-word-line { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; }
.fc-word { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; color: var(--ios-label); }
.fc-pos { font-size: 0.66rem; font-weight: 700; color: var(--ios-blue); background: rgba(0,122,255,0.12); border-radius: 4px; padding: 0.05rem 0.35rem; }
.fc-zh { font-family: var(--serif); font-size: 0.98rem; color: var(--ios-label); margin-top: 0.15rem; }
.fc-example { font-size: 0.78rem; color: var(--ios-secondary); margin-top: 0.3rem; font-style: italic; line-height: 1.4; }
.fc-source { font-size: 0.7rem; color: var(--ios-tertiary); margin-top: 0.35rem; }
.fc-delete { background: none; border: none; color: var(--ios-red); flex-shrink: 0; padding: 0.3rem; cursor: pointer; }

.empty-state { text-align: center; color: var(--ios-tertiary); font-size: 0.85rem; padding: 3.5rem 1.5rem; }

.upload-status { text-align: center; font-size: 0.82rem; color: var(--ios-secondary); min-height: 1.2em; margin: 0.3rem 0 0; }

/* ---------------- tab bar ---------------- */
.tabbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; border-top: 0.5px solid var(--ios-separator);
  background: var(--ios-navbar-bg);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  padding: 0.5rem 0 calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
  margin-top: auto;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  text-decoration: none; color: var(--ios-tertiary); cursor: pointer;
  font-size: 0.68rem; font-weight: 500;
}
.tabbar a[aria-current="true"] { color: var(--ios-blue); }

/* ---------------- login ---------------- */
.login-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; text-align: center; min-height: 100dvh; }
.login-mark {
  width: 64px; height: 64px; border-radius: 16px; background: var(--ios-blue);
  display: flex; align-items: center; justify-content: center; margin-bottom: 1.1rem;
  box-shadow: 0 8px 20px -6px rgba(0,122,255,0.55);
}
.login-screen h1 { font-size: 1.35rem; font-weight: 700; color: var(--ios-label); margin: 0 0 0.3rem; }
.login-screen p.sub { font-size: 0.85rem; color: var(--ios-secondary); margin: 0 0 1.6rem; }
.login-form { width: 100%; max-width: 280px; }
.login-form .error { color: var(--ios-red); font-size: 0.85rem; margin-bottom: 0.6rem; }
.ios-input {
  width: 100%; background: var(--ios-fill); border: none; border-radius: 11px;
  padding: 0.8rem 0.9rem; font-size: 0.98rem; color: var(--ios-label); margin-bottom: 0.9rem;
  text-align: center;
}
.ios-input:focus, .btn-block:focus-visible, .ios-row:focus-visible, .tabbar a:focus-visible, .word:focus-visible, .nav-action:focus-visible {
  outline: 2px solid var(--ios-blue); outline-offset: 2px;
}
.btn-block {
  width: 100%; border: none; border-radius: 11px; padding: 0.8rem;
  background: var(--ios-blue); color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-block:active { opacity: 0.85; }
.login-note { font-size: 0.72rem; color: var(--ios-tertiary); margin-top: 1.3rem; }

/* ---------------- bottom sheet ---------------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: var(--ios-backdrop);
  opacity: 0; pointer-events: none; transition: opacity 0.22s ease; z-index: 60;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 560px; margin: 0 auto;
  background: var(--ios-bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 0.55rem 1.2rem calc(env(safe-area-inset-bottom, 0px) + 1.2rem);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.18);
}
.sheet.open { transform: translateY(0); }
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--ios-tertiary); opacity: 0.6; margin: 0.2rem auto 0.9rem; }
.sheet-word-line { display: flex; align-items: baseline; gap: 0.5rem; }
.sheet-word { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; color: var(--ios-label); }
.sheet-phon { font-size: 0.85rem; color: var(--ios-tertiary); margin-top: 0.15rem; }
.sheet-zh { font-family: var(--serif); font-size: 1.2rem; color: var(--ios-label); margin-top: 0.7rem; }
.sheet-def { font-size: 0.86rem; color: var(--ios-secondary); margin-top: 0.35rem; line-height: 1.5; }
.sheet-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; }
.sheet-actions .btn-block { flex: 1; }
.btn-secondary {
  flex: 1; border: none; border-radius: 11px; padding: 0.8rem;
  background: var(--ios-fill); color: var(--ios-label); font-size: 1rem; font-weight: 600; cursor: pointer;
}
.sheet-status { font-size: 0.8rem; color: var(--ios-green); font-weight: 600; margin-top: 0.7rem; min-height: 1.1em; text-align: center; }
