:root {
  --night: #13202e;
  --night-2: #1b2d40;
  --night-3: #243a52;
  --sea: #2d5f7c;
  --parchment: #f1e2bf;
  --parchment-2: #e6d2a3;
  --ink: #2a1c17;
  --ink-soft: #5b4636;
  --brass: #c9a24a;
  --brass-hi: #e6c46f;
  --foam: #e9eef2;
  --muted: #9fb0c2;
  --good: #6fae7f;
  --bad: #d77a5c;
  --radius: 10px;
  --head: 'Pirata One', Georgia, serif;
  --body: 'Alegreya', Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(ellipse at top, var(--night-3), var(--night) 70%) fixed, var(--night);
  color: var(--foam);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: var(--brass-hi); }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px;
  background: rgba(19, 32, 46, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(201, 162, 74, 0.25);
}
.brand { font-family: var(--head); font-size: 28px; color: var(--brass-hi); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar nav { display: flex; gap: 4px; }
.bar nav a, .bar nav button {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  background: none; border: 1px solid transparent; color: var(--foam);
  text-decoration: none; cursor: pointer; font-size: 16px;
}
.bar nav a:hover, .bar nav button:hover { border-color: rgba(201, 162, 74, 0.4); }
.bar nav a.active { background: var(--night-3); border-color: rgba(201, 162, 74, 0.5); }
.bar .ico { font-size: 18px; }
@media (max-width: 720px) {
  .bar { padding: 6px 10px; }
  .brand { font-size: 22px; }
  .bar .lbl { display: none; }
  .bar nav a, .bar nav button { padding: 8px; }
}

main { max-width: 1280px; margin: 0 auto; padding: 16px; }

/* ---------- buttons and forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 8px; cursor: pointer;
  background: var(--brass); color: var(--ink); border: 1px solid #7c6226;
  font-weight: 700; text-decoration: none;
}
.btn:hover { background: var(--brass-hi); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; font-weight: 600; }
.btn.small { padding: 6px 12px; font-size: 15px; }
input[type=text], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #b79a64; background: #fffaf0; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
.err { color: var(--bad); min-height: 1.5em; margin: 8px 0 0; }
.muted { color: var(--muted); }

/* ---------- parchment card (login, docs, puzzles) ---------- */
.parchment {
  background: linear-gradient(180deg, var(--parchment), var(--parchment-2));
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 0 60px rgba(120, 80, 30, 0.18);
  padding: 28px;
}
.parchment h1, .parchment h2 { font-family: var(--head); font-weight: 400; margin: 0 0 8px; color: var(--ink); }
.parchment h1 { font-size: 40px; }
.parchment h2 { font-size: 30px; }
.parchment .muted { color: var(--ink-soft); }
.gate { max-width: 440px; margin: 8vh auto; }
.gate .btn { width: 100%; margin-top: 18px; }

/* ---------- scene ---------- */
.scene-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.scene-head h1 { font-family: var(--head); font-weight: 400; font-size: 34px; margin: 0; color: var(--brass-hi); }
.scene-head .where { color: var(--muted); font-size: 16px; }
.scene-tools { display: flex; gap: 8px; }
.scene {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(201, 162, 74, 0.35);
  background: #000;
  touch-action: manipulation;
}
.scene svg { display: block; width: 100%; height: auto; }
#scene { aspect-ratio: 16 / 9; background: #0b1016; width: min(100%, calc((100dvh - 190px) * 16 / 9)); margin: 0 auto; }
#scene .plane { position: absolute; inset: 0; will-change: transform; transform: scale(1.045); pointer-events: none; }
#scene .layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#scene .layer .spot { pointer-events: all; }
.fx { position: absolute; inset: 0; pointer-events: none; }
.fx-rain { width: 100%; height: 100%; }
.fx-vignette { background: radial-gradient(ellipse at 50% 45%, transparent 50%, rgba(3, 6, 10, 0.85) 100%); }
.fx-grain {
  inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.6 -0.3'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
  animation: grain 0.9s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 17% { transform: translate(-7%, 4%); } 33% { transform: translate(5%, -6%); }
  50% { transform: translate(-3%, 8%); } 67% { transform: translate(8%, 2%); } 83% { transform: translate(-6%, -4%); }
}

/* Layer animations, applied to a whole layer so the browser can move it cheaply. */
.anim-bob { animation: bob 6s ease-in-out infinite; }
.anim-bob-slow { animation: bob 9s ease-in-out infinite reverse; }
.anim-drift { animation: drift 48s ease-in-out infinite alternate; }
.anim-drift-back { animation: drift 64s ease-in-out infinite alternate-reverse; }
.anim-glide { animation: glide 14s ease-in-out infinite; }
.anim-flicker { animation: flicker 4s linear infinite; }
.anim-sweep { animation: sweep 9s ease-in-out infinite alternate; }
.anim-pulse { animation: pulse 2.6s ease-in-out infinite; }
.anim-sway { animation: sway 7s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(0.7%); } }
@keyframes drift { from { transform: translateX(-4%); } to { transform: translateX(4%); } }
@keyframes glide { 0%, 100% { transform: translate(0, 0); } 33% { transform: translate(1.2%, -1%); } 66% { transform: translate(-0.8%, 0.6%); } }
@keyframes flicker {
  0%, 100% { opacity: 1; } 8% { opacity: .82; } 12% { opacity: .96; } 30% { opacity: .88; } 34% { opacity: 1; }
  61% { opacity: .9; } 64% { opacity: .75; } 67% { opacity: .97; } 85% { opacity: .9; }
}
@keyframes sweep { from { transform: rotate(-24deg); opacity: .55; } 50% { opacity: .9; } to { transform: rotate(22deg); opacity: .55; } }
@keyframes pulse { 0%, 100% { transform: scale(.55); opacity: .35; } 50% { transform: scale(1.15); opacity: 1; } }
@keyframes sway { 0%, 100% { transform: rotate(-1.2deg); } 50% { transform: rotate(1.4deg); } }
.spot { fill: transparent; stroke: transparent; cursor: pointer; transition: fill .15s, stroke .15s; }
.spot:hover, .spot:focus-visible { fill: rgba(255, 230, 160, 0.12); stroke: rgba(255, 230, 160, 0.7); stroke-width: 4; stroke-dasharray: 14 10; outline: none; }
.scene.reveal .spot { fill: rgba(255, 230, 160, 0.14); stroke: rgba(255, 230, 160, 0.85); stroke-width: 4; stroke-dasharray: 14 10; }
.spot.kind-exit { cursor: e-resize; }
.caption {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  max-width: calc(100% - 24px);
  background: rgba(19, 32, 46, 0.85); color: var(--foam);
  padding: 6px 14px; border-radius: 20px; font-size: 16px;
  pointer-events: none; opacity: 0; transition: opacity .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.caption.show { opacity: 1; }
.narration {
  margin-top: 12px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--night-2); border-left: 4px solid var(--brass);
  font-style: italic; min-height: 1em;
}
.narration:empty { display: none; }

