:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface2: #eef0f6; --text: #1b1c22; --muted: #5d6070;
  --border: #dfe2ec; --primary: #c4302b; --primary-text: #fff; --accent: #1a73e8; --danger: #b3261e;
  --err-bg: #fdecea; --err-border: #f3b8b2; --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121318; --surface: #1c1d24; --surface2: #262833; --text: #e6e6ee; --muted: #a2a5b5;
    --border: #30323e; --primary: #ff5a4e; --primary-text: #1a0503; --accent: #8ab4f8; --danger: #ffb4ab;
    --err-bg: #3a1d1b; --err-border: #6b2c27; --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; }
h1 { font-size: 1.1rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
main { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
main > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
input[type=password], input[type=text], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; min-height: 48px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.opts { display: grid; gap: 12px; margin: 14px 0; }
@media (min-width: 640px) { .opts { grid-template-columns: 1fr 2fr; } }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.seg { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; font: inherit; font-size: .88rem; color: var(--muted); background: transparent; border: 0; border-radius: 9px;
  padding: 9px 6px; min-height: 42px; cursor: pointer; line-height: 1.2;
}
.seg button[aria-checked=true] { background: var(--surface); color: var(--text); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.btn {
  font: inherit; font-weight: 600; border-radius: 12px; padding: 10px 16px; min-height: 44px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
}
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .7; cursor: progress; }
.icon-btn { background: transparent; border: 0; color: var(--text); padding: 8px; border-radius: 50%; cursor: pointer; min-width: 44px; min-height: 44px; }
.icon-btn.small { min-width: 36px; min-height: 36px; color: var(--muted); }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
.banner { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); border-radius: var(--radius); padding: 12px 16px; }
.status { display: flex; gap: 14px; align-items: center; }
.status > div:not(.spinner) { flex: 1; }
.status.error { background: var(--err-bg); border-color: var(--err-border); align-items: flex-start; }
.status details { margin-top: 6px; font-size: .85rem; color: var(--muted); }
.status code { word-break: break-word; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { margin: 6px 0 0; }
.result-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.result-head img { border-radius: 10px; object-fit: cover; background: var(--surface2); flex: none; }
.r-meta { min-width: 0; }
#r-title { color: var(--text); font-weight: 650; text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#r-sub { font-size: .85rem; }
.md { overflow-wrap: anywhere; }
.md h2, .md h3, .md h4 { margin: 18px 0 6px; font-size: 1.02rem; }
.md ul, .md ol { padding-left: 1.3em; margin: 8px 0; }
.md li { margin: 6px 0; }
.md p { margin: 8px 0; }
.md code { background: var(--surface2); padding: 1px 5px; border-radius: 6px; font-size: .9em; }
a { color: var(--accent); }
a.ts {
  display: inline-block; font-variant-numeric: tabular-nums; font-size: .85em; font-weight: 650; text-decoration: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); padding: 0 7px; border-radius: 999px; margin-right: 2px;
}
a.ts:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.hist-head { display: flex; justify-content: space-between; align-items: center; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history { grid-template-columns: minmax(0, 1fr); }
.history li { display: flex; align-items: center; gap: 4px; min-width: 0; }
.hist-item { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; text-align: left; font: inherit; color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 6px; cursor: pointer; }
.hist-item img { border-radius: 8px; object-fit: cover; flex: none; }
.hist-item > div { min-width: 0; }
.hist-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
dialog { border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text); padding: 20px; width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .label { margin-top: 14px; }
dialog .actions { margin-top: 18px; }
@media (max-width: 420px) { dialog .actions #btn-delkey { order: 3; width: 100%; } dialog .actions .spacer { display: none; } dialog .actions button[value] { flex: 1; } }
.note { font-size: .88rem; color: var(--muted); background: var(--surface2); border-radius: 12px; padding: 10px 12px; margin: 10px 0 0; }
.check { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.check input { width: 20px; height: 20px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; z-index: 20; max-width: calc(100vw - 32px); }

.status.error { flex-direction: column; align-items: stretch; }
.err-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.err-actions:empty { display: none; }
.model-note { margin: 10px 0 0; }
