:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e2ddd1;
  --accent: #1f3a5f;
  --accent-ink: #ffffff;
  --ok: #2f6b3a;
  --err: #a33a2b;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }

.top { padding: 28px 20px 8px; max-width: 720px; margin: 0 auto; }
.top h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 40px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

.drop {
  display: grid; place-items: center; min-height: 180px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 12px; text-align: center;
  background: repeating-linear-gradient(0deg, transparent 0 27px, #ebe6da 27px 28px);
  overflow: hidden;
}
.drop:hover, .drop:focus-within { border-color: var(--accent); }
.drop strong { display: block; font-size: 1.05rem; color: var(--accent); }
.drop small { color: var(--muted); }
.drop img { width: 100%; max-height: 420px; object-fit: contain; background: #fff; }

.field { display: grid; gap: 6px; margin-top: 16px; font-size: 0.9rem; color: var(--muted); }
textarea {
  font: inherit; color: var(--ink); width: 100%; resize: vertical;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px;
  padding: 13px 18px; background: var(--accent); color: var(--accent-ink);
}
#submit { width: 100%; margin-top: 16px; font-size: 1rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); padding: 8px 12px; font-size: 0.85rem; }

.hint { min-height: 1.2em; margin: 10px 0 0; font-size: 0.9rem; color: var(--muted); }
.hint.error { color: var(--err); }
.hint.loading::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.result-head h2 { margin: 0; font-size: 1.15rem; }
#answer { line-height: 1.6; overflow-wrap: anywhere; }
#answer .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
#answer code { background: #f0ece2; padding: 1px 5px; border-radius: 4px; }
.meta { color: var(--muted); font-size: 0.8rem; margin: 12px 0 0; }

@media (prefers-color-scheme: dark) {
  :root { --bg: #14171d; --card: #1c2028; --ink: #e8e6e1; --muted: #9aa0aa; --line: #2e333d; --accent: #8fb3e0; --accent-ink: #10141a; }
  .drop { background: repeating-linear-gradient(0deg, transparent 0 27px, #232833 27px 28px); }
  textarea { background: #161a21; }
  #answer code { background: #262b35; }
}

/* Памятка */
.memo { padding: 0; }
.memo summary {
  list-style: none; cursor: pointer; padding: 16px 48px 16px 18px; position: relative;
  display: grid; gap: 2px;
}
.memo summary::-webkit-details-marker { display: none; }
.memo summary::after {
  content: ""; position: absolute; right: 20px; top: 50%; width: 9px; height: 9px;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: translateY(-70%) rotate(45deg); transition: transform 0.2s;
}
.memo[open] summary::after { transform: translateY(-30%) rotate(-135deg); }
.memo summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.memo-title { font-weight: 700; font-size: 1.05rem; color: var(--accent); }
.memo-sub { font-size: 0.85rem; color: var(--muted); }
.memo > :not(summary) { margin-left: 18px; margin-right: 18px; }
.memo > :last-child { margin-bottom: 18px; }
.memo-why { margin-top: 0; line-height: 1.5; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 8px 8px 0; }
.memo h3 { font-size: 0.95rem; margin: 18px 18px 8px; }
.memo-list { margin-top: 0; margin-bottom: 0; padding-left: 20px; display: grid; gap: 8px; line-height: 1.5; font-size: 0.95rem; }
.memo-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.memo-compare > div { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 0.88rem; line-height: 1.45; }
.memo-compare p { margin: 6px 0 0; }
.tag { font-weight: 700; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.memo-bad { border-color: color-mix(in srgb, var(--err) 35%, var(--line)) !important; }
.memo-bad .tag { color: var(--err); }
.memo-good { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)) !important; }
.memo-good .tag { color: var(--ok); }
.memo-note { font-size: 0.85rem; color: var(--muted); margin-top: 14px; }
@media (max-width: 420px) { .memo-compare { grid-template-columns: 1fr; } }
@media (prefers-color-scheme: dark) { :root { --ok: #7cc48a; --err: #e48b7d; } }

/* Несколько фото */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.photos:not(:empty) { margin-bottom: 10px; }
.photo { position: relative; margin: 0; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo figcaption {
  position: absolute; left: 6px; bottom: 6px; min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 11px; font-size: 0.75rem; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
}
.photo .remove {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; padding: 0; border-radius: 50%;
  font-size: 1.2rem; line-height: 1; background: rgba(20, 23, 29, 0.7); color: #fff;
}
.drop.compact { min-height: 72px; }
.drop[hidden] { display: none; }
