/* web/src/styles.css */
:root {
  --bg: #fbf7ef;
  --card: #ffffff;
  --ink: #1e2430;
  --muted: #667085;
  --line: #e8e1d4;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e8efff;
  --accent: #f59e0b;
  --hl-sentence: #fff3c4;
  --hl-word: #ffd95a;
  --danger: #d92d20;
  --warn-bg: #fff6e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --font-ui:
    system-ui,
    -apple-system,
    "Segoe UI",
    "PingFang TC",
    "Microsoft JhengHei",
    "Noto Sans TC",
    sans-serif;
  --font-en:
    "Segoe UI",
    -apple-system,
    "Helvetica Neue",
    Roboto,
    Arial,
    "Noto Sans",
    sans-serif;
  --font-ipa:
    "Segoe UI",
    "Lucida Sans Unicode",
    "Arial Unicode MS",
    "Noto Sans",
    "DejaVu Sans",
    -apple-system,
    sans-serif;
  color-scheme: light;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: default;
  opacity: .45;
}
:focus-visible {
  outline: 3px solid #93b4ff;
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 14px;
}
.center {
  text-align: center;
}
.spacer {
  flex: 1;
}
.error-text {
  color: var(--danger);
}
.ico {
  width: 22px;
  height: 22px;
  flex: none;
  display: block;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: transparent;
  font-weight: 600;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn .ico {
  width: 20px;
  height: 20px;
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
}
.btn-primary:hover {
  background: #1d4fd8;
}
.btn-ghost {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}
.btn-ghost:hover {
  border-color: #cfc6b6;
}
.btn-ghost.on {
  background: var(--primary-soft);
  border-color: #b7cbff;
  color: #1840b0;
}
.btn-soft {
  background: var(--primary-soft);
  color: #1840b0;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-big {
  min-height: 54px;
  font-size: 18px;
  padding: 0 24px;
  width: 100%;
}
.btn.sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
  border-radius: 10px;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  flex: none;
}
.icon-btn:hover {
  background: rgba(0, 0, 0, .05);
}
.icon-btn.sm {
  width: 36px;
  height: 36px;
}
.icon-btn.danger {
  color: var(--danger);
}
.speak-btn {
  color: var(--primary);
}
.tr-glyph {
  font-weight: 800;
  font-size: 16px;
  line-height: 1;
}
.app {
  min-height: 100vh;
  min-height: 100dvh;
}
.screen {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 120px;
}
.screen-center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(251, 247, 239, .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
}
.logo,
.logo-sm {
  display: inline-grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-en);
  font-weight: 800;
  border-radius: 12px;
}
.logo {
  width: 64px;
  height: 64px;
  font-size: 30px;
  border-radius: 18px;
  margin: 0 auto 8px;
}
.logo-sm {
  width: 32px;
  height: 32px;
  font-size: 15px;
  border-radius: 9px;
}
.app-title {
  text-align: center;
  margin: 4px 0;
  font-size: 24px;
}
.login-card {
  width: min(420px, 100%);
  text-align: center;
}
.login-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  text-align: left;
}
.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input-big {
  font-size: 20px;
  text-align: center;
  letter-spacing: .05em;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 15px;
}
.check input {
  width: 20px;
  height: 20px;
}
.form-msg {
  min-height: 1.5em;
  margin: 0;
  color: var(--danger);
  text-align: center;
}
.home-title {
  font-size: 26px;
  margin: 12px 4px 16px;
}
.choose {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.big-choice {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 26px 12px;
  text-align: center;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.big-choice:hover {
  border-color: #b7cbff;
}
.big-choice:first-child {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.big-choice:first-child .big-sub {
  color: #dce6ff;
}
.big-ico .ico {
  width: 44px;
  height: 44px;
}
.big-label {
  font-size: 20px;
  font-weight: 800;
}
.big-sub {
  font-size: 14px;
  color: var(--muted);
}
.section-title {
  font-size: 18px;
  margin: 0 0 4px;
}
.photo-panel,
.paste-panel {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}
.photo-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.thumb {
  position: relative;
  margin: 0;
  width: 128px;
}
.thumb img {
  width: 128px;
  height: 168px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  background: #f1efe9;
}
.thumb figcaption {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
}
.thumb-tools {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.paste-area {
  min-height: 220px;
  resize: vertical;
  font-family: var(--font-en);
  font-size: 17px;
  line-height: 1.6;
}
.reader-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(251, 247, 239, .95);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 980px;
  margin: 0 auto;
  flex-wrap: wrap;
}
.bar-tools {
  margin-top: 8px;
}
.brand-sm {
  font-size: 16px;
  margin-right: auto;
}
.rate-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  white-space: nowrap;
  min-height: 44px;
  border-radius: 12px;
  background: var(--card);
  border: 1.5px solid var(--line);
}
.rate {
  width: 120px;
  accent-color: var(--primary);
}
.rate-out {
  min-width: 3.2em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.reading {
  padding-top: 12px;
}
.article {
  font-family: var(--font-en);
}
.article.fs-s {
  font-size: 18px;
}
.article.fs-m {
  font-size: 22px;
}
.article.fs-l {
  font-size: 26px;
}
.art-title {
  font-size: 1.25em;
  margin: 4px 8px 12px;
}
.para {
  margin-bottom: 18px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}
.para:last-child {
  border-bottom: 0;
}
.sent {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 6px;
  padding: 6px 6px 6px 10px;
  border-radius: 12px;
  transition: background-color .2s;
}
.sent.reading {
  background: var(--hl-sentence);
  box-shadow: inset 4px 0 0 var(--accent);
}
.sent-text {
  margin: 0;
  line-height: 1.8;
  overflow-wrap: anywhere;
}
.w {
  cursor: pointer;
  border-radius: 6px;
  padding: 1px 1px;
}
.w:hover {
  background: #e9efff;
}
.w.sel {
  background: var(--hl-word);
}
.sent-tools {
  display: flex;
  gap: 2px;
  align-items: flex-start;
  padding-top: .2em;
  font-family: var(--font-ui);
}
.sent-tools .icon-btn {
  width: 40px;
  height: 40px;
}
.tr-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-weight: 800;
  font-size: 16px;
  color: var(--muted);
  font-family: var(--font-ui);
}
.tr-btn.on {
  background: var(--primary-soft);
  border-color: #b7cbff;
  color: #1840b0;
}
.tr {
  grid-column: 1 / -1;
  margin: 4px 0 4px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #f3f6ff;
  border-left: 4px solid #9db8ff;
  color: #344054;
  font-family: var(--font-ui);
  font-size: .78em;
  line-height: 1.7;
}
.wordcard {
  position: absolute;
  z-index: 60;
  width: min(360px, calc(100vw - 24px));
  max-height: 70vh;
  overflow: auto;
  background: var(--card);
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(16, 24, 40, .22);
  padding: 14px 16px 16px;
}
.wordcard.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  width: auto;
  max-height: 62vh;
  border-radius: 20px 20px 0 0;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  animation: sheet-in .18s ease-out;
}
@keyframes sheet-in {
  from {
    transform: translateY(30px);
    opacity: .4;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.wc-handle {
  display: none;
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: #d6d0c4;
  margin: -4px auto 8px;
}
.wordcard.sheet .wc-handle {
  display: block;
}
.wc-close {
  position: absolute;
  top: 6px;
  right: 6px;
}
.wc-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 40px;
}
.wc-word {
  font-family: var(--font-en);
  font-size: 28px;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.wc-kk {
  font-family: var(--font-ipa);
  font-size: 21px;
  color: #1840b0;
  margin: 2px 0 6px;
}
.wc-kk.sm {
  font-size: 17px;
  margin: 0;
}
.wc-gloss {
  margin: 4px 0 8px;
  padding-left: 1.2em;
  line-height: 1.6;
}
.wc-gloss.sm {
  font-size: 15px;
}
.wc-gloss li {
  margin: 2px 0;
}
.wc-part {
  font-family: var(--font-en);
  font-weight: 700;
  margin-top: 8px;
}
.wc-missing {
  background: var(--warn-bg);
  padding: 8px 10px;
  border-radius: 10px;
  margin: 6px 0;
}
.wc-link {
  background: #f6f4ef;
  border-radius: 12px;
  padding: 8px 12px;
  margin: 6px 0 8px;
}
.wc-link p {
  margin: 0 0 4px;
}
.wc-lemma {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.wc-lemma-word {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 19px;
}
.wc-ai {
  margin: 6px 0;
}
.ai-btn {
  width: 100%;
}
.ai-result {
  background: #f4f0ff;
  border-radius: 12px;
  padding: 8px 12px;
}
.ai-result p {
  margin: 4px 0;
}
.ai-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #5b3fd1;
  font-weight: 700;
  font-size: 14px;
}
.ai-tag .ico {
  width: 18px;
  height: 18px;
}
.pos {
  display: inline-block;
  background: #e6defd;
  color: #4a2fbf;
  border-radius: 6px;
  padding: 0 6px;
  margin-right: 6px;
  font-size: 14px;
  font-weight: 700;
}
.ai-note {
  font-size: 12px;
  color: #7a6aa8;
}
.wc-sentence {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, .45);
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}
.dialog {
  width: min(480px, 100%);
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
  padding: 16px 18px 18px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.dialog-small {
  width: min(400px, 100%);
}
.dialog-wide {
  width: min(760px, 100%);
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}
.dialog-msg {
  margin: 4px 0 16px;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}
.editor {
  display: grid;
  gap: 10px;
}
.editor-area {
  min-height: 50vh;
  resize: vertical;
  font-family: var(--font-en);
  font-size: 17px;
  line-height: 1.6;
}
.settings {
  display: grid;
  gap: 16px;
}
.field {
  display: grid;
  gap: 6px;
}
.field-label {
  font-weight: 700;
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row .input {
  flex: 1;
  min-width: 0;
}
.seg {
  display: inline-flex;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  width: max-content;
}
.seg-btn {
  min-width: 64px;
  min-height: 44px;
  border: 0;
  background: var(--card);
  font-weight: 700;
}
.seg-btn + .seg-btn {
  border-left: 1.5px solid var(--line);
}
.seg-btn.on {
  background: var(--primary);
  color: #fff;
}
.warn-box {
  background: var(--warn-bg);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0;
}
.about summary {
  cursor: pointer;
  color: var(--muted);
}
.about p {
  font-size: 13px;
  color: var(--muted);
}
.progress {
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 6px;
}
.progress-title {
  font-size: 20px;
  font-weight: 800;
  margin: 8px 0 0;
}
.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid var(--primary-soft);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
.spinner.sm {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-width: 3px;
  vertical-align: -3px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(520px, calc(100vw - 24px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 10px 14px;
  border-radius: 14px;
  background: #1f2937;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .18s ease-out;
}
.toast-error {
  background: #b42318;
}
.toast-warn {
  background: #b54708;
}
.toast-msg {
  flex: 1;
}
.toast-action {
  background: rgba(255, 255, 255, .18);
  border: 0;
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
}
.toast-close {
  background: transparent;
  border: 0;
  color: #fff;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
}
.toast-close .ico {
  width: 18px;
  height: 18px;
}
.toast.leaving {
  opacity: 0;
  transition: opacity .2s;
}
@keyframes toast-in {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
@media (max-width: 699px) {
  .screen {
    padding: 12px 12px 120px;
  }
  .brand-sm {
    display: none;
  }
  .bar-main {
    flex-wrap: nowrap;
  }
  .rate-box {
    flex: 1;
    min-width: 0;
    padding: 0 8px;
  }
  .rate {
    width: auto;
    flex: 1;
    min-width: 60px;
  }
  .tb-stop .tb-label {
    display: none;
  }
  .tb-stop {
    padding: 0 12px;
  }
  .bar-tools {
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 4px;
  }
  .bar-tools .btn {
    padding: 0 8px;
    font-size: 14px;
    flex: 1;
    min-width: 0;
    gap: 3px;
  }
  .bar-tools .btn .ico {
    width: 18px;
    height: 18px;
  }
  .sent {
    padding-left: 6px;
  }
  .choose {
    grid-template-columns: 1fr;
  }
  .big-choice {
    grid-template-columns: auto 1fr;
    justify-items: start;
    text-align: left;
    padding: 18px;
    column-gap: 14px;
  }
  .big-choice .big-ico {
    grid-row: span 2;
  }
  .home-title {
    font-size: 22px;
  }
}
@media (min-width: 700px) {
  .bar-row {
    flex-wrap: nowrap;
  }
  .reader-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .bar-tools {
    margin-top: 0;
  }
  .bar-main,
  .bar-tools {
    margin: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
