/* Сортувальний капелюх — сторінка тесту.
   До результату: лише нейтральна палітра «старої повсті». Кольори факультетів
   (--house) з'являються тільки на екрані результату. */

@font-face { font-family: "Arsenal"; src: url("../fonts/Arsenal-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Arsenal"; src: url("../fonts/Arsenal-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Arsenal"; src: url("../fonts/Arsenal-Bold.ttf") format("truetype"); font-weight: 700; font-style: normal; font-display: swap; }

:root {
  --felt: #1F1A17;
  --felt-2: #2A2420;
  --felt-3: #352D28;
  --paper: #EFE6D6;
  --muted: #A39788;
  --line: #4A4039;
  --silver: #B9A8DC;          /* сріблясто-бузковий: не колір жодного факультету */
  --silver-ink: #1F1A17;
  --danger: #E3A39B;
  --house: var(--silver);     /* перевизначається лише на екрані результату */

  --radius: 14px;
  --gap: 1rem;
  --measure: 34rem;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--felt) radial-gradient(120% 70% at 50% 0%, var(--felt-3), var(--felt) 70%) fixed;
  color: var(--paper);
  font-family: "Arsenal", "Segoe UI", system-ui, sans-serif;
  font-size: 1.125rem;
  line-height: 1.5;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

#app { min-height: 100dvh; }
.screen {
  min-height: 100dvh;
  max-width: var(--measure);
  margin: 0 auto;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem max(2rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.screen.entering { animation: enter .45s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { font-weight: 700; line-height: 1.15; margin: 0; }
p { margin: 0; }

/* --- Капелюх --- */
.hat { fill: none; stroke: var(--paper); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.hat .crease, .hat use { stroke-opacity: 1; }
.hat-welcome { width: 7.5rem; height: 5.6rem; margin: 2.5rem auto 1.25rem; display: block; opacity: .9; }
.hat-thinking { width: 10rem; height: 7.5rem; display: block; margin: 0 auto 1.5rem; transform-origin: 50% 85%; animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1) rotate(0); } 50% { transform: scale(1.04) rotate(-2deg); } }

/* --- Вітання --- */
.screen-welcome { text-align: center; }
.screen-welcome h1 { font-size: 2.4rem; letter-spacing: .01em; }
.lede { color: var(--muted); margin: .75rem auto 2rem; max-width: 26rem; }
#welcome-form { text-align: left; display: grid; gap: 1.75rem; }

.field { display: grid; gap: .5rem; }
.field-label, .choice legend { font-weight: 700; font-size: 1.05rem; }
input[type="text"] {
  font: inherit; color: var(--paper);
  background: var(--felt-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem 1rem; width: 100%;
}
input[type="text"]:focus { outline: none; border-color: var(--silver); box-shadow: 0 0 0 3px rgb(185 168 220 / .25); }
.field-error { color: var(--danger); font-size: .95rem; }

.choice { border: 0; padding: 0; margin: 0; display: grid; gap: .6rem; }
.choice legend { padding: 0; margin-bottom: .6rem; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.choice label { display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: block; text-align: center;
  padding: .75rem .5rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--felt-2); transition: border-color .15s, background .15s;
}
.choice-wide span { color: var(--muted); }
.choice input:checked + span { border-color: var(--silver); background: var(--felt-3); color: var(--paper); box-shadow: inset 0 0 0 1px var(--silver); }
.choice input:focus-visible + span { outline: 3px solid var(--silver); outline-offset: 2px; }

/* --- Кнопки --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 700; text-decoration: none; text-align: center;
  color: var(--paper); background: transparent;
  border: 1px solid var(--line); border-radius: 999px;
  padding: .85rem 1.5rem; min-height: 3.1rem; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--silver); border-color: var(--silver); color: var(--silver-ink); }
.btn-primary:hover { background: #C9BCE5; border-color: #C9BCE5; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .6; cursor: progress; }
.btn-link { font: inherit; color: var(--muted); background: none; border: 0; padding: .6rem; text-decoration: underline; text-underline-offset: .2em; cursor: pointer; }
.btn-link:hover { color: var(--paper); }
:focus-visible { outline: 3px solid var(--silver); outline-offset: 3px; }

/* --- Питання --- */
.screen-question { position: relative; max-width: none; padding: 0; }
.question-bg {
  position: fixed; inset: 0; z-index: 0;
  background-color: var(--felt); background-size: cover; background-position: center;
  transition: opacity .35s;
}
.question-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgb(31 26 23 / .55) 0%, rgb(31 26 23 / .78) 40%, rgb(31 26 23 / .96) 70%, var(--felt) 100%);
}
.question-inner {
  position: relative; z-index: 1;
  width: 100%; max-width: var(--measure); margin: 0 auto;
  min-height: 100dvh; display: flex; flex-direction: column;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.75rem, env(safe-area-inset-bottom));
}
.progress { height: 4px; border-radius: 4px; background: rgb(239 230 214 / .15); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--paper); border-radius: 4px; transition: width .4s var(--ease); }
.progress-label { margin-top: .6rem; color: var(--muted); font-size: .95rem; }
.question-text { margin-top: auto; padding-top: 3rem; font-size: 1.6rem; line-height: 1.25; outline: none; }
.options { display: grid; gap: .65rem; margin-top: 1.5rem; }
.option {
  font: inherit; text-align: left; color: var(--paper);
  background: rgb(42 36 32 / .82); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; min-height: 3.4rem; cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: border-color .15s, background .15s, transform .1s;
}
.option:hover { border-color: var(--muted); }
.option:active { transform: scale(.99); }
.option.chosen { border-color: var(--silver); background: rgb(53 45 40 / .95); box-shadow: inset 0 0 0 1px var(--silver); }
.options[aria-busy="true"] .option:not(.chosen) { opacity: .45; }
.options[aria-busy="true"] .option { pointer-events: none; }

/* --- Думає / вагається --- */
.screen-thinking, .screen-extra { justify-content: center; text-align: center; }
.thinking-text { color: var(--muted); font-size: 1.2rem; }
.hat-voice { font-size: 1.55rem; line-height: 1.35; margin-bottom: 2rem; }

/* --- Результат --- */
.screen-result {
  padding-top: 2.5rem;
  /* --house задає JS лише тут. Кольори факультетів підібрані для світлого паперу документа,
     тож на темному тлі для тексту беремо світліший відтінок. Обчислюємо саме тут, а не в :root:
     інакше змінна обчислилася б від бузкового значення за замовчуванням. */
  --house-ink: color-mix(in oklab, var(--house) 62%, white);
}
.verdict-block { text-align: center; }
.house-mark {
  width: 6.5rem; height: 6.5rem; margin: 0 auto 1.25rem; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  border: 2px solid var(--house-ink); color: var(--house-ink);
  font-size: 3rem; font-weight: 700;
  background: color-mix(in srgb, var(--house) 30%, var(--felt));
}
.house-mark img { width: 100%; height: 100%; object-fit: cover; }
.house-mark.tie { font-size: 2.6rem; }
.verdict-kicker { color: var(--muted); }
.verdict { font-size: clamp(2.6rem, 12vw, 4.2rem); color: var(--house-ink); margin-top: .15rem; line-height: 1.05; }
.verdict.tie { font-size: clamp(2rem, 9vw, 3rem); }
.badges { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.badges li { border: 1px solid var(--line); border-radius: 999px; padding: .3rem .8rem; font-size: .95rem; color: var(--paper); }

.speech { margin-top: 2.25rem; display: grid; gap: 1rem; font-size: 1.3rem; line-height: 1.45; min-height: 6rem; }
.speech p.typing::after { content: "▍"; color: var(--muted); animation: blink 1s steps(1) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
#speech-skip { align-self: flex-start; margin-top: .5rem; }

.result-rest { margin-top: 2.5rem; display: grid; gap: 2.25rem; }
.result-rest.entering { animation: enter .5s var(--ease) both; }
.scale h3, .profiles h3 { font-size: 1.25rem; }
.note { color: var(--muted); font-size: .95rem; margin-top: .35rem; }
.bars { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .85rem; }
.bar-row { display: grid; grid-template-columns: 7.2rem 1fr 3rem; align-items: center; gap: .75rem; }
.bar-row.is-result .bar-name { font-weight: 700; }
.bar-track { display: block; height: .7rem; border-radius: .7rem; background: color-mix(in srgb, var(--c) 22%, var(--felt-2)); overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: color-mix(in oklab, var(--c) 72%, white); border-radius: .7rem; transition: width .9s var(--ease); }
.bar-pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.second { font-style: italic; color: var(--paper); border-left: 3px solid var(--line); padding-left: 1rem; }
.profiles { display: grid; gap: 1.75rem; }
.profile h3 { color: color-mix(in oklab, var(--pc, var(--house)) 62%, white); margin-bottom: .6rem; }
.profile p + p { margin-top: .8rem; }
.profile p { color: #DCD2C1; }

.actions { display: grid; gap: .7rem; }
.actions .btn-link { justify-self: center; margin-top: .5rem; }

/* --- Повідомлення --- */
.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 2rem); z-index: 10;
  background: var(--paper); color: var(--felt); border-radius: var(--radius);
  padding: .8rem 1.1rem; box-shadow: 0 8px 30px rgb(0 0 0 / .35);
}
.noscript { padding: 2rem; text-align: center; }

@media (min-width: 40rem) {
  body { font-size: 1.2rem; }
  .question-text { font-size: 2rem; }
  .speech { font-size: 1.45rem; }
  .actions { grid-template-columns: 1fr 1fr; }
  .actions .btn-link, #cert-share { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