/* ---------- map ---------- */
.map { position: relative; }
.pin {
  position: absolute; transform: translate(-50%, -100%);
  display: flex; flex-direction: column; align-items: center;
  background: none; border: 0; cursor: pointer; color: var(--foam); padding: 0;
}
.pin .dot {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--brass); border: 3px solid var(--ink); box-shadow: 0 4px 10px rgba(0,0,0,.5);
}
.pin .name {
  margin-top: 6px; background: rgba(19, 32, 46, 0.88); padding: 3px 10px; border-radius: 12px;
  font-family: var(--head); font-size: 20px; white-space: nowrap;
}
.pin.locked .dot { background: #6b7280; }
.pin.locked .name { color: var(--muted); }
.pin:hover .dot { background: var(--brass-hi); }
@media (max-width: 720px) { .pin .name { font-size: 15px; } .pin .dot { width: 22px; height: 22px; } }
.loc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 16px; }
.loc-card { background: var(--night-2); border: 1px solid rgba(201,162,74,.25); border-radius: var(--radius); padding: 14px; text-align: left; color: inherit; cursor: pointer; }
.loc-card h3 { font-family: var(--head); font-weight: 400; font-size: 24px; margin: 0; color: var(--brass-hi); }
.loc-card.locked { opacity: .6; cursor: default; }
.loc-card p { margin: 4px 0 0; font-size: 16px; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: min(420px, 100vw);
  background: var(--night-2); border-left: 1px solid rgba(201,162,74,.35);
  box-shadow: -10px 0 40px rgba(0,0,0,.5);
  padding: 16px; overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { font-family: var(--head); font-weight: 400; font-size: 30px; margin: 0; color: var(--brass-hi); }
.x { background: none; border: 0; color: inherit; font-size: 32px; line-height: 1; cursor: pointer; padding: 4px 8px; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 12px; }
.item {
  background: var(--night-3); border: 1px solid rgba(201,162,74,.3); border-radius: var(--radius);
  padding: 10px; text-align: center; cursor: pointer; color: inherit;
}
.item svg { width: 56px; height: 56px; display: block; margin: 0 auto 6px; }
.item.selected { border-color: var(--brass-hi); background: #37506b; }
.list { list-style: none; padding: 0; margin: 12px 0 0; }
.list li { margin: 0 0 8px; }
.list button {
  width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer;
  background: var(--night-3); border: 1px solid rgba(201,162,74,.25); color: inherit;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.tag { font-size: 13px; padding: 2px 8px; border-radius: 10px; background: var(--sea); white-space: nowrap; }
.tag.private { background: #4b5563; }

/* ---------- modal ---------- */
dialog {
  border: 0; padding: 0; background: transparent; color: inherit;
  width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgba(5, 10, 18, 0.7); }
#modalBody { max-height: calc(100dvh - 32px); overflow-y: auto; }
.doc .close-row { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.doc .art svg { width: 100%; height: auto; display: block; border-radius: 6px; margin: 8px 0; }
.doc .body { font-size: 19px; }
.doc .body .big { font-family: var(--head); font-size: 44px; letter-spacing: .2em; text-align: center; margin: 10px 0; }
.doc.style-map { background: linear-gradient(180deg, #efe0bb, #d9c28c); }
.doc .from { font-size: 15px; color: var(--ink-soft); margin: 0 0 8px; }
.puzzle form { margin-top: 14px; }
.puzzle .code { font-family: var(--head); font-size: 34px; letter-spacing: .4em; text-align: center; }
.puzzle .solved { background: rgba(111, 174, 127, .2); border: 1px solid var(--good); border-radius: 8px; padding: 12px; margin-top: 14px; }
.puzzle .result.bad { color: #9b3a22; }
.hints { margin-top: 20px; border-top: 1px dashed #b79a64; padding-top: 12px; }
.hints h3 { margin: 0 0 6px; font-size: 18px; }
.hints ol { margin: 0 0 10px; padding-left: 22px; }
.hints .vote { font-size: 15px; color: var(--ink-soft); margin: 6px 0; }
.pick-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 10px; }
.pick-items button { background: #fffaf0; border: 1px solid #b79a64; border-radius: 8px; padding: 8px; cursor: pointer; color: var(--ink); }
.pick-items svg { width: 44px; height: 44px; display: block; margin: 0 auto 4px; background: var(--night-2); border-radius: 6px; padding: 4px; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
@media (max-width: 900px) { .board { grid-template-columns: 1fr; } }
.board h2 { font-family: var(--head); font-weight: 400; font-size: 30px; margin: 0 0 8px; color: var(--brass-hi); }
.cork {
  background: #5b3b22 radial-gradient(circle at 20% 20%, rgba(255,255,255,.06) 0 2px, transparent 3px) 0 0/18px 18px;
  border-radius: var(--radius); padding: 14px; border: 6px solid #3b2413;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; min-height: 120px;
}
.card {
  background: var(--parchment); color: var(--ink); border-radius: 4px; padding: 10px 12px 12px;
  box-shadow: 0 6px 12px rgba(0,0,0,.35); cursor: pointer; text-align: left; border: 0; position: relative;
}
.card:nth-child(3n) { transform: rotate(-1.2deg); }
.card:nth-child(3n+1) { transform: rotate(0.8deg); }
.card::before { content: ''; position: absolute; top: -6px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #b23a2a; box-shadow: 0 2px 3px rgba(0,0,0,.4); }
.card strong { display: block; font-size: 17px; }
.card small { color: var(--ink-soft); }
.empty { color: var(--muted); font-style: italic; }
.notes { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.note { background: var(--night-2); border-radius: 8px; padding: 10px 12px; border-left: 3px solid var(--sea); }
.note .meta { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.note .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.note .del { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
.note .link { background: none; border: 0; color: var(--brass-hi); cursor: pointer; padding: 0; text-decoration: underline; font-size: 15px; }
.log { list-style: none; padding: 0; margin: 0; font-size: 16px; }
.log li { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.log time { color: var(--muted); font-size: 13px; display: block; }
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer .btn { align-self: flex-end; }

/* ---------- admin ---------- */
table.crew { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 16px; }
table.crew th, table.crew td { text-align: left; padding: 8px; border-bottom: 1px solid rgba(255,255,255,.1); }
.crew-wrap { overflow-x: auto; }
.invite-box { background: var(--night-2); border: 1px dashed var(--brass); border-radius: 8px; padding: 12px; margin-top: 12px; overflow-wrap: anywhere; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > div { flex: 1 1 160px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--brass); color: var(--ink); padding: 10px 18px; border-radius: 20px; font-weight: 700;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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

/* ---------- map pins ride on a parallax plane ---------- */
#scene .pin { pointer-events: auto; }

/* ---------- talking to characters ---------- */
.talk-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.talk-head h2 { margin: 0; }
.portrait { width: 72px; height: 72px; flex: 0 0 72px; border-radius: 50%; overflow: hidden; background: #1b2d40; border: 3px solid #7c6226; }
.portrait svg { width: 100%; height: 100%; display: block; }
.chat {
  max-height: min(46dvh, 420px); overflow-y: auto; padding: 10px; border-radius: 8px;
  background: rgba(60, 40, 20, 0.08); border: 1px solid #b79a64; display: flex; flex-direction: column; gap: 8px;
}
.line { max-width: 85%; padding: 8px 12px; border-radius: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.line.them { align-self: flex-start; background: #fffaf0; border: 1px solid #d8c49a; }
.line.me { align-self: flex-end; background: #2d5f7c; color: #f4f1e8; }
.line.waiting { color: var(--ink-soft); font-style: italic; }
.talk-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.talk-form textarea { min-height: 48px; }
.talk-form .btn { flex: 0 0 auto; }
.small { font-size: 15px; margin: 6px 0 0; }
