:root {
  --paper: #efe4cf;
  --paper-dark: #e3d5b8;
  --ink: #2b2118;
  --ink-soft: #5a4a38;
  --accent: #7a1f1f;
  --gold: #9c7c3c;
  --bg: #17130e;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: radial-gradient(ellipse at 50% 20%, #2a2218 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: "Playfair Display", Georgia, serif;
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 16px 40px;
}
header { text-align: center; margin-bottom: 22px; color: var(--paper); position: relative; width: 100%; max-width: 1060px; }
header .over { font-family: "IM Fell English", serif; letter-spacing: 4px;
               font-size: 13px; color: var(--gold); text-transform: uppercase; }
header h1 { font-size: clamp(22px, 4vw, 34px); font-weight: 900; margin: 6px 0 2px;
            letter-spacing: 1px; }
header .sub { font-family: "IM Fell English", serif; font-style: italic;
              color: #c9b995; font-size: 15px; }
header .rule { width: 340px; max-width: 80vw; height: 14px; margin: 12px auto 0;
  background:
    linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold) 80%, transparent) center/100% 1px no-repeat;
  position: relative; }
header .rule::after { content: "❦"; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -52%); color: var(--gold); background: #221b12;
  padding: 0 10px; font-size: 14px; }

/* Переключатель языка */
.lang-switch { display: inline-flex; gap: 0; margin-top: 12px;
  border: 1px solid var(--gold); border-radius: 20px; overflow: hidden; }
.lang-switch button {
  background: transparent; color: #c9b995; border: none; cursor: pointer;
  font-family: "IM Fell English", serif; font-size: 13px; padding: 6px 16px;
  transition: background .15s, color .15s;
}
.lang-switch button.active { background: var(--gold); color: #17130e; font-weight: 700; }

main { width: 100%; max-width: 1060px; }
.plate {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,250,235,.5), transparent 60%),
    var(--paper);
  border: 1px solid #b9a67f;
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 7px #a08c62, 0 30px 70px rgba(0,0,0,.6);
  border-radius: 3px;
  padding: 34px clamp(18px, 4vw, 48px) 30px;
  position: relative;
}
.plate::before { content: ""; position: absolute; inset: 10px; pointer-events: none;
  border: 1px solid rgba(90,74,56,.35); }

.stage { display: none; }
.stage.active { display: block; }

/* ---------- Загрузка ---------- */
#drop {
  border: 2px dashed #a08c62; border-radius: 4px;
  padding: 46px 20px; text-align: center; cursor: pointer;
  transition: background .2s, border-color .2s;
}
#drop:hover, #drop.drag { background: rgba(156,124,60,.12); border-color: var(--accent); }
#drop .icon { font-size: 44px; }
#drop h2 { font-size: 20px; margin: 10px 0 4px; }
#drop p { font-family: "IM Fell English", serif; color: var(--ink-soft); font-size: 14px; }
.btnrow { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 26px; }
button.btn {
  font-family: "Playfair Display", serif; font-weight: 700; font-size: 15px;
  background: var(--ink); color: var(--paper); border: none;
  padding: 12px 26px; cursor: pointer; letter-spacing: .5px;
  box-shadow: 0 3px 0 #000, inset 0 0 0 1px rgba(255,255,255,.15);
  transition: transform .1s, background .2s;
}
button.btn:hover { background: #3d2f21; }
button.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
button.btn.red { background: var(--accent); }
button.btn.ghost { background: transparent; color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink); }
button.btn:disabled { opacity: .45; cursor: default; }

/* ---------- Камера ---------- */
#cam-modal { position: fixed; inset: 0; background: rgba(10,8,5,.92);
  display: none; align-items: center; justify-content: center; z-index: 50; flex-direction: column; gap: 16px; }
#cam-modal.open { display: flex; }
#cam-video { max-width: min(92vw, 640px); max-height: 70vh; border: 6px solid var(--paper-dark);
  box-shadow: 0 20px 60px #000; transform: scaleX(-1); background: #000; }
#cam-err { color: #e8c9a0; font-family: "IM Fell English", serif; display: none; }

/* ---------- Анализ ---------- */
#stage-analyze { text-align: center; padding: 40px 0 30px; }
#ana-photo-wrap { position: relative; display: inline-block; margin-bottom: 18px;
  box-shadow: 0 12px 34px rgba(43,33,24,.45); border: 4px solid var(--paper-dark); }
#ana-photo { display: block; max-height: 240px; max-width: min(80vw, 420px);
  filter: grayscale(.65) sepia(.25) contrast(1.05); }
#ana-scan { position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 14px var(--accent); animation: scanY 1.6s ease-in-out infinite; }
@keyframes scanY { 0%,100% { top: 5% } 50% { top: 93% } }
.quill { font-size: 52px; animation: dip 1.6s ease-in-out infinite; display: inline-block; }
@keyframes dip { 0%,100% { transform: rotate(-8deg) translateY(0);} 50% { transform: rotate(6deg) translateY(6px);} }
#ana-status { font-family: "IM Fell English", serif; font-size: 17px; margin-top: 14px; color: var(--ink); }

/* ---------- Результаты ---------- */
.verdict-head { text-align: center; margin-bottom: 24px; }
.verdict-head .over { font-family: "IM Fell English", serif; letter-spacing: 3px;
  font-size: 12px; color: var(--accent); text-transform: uppercase; }
