/* 3Abroad. Sorting Hat: the site's cobalt night sky, one question at a time. */
:root {
  --cobalt: #2a30c8;
  --ink: #1e2496;
  --cream: #f3eee2;
  --soft: #dcd8f0;
  --serif: 'IM Fell English', Garamond, 'Times New Roman', serif;
  --sc: 'IM Fell English SC', Garamond, 'Times New Roman', serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100svh; overflow-x: hidden;
  background: var(--cobalt); color: var(--cream);
  font-family: var(--sc); font-size: 18px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
[hidden] { display: none !important; }
.sky { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* A cream flash at the verdict, and the dimming while the hat thinks */
.flash { position: fixed; inset: 0; pointer-events: none; z-index: 5; opacity: 0; background: radial-gradient(circle at 50% 30%, rgba(243,238,226,.9), rgba(243,238,226,.25) 35%, rgba(243,238,226,0) 70%); }
.flash.is-on { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }
body::after { content: ''; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 35%, rgba(10,12,70,0) 30%, rgba(10,12,70,.55)); opacity: 0; transition: opacity 1.2s ease; }
body.is-thinking::after { opacity: 1; }

.bar { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 24px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--cream); text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--serif); font-size: 26px; }
.brand-desc { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; opacity: .85; }
.back { white-space: nowrap; color: var(--cream); font-size: 17px; text-decoration: none; background-image: linear-gradient(currentColor, currentColor); background-size: 0 1px; background-position: 50% 100%; background-repeat: no-repeat; transition: background-size .3s ease; }
.back:hover, .back:focus-visible { background-size: 100% 1px; }

.stage { position: relative; flex: 1; width: min(720px, 100% - 32px); margin: 0 auto; padding: 8px 0 64px; display: flex; flex-direction: column; align-items: center; text-align: center; }

/* The hat */
.hat-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.hat-lean { --lean: 0deg; transform: rotate(var(--lean)); transform-origin: 50% 95%; transition: transform .6s cubic-bezier(.3, 1.4, .5, 1); }
.hat { width: 200px; transform-origin: 50% 90%; animation: hat-idle 5s ease-in-out infinite; transition: width .9s cubic-bezier(.3, 1, .4, 1); }
/* While it thinks, the hat moves to the middle of the screen and grows. */
.stage { transition: padding-top .9s cubic-bezier(.3, 1, .4, 1); }
body.is-thinking .stage { padding-top: max(8px, calc(50svh - 260px)); }
body.is-thinking .hat { width: 280px; }
.hat svg, .hat img { display: block; width: 100%; height: auto; overflow: visible; }
.hat .mouth, .hat .eyes { transform-box: fill-box; transform-origin: 50% 30%; transition: transform .12s ease; }
.hat.is-talking .mouth { animation: mouth .16s ease-in-out infinite alternate; }
.hat.is-blinking .eyes { transform: scaleY(.15); }
@keyframes mouth { from { transform: scaleY(.7); } to { transform: scaleY(1.7) translateY(1px); } }
.hat-wrap.is-thinking .hat-says { animation: glimmer 1.2s ease-in-out infinite; }
@keyframes glimmer { 50% { opacity: .55; } }
.hat-wrap.is-thinking .hat { animation: hat-think .9s ease-in-out infinite; }
.hat-wrap.is-speaking .hat { animation: hat-speak .5s ease-in-out 3; }
.hat-says { min-height: 2.6em; max-width: 30ch; margin: 6px 0 0; font-family: var(--serif); font-style: italic; font-size: 22px; line-height: 1.3; opacity: 0; transition: opacity .3s ease; text-wrap: balance; text-shadow: 0 0 18px rgba(190,186,255,.6); }
.hat-says.is-on { opacity: 1; }
@keyframes hat-idle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) translateY(-3px); } }
@keyframes hat-think { 0%, 100% { transform: rotate(-7deg) scaleY(.98); } 50% { transform: rotate(7deg) scaleY(1.03) translateY(-6px); } }
@keyframes hat-speak { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06) rotate(-2deg); } }
@media (prefers-reduced-motion: reduce) { .hat, .hat-wrap.is-thinking .hat, .hat-wrap.is-speaking .hat, .hat.is-talking .mouth { animation: none; } .hat-lean { transition: none; } }

