:root {
  --bg: #f6f7f9; --card: #fff; --text: #1c1f24; --muted: #6b7280; --border: #e5e7eb; --accent: #2563eb; --chip: #eef2ff; --hl: #d97706;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --card: #1a1d23; --text: #e8eaed; --muted: #9aa0a9; --border: #2a2e36; --accent: #6b9bff; --chip: #232a3a; --hl: #f59e0b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.55 -apple-system, system-ui, sans-serif; }
.wrap { max-width: 640px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(55vh + 24px); }
#setup.wrap { padding-bottom: 32px; }
h1 { font-size: 1.5rem; margin: 8px 0; }
h2 { font-size: 1rem; margin: 28px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.err, .error { color: #dc2626; }
code { font-size: .9em; }
.row { display: flex; gap: 8px; margin-top: 8px; }
input, textarea { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
textarea { resize: vertical; }
.btn { font: inherit; font-size: 16px; font-weight: 600; padding: 9px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#setup .btn.primary { width: 100%; margin-top: 10px; }
.link { background: none; border: none; color: var(--accent); font: inherit; padding: 0; }
.status { background: #fef3c7; color: #92400e; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .status { background: #3b2f12; color: #fcd34d; } }
.hint { font-size: .85rem; margin: 10px 0; }
.u { text-decoration: underline 2px var(--hl); text-underline-offset: 3px; }

.text { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 4px 16px; font-size: 1.1rem; line-height: 1.75; }
.text p { margin: 12px 0; }
.w { border-radius: 4px; }
.w.saved { text-decoration: underline 2px var(--hl); text-underline-offset: 4px; }
.w.on { background: var(--chip); outline: 2px solid var(--accent); }

.recent { list-style: none; padding: 0; margin: 0; }
.recent li { padding: 10px 2px; border-bottom: 1px solid var(--border); }

.phrase { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 5; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

.card {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; max-height: 55vh; overflow: auto; overscroll-behavior: contain;
  background: var(--card); border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); font-size: 16px;
}
.card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .src { font-size: 1.15rem; }
.card .actions { display: flex; gap: 2px; flex-shrink: 0; }
.icon { border: none; background: transparent; font-size: 20px; color: var(--muted); padding: 6px 8px; min-width: 40px; min-height: 40px; }
.star.on { color: #f59e0b; }
.star:disabled { opacity: .4; }
.meta { color: var(--muted); font-size: .85rem; }
.freq { font-size: .72rem; font-weight: 600; border-radius: 99px; padding: 1px 8px; margin-left: 4px; }
.f1 { background: #dcfce7; color: #166534; } .f2 { background: #dbeafe; color: #1d4ed8; } .f3 { background: #fef3c7; color: #92400e; }
.f4 { background: #fde2e2; color: #9f1239; } .f5 { background: #fde2e2; color: #9f1239; }
.tr { color: var(--accent); font-weight: 700; font-size: 1.25rem; margin: 4px 0 6px; }
.alts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.alts span { background: var(--chip); border-radius: 99px; padding: 2px 10px; font-size: .85rem; }
.note { margin: 8px 0; }
.sec { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 12px; }
.ex { list-style: none; padding: 0; margin: 4px 0; }
.ex li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.saved-msg { color: #16a34a; font-size: .85rem; margin-top: 8px; }
.cached { color: var(--muted); font-size: .8rem; margin-top: 8px; }
.loading { display: flex; gap: 5px; padding: 8px 0; }
.loading span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: b 1s infinite ease-in-out; }
.loading span:nth-child(2) { animation-delay: .15s; } .loading span:nth-child(3) { animation-delay: .3s; }
@keyframes b { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
