:root {
  --fog: #0e1220;
  --fog-2: #161c2e;
  --panel: #151b2c;
  --panel-2: #1b2236;
  --line: #2a3350;
  --ink: #e7e2d6;
  --muted: #9aa3b5;
  --flame: #ffb347;
  --danger: #ff8a7a;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

html { background: var(--fog); }

body {
  min-height: 100vh;
  background: radial-gradient(ellipse 120% 600px at 50% 0%, var(--fog-2), var(--fog)) no-repeat var(--fog);
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  line-height: 1.45;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 16px 48px;
}

[hidden] { display: none !important; }

/* ---------- Typography ---------- */
h1 { font-size: 2.4rem; letter-spacing: .06em; margin: 8px 0 4px; }
h2 { margin: 0; }
.tag { font-style: normal; }
.hero { text-align: center; margin-bottom: 24px; }
.hero .tag { color: var(--muted); font-style: italic; margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.eyebrow { margin: 0; color: var(--muted); font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; }
.error { color: var(--danger); min-height: 1.4em; margin: 10px 0 0; font-size: .95rem; }

/* ---------- Controls ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 12px;
}

label { font-size: .9rem; color: var(--muted); }

input {
  font: inherit;
  color: var(--ink);
  background: var(--fog);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
}
input:focus { outline: 2px solid var(--flame); outline-offset: 1px; border-color: transparent; }

#code {
  text-transform: uppercase;
  letter-spacing: .4em;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  padding: 11px 22px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
}
button:hover:not(:disabled) { filter: brightness(1.12); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--flame); color: var(--fog); border-color: transparent; font-weight: 600; }
button.ghost { background: transparent; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; display: block; margin: 20px auto 0; }

.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Keeper art ---------- */
.hero-keeper { display: flex; justify-content: center; }
.keeper-svg .flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 2.4s ease-in-out infinite; }
.keeper-svg.dim { opacity: .45; }
.keeper-svg.dim .flame { animation: none; }
@keyframes flicker {
  0%, 100% { transform: scale(1, 1); }
  30% { transform: scale(.92, 1.06); }
  60% { transform: scale(1.05, .95); }
}

/* ---------- Lobby ---------- */
.lobby-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.room-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 2.6rem;
  letter-spacing: .3em;
  color: var(--flame);
}