/* Screens */
.screen { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; animation: screen-in .45s ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } }
.kicker { font-size: 15px; letter-spacing: .2em; text-transform: uppercase; opacity: .85; }
h1, h2 { margin: 0; font-family: var(--serif); font-weight: 400; letter-spacing: -.01em; line-height: 1.05; text-wrap: balance; }
h1 { font-size: clamp(44px, 8vw, 68px); }
h2 { font-size: clamp(32px, 6vw, 46px); }
h1 em { font-style: italic; }
.lead { max-width: 36ch; margin: 0; font-size: 20px; }
.fine { margin: 6px 0 0; font-size: 14px; opacity: .7; max-width: 46ch; }
.hint { margin: -4px 0 4px; font-size: 16px; opacity: .8; min-height: 1em; }
.step { margin: 0; font-size: 15px; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
.trail { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 0; }
.trail li { position: relative; width: 7px; height: 7px; border-radius: 50%; background: rgba(243,238,226,.25); transition: background .4s, transform .4s; }
.trail li + li { margin-left: 14px; }
.trail li + li::before { content: ''; position: absolute; right: 100%; top: 3px; width: 14px; height: 1px; background: rgba(243,238,226,.2); }
.trail li.is-done { background: var(--cream); box-shadow: 0 0 8px rgba(243,238,226,.7); }
.trail li.is-done + li::before, .trail li.is-done + li.is-done::before { background: rgba(243,238,226,.7); }
.trail li.is-here { background: var(--cream); transform: scale(1.5); }
.trail li.is-here::after { content: ''; position: absolute; inset: -5px; border-radius: 50%; border: 1px solid var(--cream); animation: ring 1.6s ease-out infinite; }
@keyframes ring { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }

/* Buttons */
.btn { min-height: 52px; padding: 0 30px; border: 1px solid var(--cream); border-radius: 999px; background: var(--cream); color: var(--cobalt); font: inherit; font-size: 20px; cursor: pointer; transition: background .2s, color .2s; }
.btn:hover { background: transparent; color: var(--cream); }
.btn:focus-visible, .opt:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }
.link-btn { min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--cream); font: inherit; font-size: 17px; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; opacity: .85; }
.link-btn:disabled { visibility: hidden; }
.nav-row { width: 100%; display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }

/* Answers */
.options { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.opt {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 64px;
  padding: 14px 18px; border: 1px solid rgba(243, 238, 226, .6); border-radius: 16px; background: rgba(243, 238, 226, .04);
  color: var(--cream); font: inherit; text-align: left; cursor: pointer; transition: background .2s, border-color .2s, color .2s;
}
.options.is-long { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.opt:hover { background: rgba(243, 238, 226, .12); border-color: var(--cream); }
.opt[aria-pressed="true"] { background: var(--cream); color: var(--cobalt); border-color: var(--cream); }
.opt b { font-family: var(--serif); font-weight: 400; font-size: 22px; line-height: 1.15; text-wrap: balance; }
.opt small { font-size: 15px; opacity: .8; }

/* The verdict */
.picks { list-style: none; margin: 4px 0 0; padding: 0; width: 100%; display: grid; gap: 14px; }
.pick { padding: 20px 22px; border: 1px solid rgba(243, 238, 226, .6); border-radius: 18px; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.pick-rank { font-size: 15px; letter-spacing: .16em; text-transform: uppercase; opacity: .8; }
.pick-name { margin: 0; font-family: var(--serif); font-size: clamp(28px, 5vw, 36px); line-height: 1.1; }
.pick-place { font-family: var(--serif); font-style: italic; font-size: 19px; opacity: .9; }
.pick-why { margin: 4px 0 0; font-size: 16px; }
.pick-links { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 4px; }
.pick-links a { color: var(--cream); font-size: 16px; }
.loosened { margin: 0; font-size: 15px; font-style: italic; opacity: .85; max-width: 46ch; }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 20px; margin-top: 6px; }
/* Sharing a result */
.share { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 8px; }
.share-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.share-opt { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid rgba(243,238,226,.6); border-radius: 999px; background: rgba(243,238,226,.05); color: var(--cream); font: inherit; font-size: 16px; text-decoration: none; cursor: pointer; transition: background .2s, border-color .2s, box-shadow .3s; }
.share-opt:hover { background: rgba(243,238,226,.14); border-color: var(--cream); box-shadow: 0 0 22px rgba(190,186,255,.3); }
.share-opt:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }
.share-opt:disabled { opacity: .6; cursor: progress; }
.share-opt svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.share-toast { min-height: 1.4em; margin: 0; max-width: 40ch; font-family: var(--serif); font-style: italic; font-size: 17px; opacity: 0; transition: opacity .3s; }
.share-toast.is-on { opacity: .95; }
#result .share { animation: fade-in .8s ease both; animation-delay: 1.3s; }
@media (max-width: 680px) {
  .share-row { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .share-opt { justify-content: center; padding: 0 10px; font-size: 15px; }
}

@media (max-width: 680px) {
  .bar { padding: 14px 16px; }
  .brand-name { font-size: 22px; }
  .brand-desc { display: none; }
  .hat-says { font-size: 18px; }
  .options { grid-template-columns: 1fr 1fr; gap: 10px; }
  .options.is-long { grid-template-columns: 1fr; }
  .opt { min-height: 56px; padding: 10px 14px; border-radius: 14px; }
  .opt b { font-size: 20px; }
  .opt small { font-size: 13px; }
}

/* ---------- Motion ---------- */
/* Headings arrive word by word, out of a blur. */
.w { display: inline-block; animation: word-in .7s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i) * 70ms); }
@keyframes word-in { from { opacity: 0; filter: blur(10px); transform: translateY(12px); } to { opacity: 1; filter: none; transform: none; } }
/* Answers float in after the question, one by one. */
#quiz.is-arriving .opt { animation: opt-in .55s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: calc(320ms + var(--i) * 70ms); }
@keyframes opt-in { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
.opt { transition: background .2s, border-color .2s, color .2s, opacity .4s, transform .4s, box-shadow .3s; }
.opt:hover { box-shadow: 0 0 0 1px var(--cream), 0 0 26px rgba(190,186,255,.35); transform: translateY(-2px); }
/* Picking one: it glows, the rest fall away. */
.options.is-decided .opt:not(.is-chosen) { opacity: .18; transform: scale(.96); }
#quiz .opt.is-chosen { animation: chosen .7s ease-out; box-shadow: 0 0 0 1px var(--cream), 0 0 40px rgba(243,238,226,.55); }
@keyframes chosen { 0% { transform: scale(1); } 35% { transform: scale(1.04); } 100% { transform: scale(1); } }
/* Leaving a question */
#quiz.is-leaving { animation: leave .32s ease-in both; }
@keyframes leave { to { opacity: 0; transform: translateY(-16px); filter: blur(4px); } }
#quiz.is-arriving .step, #quiz.is-arriving .hint { animation: fade-in .6s ease both; }
@keyframes fade-in { from { opacity: 0; } }
/* The verdict: cards turn over into place. */
.picks { perspective: 900px; }
.pick { animation: pick-in .9s cubic-bezier(.2, .9, .3, 1.1) both; animation-delay: calc(500ms + var(--i) * 260ms); transform-origin: 50% 0; background: rgba(243,238,226,.05); backdrop-filter: blur(2px); }
@keyframes pick-in { from { opacity: 0; transform: rotateX(-70deg) translateY(30px); } to { opacity: 1; transform: none; } }
.pick:first-child { border-color: var(--cream); box-shadow: 0 0 40px rgba(190,186,255,.3); }
#result .result-actions, #result .fine, #result .loosened { animation: fade-in .8s ease both; animation-delay: 1.3s; }
/* Start button: a slow shimmer runs across it. */
.btn { position: relative; overflow: hidden; }
#start::after { content: ''; position: absolute; top: 0; bottom: 0; width: 40%; left: -60%; background: linear-gradient(100deg, transparent, rgba(255,255,255,.7), transparent); animation: shimmer 3.2s ease-in-out infinite; }
#start:hover::after { animation: none; }
@keyframes shimmer { 0%, 55% { left: -60%; } 100% { left: 130%; } }
@media (prefers-reduced-motion: reduce) {
  .w, #quiz.is-arriving .opt, #quiz .opt.is-chosen, #quiz.is-leaving, .pick, #start::after, .trail li.is-here::after, .flash.is-on { animation: none; }
}

/* ---------- Sound switch ---------- */
.sound { position: fixed; z-index: 6; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 6px 6px 6px 18px; border: 0; border-radius: 999px; background: rgba(20,24,120,.55); backdrop-filter: blur(6px); color: var(--cream); font: inherit; font-size: 15px; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; cursor: pointer; }
.sound:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }
.sound-switch { position: relative; width: 84px; height: 40px; border: 1px solid var(--cream); border-radius: 999px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; }
.sound-switch svg { position: relative; z-index: 1; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transition: color .3s; }
.sound-knob { position: absolute; top: 3px; right: 3px; width: 32px; height: 32px; border-radius: 50%; background: var(--cream); transition: transform .35s cubic-bezier(.3, 1.4, .5, 1); }
.sound .ico-off { color: var(--cobalt); }
.sound[aria-pressed="true"] .sound-knob { transform: translateX(-42px); }
.sound[aria-pressed="true"] .ico-on { color: var(--cobalt); }
.sound[aria-pressed="true"] .ico-off { color: var(--cream); }
.stage { padding-bottom: 96px; }
@media (max-width: 680px) {
  .sound { font-size: 12px; gap: 10px; padding-left: 14px; }
  .sound-switch { width: 72px; height: 34px; }
  .sound-knob { width: 26px; height: 26px; }
  .sound[aria-pressed="true"] .sound-knob { transform: translateX(-36px); }
  .trail li + li { margin-left: 9px; }
  .trail li + li::before { width: 9px; }
  .hat { width: 140px; }
  body.is-thinking .hat { width: 200px; }
}