.verdict-head h2 { font-size: clamp(24px, 4vw, 36px); font-weight: 900; margin: 4px 0; }
.verdict-head .quote { font-family: "IM Fell English", serif; font-style: italic;
  color: var(--ink-soft); font-size: 15px; max-width: 640px; margin: 8px auto 0; }

.cols { display: grid; grid-template-columns: minmax(280px, 460px) 1fr; gap: 30px; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
#planche-wrap { text-align: center; }
#planche { width: 100%; height: auto; border: 1px solid #a08c62;
  box-shadow: 0 10px 30px rgba(43,33,24,.35); }
#planche-cap { font-family: "IM Fell English", serif; font-size: 12px;
  color: var(--ink-soft); margin-top: 8px; }

.gauge-wrap { text-align: center; margin-bottom: 18px; }
.gauge-num { font-size: 40px; font-weight: 900; }
.gauge-lab { font-family: "IM Fell English", serif; font-size: 13px;
  letter-spacing: 2px; text-transform: uppercase; color: var(--ink-soft); }

.metric { margin-bottom: 13px; }
.metric .row1 { display: flex; justify-content: space-between; align-items: baseline;
  font-size: 14.5px; gap: 10px; }
.metric .name { font-weight: 700; }
.metric .num { font-family: "IM Fell English", serif; color: var(--accent); white-space: nowrap; }
.metric .bar { height: 7px; background: #d8c9a6; margin-top: 5px; position: relative;
  box-shadow: inset 0 0 0 1px rgba(90,74,56,.4); }
.metric .fill { position: absolute; inset: 0 auto 0 0; width: 0%;
  background: linear-gradient(90deg, #9c7c3c, var(--accent)); transition: width .8s ease; }
.metric .note { font-family: "IM Fell English", serif; font-size: 13px;
  color: var(--ink-soft); margin-top: 4px; font-style: italic; }
.metric .roman { display: inline-block; min-width: 24px; color: var(--gold); font-weight: 900; }

.verdict-box { margin-top: 22px; background: rgba(122,31,31,.07);
  border: 1px solid rgba(122,31,31,.35); padding: 16px 18px; }
.verdict-box h3 { font-size: 15px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px; }
.verdict-box p { font-size: 14.5px; line-height: 1.55; }

footer { margin-top: 26px; max-width: 860px; text-align: center;
  color: #9b8a6c; font-family: "IM Fell English", serif; font-size: 13px; line-height: 1.6; }
footer b { color: #c9b995; }
footer a { color: #c9b995; }
footer > div { margin-bottom: 10px; font-size: 14px; }
#toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #2b2118; color: #efe4cf; padding: 10px 24px; border-radius: 4px;
  font-family: "IM Fell English", serif; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 99;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); }
#toast.show { opacity: 1; }

#debug-out { display: none; }

/* ---------- бланкъ «Особенности портрета» ---------- */
.sheet { margin-top: 18px; border: 1px solid rgba(90,74,56,.45); outline: 1px solid rgba(90,74,56,.2);
  outline-offset: 3px; padding: 14px 18px 16px; background: rgba(156,124,60,.05); }
.sheet-title { font-size: 12.5px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-soft); text-align: center; margin-bottom: 10px;
  font-family: "Playfair Display", serif; font-weight: 700; }

.grille { display: flex; flex-wrap: wrap; gap: 6px 22px; justify-content: center;
  padding: 8px 0 12px; border-bottom: 1px solid rgba(90,74,56,.35); margin-bottom: 10px; }
.g-cell { display: flex; align-items: center; gap: 8px;
  font-family: "IM Fell English", serif; font-size: 15px; }
.g-lab { color: var(--ink-soft); font-style: italic; }
.swatch { width: 17px; height: 17px; border-radius: 50%;
  border: 1.5px solid rgba(43,33,24,.55); box-shadow: inset 0 0 3px rgba(0,0,0,.25);
  background: #ccc; flex: none; }
.g-val { font-weight: 700; }
.g-wide { min-width: 70px; }

.z { margin-top: 14px; }
.z:first-child { margin-top: 4px; }
.z-title { font-family: "IM Fell English", serif; font-style: italic; font-size: 13.5px;
  color: var(--gold); letter-spacing: 1px; margin-bottom: 2px; }
.z-row { padding: 5px 0 0; }
.r-main { display: flex; align-items: baseline; gap: 8px; }
.r-name { font-weight: 700; font-size: 14.5px; }
.r-name .roman { display: inline-block; min-width: 26px; color: var(--gold); font-weight: 900; }
.r-leader { flex: 1; border-bottom: 1.5px dotted rgba(90,74,56,.55);
  transform: translateY(-3px); min-width: 20px; }
.r-val { font-family: "IM Fell English", serif; color: var(--accent);
  white-space: nowrap; font-size: 15px; }
.r-mark { width: 18px; text-align: center; font-size: 15px; flex: none; }
.r-mark.hi  { color: var(--accent); }
.r-mark.mid { color: #9c7c3c; }
.r-mark.lo  { color: rgba(90,74,56,.45); }
.r-note { font-family: "IM Fell English", serif; font-size: 12.5px; font-style: italic;
  color: var(--ink-soft); margin: 1px 0 0 34px; line-height: 1.35; }

.verdict-box .drivers { font-family: "IM Fell English", serif; font-size: 15.5px;
  color: var(--accent); font-weight: 700; margin-bottom: 8px; }

@media (max-width: 700px) {
  .grille { flex-direction: column; align-items: flex-start; gap: 8px; }
}