.players {
  list-style: none;
  margin: 16px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.player {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 12px 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
  min-height: 140px;
}
.player.me { border-color: var(--flame); }
.player.away .player-name { color: var(--muted); }
.player.empty { border-style: dashed; background: transparent; color: var(--muted); align-content: center; }
.player .seat { width: 34px; height: 54px; border: 1px dashed var(--line); border-radius: 10px; }
.player-name { font-size: .95rem; overflow-wrap: anywhere; }

.tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; min-height: 1.3em; }
.tags .tag, .here-list .tag {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .68rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.tag-host { color: var(--flame) !important; border-color: var(--flame) !important; }
.tag-bot { color: #4fc3d9 !important; border-color: #2b6b78 !important; }

.remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  padding: 0;
  line-height: 1;
  font-size: 1rem;
  background: transparent;
  color: var(--muted);
}

.host-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.small { font-size: .85rem; }
button.wide { width: 100%; }

/* ---------- Role reveal ---------- */
.reveal { text-align: center; padding-top: 48px; }
.reveal-art { display: flex; justify-content: center; margin: 12px 0 4px; }
.reveal h1 { font-size: 2rem; animation: rise .7s ease-out both; }
.reveal-text { max-width: 26em; margin: 8px auto 24px; color: var(--ink); animation: rise .7s .15s ease-out both; }
.reveal.shade h1 { color: #c9b6ff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.countdown { height: 4px; background: var(--line); border-radius: 999px; overflow: hidden; max-width: 280px; margin: 24px auto 10px; }
.countdown span { display: block; height: 100%; width: 100%; background: var(--flame); }
.reveal.shade .countdown span { background: #9b7bff; }

.allies { margin-top: 8px; }
.allies-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.allies-list li { display: grid; justify-items: center; gap: 2px; }

/* Shade players get a colder palette once they know. */
body.is-shade { --flame: #9b7bff; }
body.is-shade .shade-svg .flame { animation-duration: 3.6s; }
.shade-svg .smoke { animation: drift 3s ease-in-out infinite; }
@keyframes drift { 0%, 100% { transform: translateY(0); opacity: .7; } 50% { transform: translateY(-2px); opacity: .35; } }

/* ---------- In game ---------- */
.game-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.peek { padding: 8px 16px; font-size: .9rem; }
.peek-role { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.peek-role.keeper { border-color: #ffb347; color: #ffd9a0; }
.peek-role.shade { border-color: #9b7bff; color: #d9ccff; }

/* ---------- Harbor map ---------- */
.harbor { margin: 16px 0 12px; }
.map-wrap { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); line-height: 0; }
.harbor-map { width: 100%; height: auto; display: block; }
.harbor-map .land { fill: #1a2233; }
.harbor-map .shore { fill: none; stroke: #2c3a55; stroke-width: 3; }
.harbor-map .waves path { fill: none; stroke: #1f3a58; stroke-width: 1.5; stroke-linecap: round; }
.harbor-map .path { stroke: #3a4560; stroke-width: 3; stroke-dasharray: 2 6; stroke-linecap: round; }
.harbor-map .path.live { stroke: var(--flame); opacity: .75; }

.harbor-map .place .halo { fill: transparent; }
.harbor-map .place .disc { fill: #232c42; stroke: #3a4560; stroke-width: 1.5; }
.harbor-map .place .icon { fill: none; stroke: #8a93a6; stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.harbor-map .place .icon .cut { stroke-width: 1; opacity: .7; }
.harbor-map .place .label { fill: var(--muted); font-size: 11px; text-anchor: middle; font-family: Georgia, serif; }
.harbor-map .place { opacity: .55; transition: opacity .2s; }

.harbor-map .place.here { opacity: 1; }
.harbor-map .place.here .disc { fill: #2e2a22; stroke: none; }
.harbor-map .place.here .icon { stroke: #ffe2b0; }
.harbor-map .place.here .label { fill: var(--ink); font-weight: 600; }
.harbor-map .place.here .ring { fill: none; stroke-width: 2.5; animation: breathe 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

.harbor-map .place.next { opacity: 1; cursor: pointer; }
.harbor-map .place.next .halo { fill: var(--flame); opacity: .14; animation: beckon 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.harbor-map .place.next .disc { stroke: var(--flame); }
.harbor-map .place.next .label { fill: var(--ink); }
.harbor-map .place.next:hover .disc, .harbor-map .place.next:focus .disc { fill: #2b3550; }
.harbor-map .place.next:focus { outline: none; }
.harbor-map .place.next:focus-visible .halo { opacity: .4; }
.harbor-map .place.next.wait { cursor: progress; }
.harbor-map .place.next.wait .halo { animation: none; opacity: .05; }

@keyframes breathe { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.12); opacity: .6; } }
@keyframes beckon { 0%, 100% { transform: scale(.9); } 50% { transform: scale(1.1); } }

.move-hint { margin: 8px 0 0; }

/* ---------- Where you are ---------- */
.here { gap: 6px; }
.here-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.here h3 { margin: 0; font-size: 1.3rem; }
.here h3.arrive { animation: rise .5s ease-out both; }
.here .eyebrow { margin-top: 6px; }
.walking { font-size: .8rem; color: var(--flame); font-style: italic; }
.here-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.here-list li { display: flex; align-items: center; gap: 6px; }
.here-list li.alone { color: var(--muted); font-style: italic; }
.here-list .keeper-svg { flex: none; }

/* ---------- Harbor lights (team progress) ---------- */
.lights { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.lights-bar { flex: 1; height: 10px; background: #1a2030; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lights-bar span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #b8742a, #ffb347 60%, #ffe2a8);
  box-shadow: 0 0 12px #ffb34799;
  transition: width .8s ease;
}
.lights span.small { color: var(--muted); white-space: nowrap; }

.harbor-map .task-pin circle { fill: #ffb347; stroke: #0e1220; stroke-width: 1.5; }
.harbor-map .task-pin path { fill: none; stroke: #0e1220; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
body.is-shade .harbor-map .task-pin circle { fill: #9b7bff; }

/* ---------- Task list ---------- */
.task-card { margin-top: 12px; gap: 6px; }
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.task-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--fog); border: 1px solid transparent; }
.task-list li.here { border-color: var(--flame); }
.task-list li.done { opacity: .55; text-decoration: line-through; text-decoration-color: #ffffff55; }
.task-list li.fake-note { background: none; padding: 4px 0 0; display: block; text-decoration: none; opacity: 1; }
#task-here { margin: 4px 0 2px; }

/* ---------- Mini-game window ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(5, 7, 14, .78);
  display: grid; place-items: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.modal-card {
  width: min(440px, 100%);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }
.small-btn { padding: 6px 14px; font-size: .85rem; }
.task-stage { display: grid; gap: 14px; justify-items: center; }
.task-status { text-align: center; min-height: 1.4em; margin: 12px 0 0; }
button.big { font-size: 1.3rem; padding: 16px; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* Light the great lamp */
.timing-track { position: relative; width: 100%; height: 46px; border-radius: 10px; background: #0b0f1a; border: 1px solid var(--line); overflow: hidden; touch-action: manipulation; }
.timing-zone { position: absolute; top: 0; bottom: 0; background: #ffb34733; border-left: 2px solid #ffb347; border-right: 2px solid #ffb347; }
.timing-spark { position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: #fff3d0; box-shadow: 0 0 14px 4px #ffb347; }
.timing-track.hit { box-shadow: 0 0 0 2px #ffb347, 0 0 30px #ffb34788; }
.task-stage.lit .timing-track { background: #3a2a12; }

/* Light the candles */
.candles { display: flex; gap: 8px; justify-content: center; }
.candle { padding: 6px 4px; border-radius: 10px; background: #0b0f1a; width: 52px; }
.candle svg { width: 32px; height: 74px; display: block; margin: auto; }
.candle .c-wax { fill: #e9e2cf; }
.candle .c-flame { fill: #3a3f4b; transition: fill .15s; }
.candle.on .c-flame { fill: #ffb347; filter: drop-shadow(0 0 6px #ffb347); }

/* Signal flags */
.flag-target { text-align: center; }
.flag-target svg { width: 120px; display: block; margin: 6px auto 0; border-radius: 3px; }
.flag-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; }
.flag-option { padding: 10px; border-radius: 10px; }
.flag-option svg { width: 100%; max-width: 110px; display: block; margin: auto; border-radius: 2px; }
.flag-option.right { border-color: #ffb347; box-shadow: 0 0 0 2px #ffb347; }

/* Mend the net */
.net { width: 100%; max-width: 320px; background: #0b0f1a; border-radius: 10px; touch-action: none; }
.net .net-grid { stroke: #2a3350; stroke-width: .5; }
.net .net-line { fill: none; stroke: #ffb347; stroke-width: 1.4; stroke-linejoin: round; }
.net .knot { cursor: pointer; }
.net .knot circle { fill: #232c42; stroke: #8a93a6; stroke-width: 1; }
.net .knot text { fill: var(--ink); font-size: 6.5px; text-anchor: middle; font-family: ui-sans-serif, system-ui, sans-serif; pointer-events: none; }
.net .knot.tied circle { fill: #ffb347; stroke: #ffe2a8; }
.net .knot.tied text { fill: #0e1220; }

/* Haul in the rope */
.rope-meter { width: 100%; height: 18px; border-radius: 999px; background: repeating-linear-gradient(45deg, #2b2416 0 6px, #3a301c 6px 12px); border: 1px solid var(--line); overflow: hidden; }
.rope-meter span { display: block; height: 100%; width: 0; background: repeating-linear-gradient(45deg, #c99a52 0 6px, #e8bd72 6px 12px); transition: width .12s; }
.tug { animation: tug .15s; }
@keyframes tug { 50% { transform: translateY(3px) scale(.98); } }

/* Wind the clock */
.crank { width: 170px; height: 170px; padding: 8px; border-radius: 50%; background: #0b0f1a; touch-action: none; user-select: none; -webkit-user-select: none; }
.crank svg { width: 100%; height: 100%; }
.crank .crank-track { fill: none; stroke: #2a3350; stroke-width: 8; }
.crank .crank-fill { fill: none; stroke: #ffb347; stroke-width: 8; stroke-dasharray: 100; stroke-dashoffset: 100; transform: rotate(-90deg); transform-origin: 50% 50%; stroke-linecap: round; }
.crank .crank-arm { fill: #8a93a6; transform-origin: 50px 50px; }
.crank .crank-hub { fill: #e7e2d6; }

/* ---------- Game over ---------- */
.over { text-align: center; padding-top: 56px; }
.over h1 { color: #ffd59a; }
.over.shade h1 { color: #c9b6ff; }
.over .allies-list { margin: 10px 0 28px; }

.toast.witness { border-color: #ffd84d; background: #2e2716; }
.toast.danger { border-color: #ff6b5b; background: #3a1616; color: #ffd9d4; }

/* ---------- Goal, hints and actions ---------- */
.goal {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--flame);
  background: linear-gradient(90deg, #ffffff08, transparent);
  font-size: .95rem;
}
.hint { margin: 0; font-style: italic; color: #d8cdb5; }
body.is-shade .hint { color: #d3c6ff; }
.actions { display: grid; gap: 8px; }
.actions:empty { display: none; }
button.report {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #c9923e; color: #1b1206; border: 0; font-weight: 700;
  animation: urge 1.6s ease-in-out infinite;
}
button.report .bell-svg { flex: none; }
button.report .bell-waves { display: none; }
button.snuff { background: #2a1838; border-color: #7b4dff; color: #e3d8ff; font-weight: 600; }
button.snuff:not(:disabled):hover { background: #3a2050; }
@keyframes urge { 0%, 100% { box-shadow: 0 0 0 0 #c9923e66; } 50% { box-shadow: 0 0 0 8px #c9923e00; } }

.cold-here { display: grid; gap: 6px; padding: 10px; border-radius: 10px; background: #0f1a28; border: 1px solid #2c4560; }
.cold-row { display: flex; align-items: center; gap: 10px; color: #cfe2f5; }
.cold-svg .frost { animation: twinkle 2.8s ease-in-out infinite; }
.cold-svg .breath { animation: drift 3.2s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .85; } 50% { opacity: .35; } }

/* ---------- Wisps ---------- */
.wisp-banner {
  display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px 14px;
  border-radius: var(--radius); background: #12223a; border: 1px solid #36557c; color: #d6e7fb;
}
.wisp-banner p { margin: 0; font-size: .92rem; }
.wisp-svg { animation: hover 3s ease-in-out infinite; }
@keyframes hover { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
body.is-wisp .harbor-map { filter: saturate(.35) brightness(1.15) hue-rotate(-10deg); }
body.is-wisp .goal { border-left-color: #9fc3e8; }
.here-list li.is-wisp { color: #bcd6f2; font-style: italic; }

/* ---------- Seeing a snuff ---------- */
body.flash::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 30;
  background: radial-gradient(circle, transparent 30%, #5b1010aa);
  animation: flash .9s ease-out forwards;
}
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* ---------- Your lantern goes out ---------- */
.snuffed-overlay {
  position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, #0b1524ee, #04070dfa);
  animation: fadein .8s ease-out both;
}
.snuffed-card { text-align: center; max-width: 360px; display: grid; justify-items: center; gap: 6px; }
.snuffed-card h2 { color: #cfe2f5; font-size: 1.6rem; margin: 6px 0 0; }
.snuffed-card p { color: #a9bfd6; }
.snuffed-card .cold-svg { animation: sink 1.4s ease-out both; }
@keyframes sink { from { transform: translateY(-14px) rotate(8deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- The bell ---------- */
.meeting { text-align: center; padding-top: 40px; }
.bell-art { display: flex; justify-content: center; }
.bell-svg .bell-swing { transform-origin: 60px 22px; animation: swing 1.1s ease-in-out 3; }
.bell-svg .bell-waves { animation: ring 1.1s ease-out 3; opacity: 0; }
@keyframes swing { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(14deg); } 75% { transform: rotate(-14deg); } }
@keyframes ring { 0% { opacity: .9; } 100% { opacity: 0; } }
.meeting h1 { font-size: 1.8rem; color: #ffd59a; }
.cold-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 18px; }
.cold-list li { display: grid; justify-items: center; gap: 2px; color: #cfe2f5; }
.meeting .countdown span { background: #c9923e; }

/* ---------- How to play ---------- */
.howto-card { max-height: calc(100vh - 32px); overflow-y: auto; }
.howto-steps { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 14px; counter-reset: step; }
.howto-steps li { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; font-size: .95rem; }
.howto-art { display: grid; place-items: center; width: 52px; height: 58px; border-radius: 12px; background: var(--fog); }
#howto-open { margin-top: 14px; }

.roster { margin-top: 16px; }
.roster summary { cursor: pointer; color: var(--muted); padding: 6px 0; }

.players.compact { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.players.compact .player { min-height: 0; padding: 8px 6px; }
.tag-shade { color: #c9b6ff !important; border-color: #6a4fc9 !important; }

/* ---------- Banner & toast ---------- */
.banner {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #3a2a18;
  color: var(--flame);
  text-align: center;
  padding: 8px 16px;
  font-size: .9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--panel-2);
  border: 1px solid var(--flame);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

@media (max-width: 420px) {
  .players { grid-template-columns: repeat(2, 1fr); }
  .host-controls { grid-template-columns: 1fr; }
  h1 { font-size: 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .keeper-svg .flame, .shade-svg .smoke, .reveal h1, .reveal-text,
  .harbor-map .place .ring, .harbor-map .place .halo, .here h3.arrive, .shake, .tug,
  button.report, .cold-svg .frost, .cold-svg .breath, .wisp-svg, body.flash::after,
  .snuffed-overlay, .snuffed-card .cold-svg, .bell-svg .bell-swing, .bell-svg .bell-waves { animation: none; }
}
