:root {
  --parch: #f4e7c9;
  --parch-dim: #d9c7a0;
  --umber: #23160d;
  --umber-2: #3a2617;
  --ochre: #d39a4c;
  --gold: #f1c77a;
  --teal: #5fe0cf;
  --red: #ff7a52;
  --panel: rgba(30, 19, 11, 0.62);
  --line: rgba(241, 199, 122, 0.45);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--umber);
  color: var(--parch);
  font-family: var(--serif);
  user-select: none;
  -webkit-user-select: none;
}
canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: none; }
.hidden { display: none !important; }

/* ---------- panels ---------- */
.panel {
  background: linear-gradient(180deg, rgba(48, 31, 18, 0.72), rgba(24, 15, 9, 0.7));
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 0 0 3px rgba(0, 0, 0, 0.18), inset 0 0 0 4px rgba(241, 199, 122, 0.12);
  backdrop-filter: blur(6px) saturate(1.2);
  -webkit-backdrop-filter: blur(6px) saturate(1.2);
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px);
}

.btn {
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--parch);
  background: linear-gradient(180deg, rgba(70, 45, 25, 0.85), rgba(35, 22, 13, 0.9));
  border: 1px solid var(--line);
  padding: 12px 26px;
  cursor: pointer;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 8px 100%, 0 50%);
  transition: transform 0.15s, background 0.2s, color 0.2s;
}
.btn small { font-family: var(--serif); font-style: italic; letter-spacing: 0.02em; opacity: 0.7; margin-left: 6px; text-transform: none; }
.btn:hover { background: linear-gradient(180deg, rgba(120, 78, 38, 0.95), rgba(60, 37, 20, 0.95)); color: #fff6dd; transform: translateY(-1px); }
.btn.primary { background: linear-gradient(180deg, #c98c3e, #8a5520); color: #fff4d8; border-color: #ffd88f; }
.btn.primary:hover { background: linear-gradient(180deg, #e0a14f, #9d6226); }
.btn.small { font-size: 11px; padding: 7px 16px; }

kbd {
  font-family: var(--display); font-size: 11px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  padding: 1px 6px; border-radius: 3px;
  background: rgba(255, 230, 180, 0.06);
  color: var(--gold);
}

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #3b2717 0%, #170f09 70%);
  z-index: 50; gap: 14px;
}
.load-title { font-family: var(--display); font-size: 34px; letter-spacing: 0.2em; color: var(--gold); text-transform: uppercase; }
.load-sub { font-style: italic; font-size: 19px; opacity: 0.8; }
.bar { width: 260px; height: 3px; background: rgba(241, 199, 122, 0.15); }
#loadBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--ochre), var(--gold)); transition: width 0.2s; }
.glyph-ring {
  width: 70px; height: 70px; border-radius: 50%;
  border: 2px dashed rgba(241, 199, 122, 0.6);
  animation: spin 8s linear infinite;
  margin-bottom: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- title ---------- */
#title {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 55%, rgba(20, 12, 6, 0) 0%, rgba(20, 12, 6, 0.25) 55%, rgba(15, 9, 5, 0.75) 100%);
  animation: fadein 2.5s ease;
}
.title-inner { text-align: center; }
#title h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(44px, 7vw, 96px);
  letter-spacing: 0.14em; margin: 0;
  color: #fff3d6;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(90, 50, 20, 0.6), 0 0 40px rgba(255, 190, 110, 0.45), 0 10px 40px rgba(0, 0, 0, 0.5);
  line-height: 1;
}
#title h1 span {
  display: block; font-family: var(--serif); font-style: italic; font-weight: 500;
  text-transform: none; letter-spacing: 0.05em;
  font-size: 0.42em; color: var(--gold); margin: 6px 0;
}
.tag { font-size: 22px; font-style: italic; margin: 22px 0 34px; color: #fbeccc; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.menu { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.credit { margin-top: 38px; font-size: 15px; opacity: 0.75; letter-spacing: 0.05em; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); }
.ornament {
  width: 220px; height: 26px; margin: 0 auto 18px;
  background:
    radial-gradient(circle at 50% 50%, var(--gold) 0 4px, transparent 5px),
    linear-gradient(90deg, transparent, var(--gold) 30%, transparent 46%, transparent 54%, var(--gold) 70%, transparent) center/100% 1px no-repeat;
  opacity: 0.85;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud .btn, #hud button, .marker .go { pointer-events: auto; }

#objectives { position: absolute; z-index: 2; top: 16px; left: 16px; padding: 14px 20px 14px 18px; min-width: 260px; }
.lvl { font-family: var(--display); font-size: 13px; letter-spacing: 0.18em; color: var(--gold); text-transform: uppercase; margin-bottom: 8px; }
#objList { list-style: none; padding: 0; margin: 0; font-size: 17px; }
#objList li { display: flex; align-items: center; gap: 10px; padding: 3px 0; opacity: 0.75; }
#objList li.done { opacity: 1; color: var(--teal); }
#objList li svg { width: 18px; height: 18px; flex: none; }
#objList li .st { margin-left: auto; font-size: 13px; font-style: italic; opacity: 0.8; }
#popline { margin-top: 8px; font-size: 14px; font-style: italic; opacity: 0.75; border-top: 1px solid rgba(241, 199, 122, 0.2); padding-top: 6px; }

#warn {
  position: absolute; top: 18px; right: 18px;
  font-family: var(--display); letter-spacing: 0.12em; font-size: 14px;
  padding: 10px 18px; color: #ffd2b8;
  background: linear-gradient(180deg, rgba(120, 30, 10, 0.75), rgba(60, 14, 6, 0.75));
  border: 1px solid rgba(255, 140, 90, 0.6);
  clip-path: polygon(8px 0, 100% 0, 100% 100%, 8px 100%, 0 50%);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { filter: brightness(1.35); } }
#sandboxBar { position: absolute; top: 16px; right: 16px; display: flex; gap: 8px; }
#warn:not(.hidden) ~ #sandboxBar { top: 64px; }

#messages {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%);
  width: min(660px, 70vw); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.msg {
  font-size: 21px; line-height: 1.3; text-align: center;
  padding: 10px 26px; color: #fff5dc;
  background: linear-gradient(90deg, transparent, rgba(30, 18, 9, 0.72) 15%, rgba(30, 18, 9, 0.72) 85%, transparent);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  animation: msgIn 0.6s ease both;
  transition: opacity 1.2s, transform 1.2s;
}
.msg.good { color: #b9fff1; }
.msg.bad { color: #ffc0a4; }
.msg.warn { color: #ffe08a; }
.msg.hint { color: #f8e7c0; font-style: italic; }
.msg.out { opacity: 0; transform: translateY(-8px); }
@keyframes msgIn { from { opacity: 0; transform: translateY(-10px); letter-spacing: 0.06em; } }

#breathGauge {
  position: absolute; z-index: 2; left: 18px; bottom: 18px; width: 150px; height: 150px;
  display: flex; align-items: center; justify-content: center;
  clip-path: none; border-radius: 50%;
}
#breathGauge svg { position: absolute; inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px); transform: rotate(-90deg); }
#breathGauge .track { fill: none; stroke: rgba(241, 199, 122, 0.15); stroke-width: 7; }
#breathGauge .fill { fill: none; stroke: var(--gold); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 314; stroke-dashoffset: 314; transition: stroke 0.3s; filter: drop-shadow(0 0 6px currentColor); }
#breathGauge .ticks line { stroke: rgba(241, 199, 122, 0.35); stroke-width: 1.2; }
.gauge-label { position: relative; text-align: center; line-height: 1.1; }
.gauge-label span { display: block; font-family: var(--display); font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); }
.gauge-label b { font-weight: 500; font-style: italic; font-size: 16px; opacity: 0.85; }

#powers { position: absolute; z-index: 2; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; }
.power {
  pointer-events: auto; cursor: pointer;
  position: relative; width: 74px; height: 86px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 8px;
  background: linear-gradient(180deg, rgba(48, 31, 18, 0.78), rgba(24, 15, 9, 0.78));
  border: 1px solid var(--line);
  clip-path: polygon(50% 0, 100% 14%, 100% 86%, 50% 100%, 0 86%, 0 14%);
  color: var(--gold);
  transition: transform 0.15s, filter 0.2s;
}
.power svg { width: 42px; height: 42px; }
.power .k { font-family: var(--display); font-size: 11px; opacity: 0.8; margin-top: 2px; }
.power .cd { position: absolute; inset: 0; background: conic-gradient(rgba(0, 0, 0, 0.6) var(--p, 0%), transparent 0); pointer-events: none; }
.power.locked { color: rgba(241, 199, 122, 0.25); cursor: default; }
.power.locked .k::after { content: ' · ?'; }
.power.ready:hover { transform: translateY(-3px); filter: brightness(1.3); }
.power.active { color: var(--teal); filter: drop-shadow(0 0 8px var(--teal)); animation: pulse 1s infinite; }
.power-wrap .tip {
  position: absolute; bottom: 96px; left: 50%; transform: translateX(-50%);
  width: 220px; padding: 8px 12px; font-size: 15px; text-align: center; color: var(--parch);
  background: rgba(24, 15, 9, 0.9); border: 1px solid var(--line);
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.power-wrap { position: relative; }
.power-wrap:hover .tip { opacity: 1; }
.tip b { font-family: var(--display); font-weight: 500; letter-spacing: 0.08em; font-size: 13px; color: var(--gold); display: block; }

#keys { position: absolute; right: 18px; bottom: 14px; font-size: 14px; font-style: italic; opacity: 0.6; text-shadow: 0 1px 4px #000; }

/* ---------- markers ---------- */
#markers { position: absolute; inset: 0; overflow: hidden; z-index: 0; }
.marker {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -100%);
  display: flex; flex-direction: column; align-items: center;
  color: var(--parch); text-align: center; white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  transition: opacity 0.3s;
  will-change: transform;
}
.marker .badge {
  display: flex; align-items: center; gap: 7px;
  font-size: 15px; padding: 4px 12px 4px 8px;
  background: rgba(30, 19, 11, 0.66);
  border: 1px solid var(--line);
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 6px 100%, 0 50%);
}
.marker svg { width: 18px; height: 18px; color: var(--gold); }
.marker .pin { width: 1px; height: 26px; background: linear-gradient(var(--line), transparent); }
.marker.claimed .badge { border-color: rgba(95, 224, 207, 0.6); }
.marker.claimed svg { color: var(--teal); }
.marker.walk .badge { font-size: 13px; }
.marker.blocked .badge { border-color: rgba(255, 140, 90, 0.7); color: #ffd2b8; }
.marker .go {
  margin-top: 4px;
  font-family: var(--display); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: #fff4d8; background: linear-gradient(180deg, #c98c3e, #8a5520); border: 1px solid #ffd88f;
  padding: 5px 12px; cursor: pointer;
  clip-path: polygon(6px 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 6px 100%, 0 50%);
}
.marker .go:hover { filter: brightness(1.2); }
.marker .sub { font-size: 12px; font-style: italic; opacity: 0.8; }

/* ---------- overlays ---------- */
#help, #pause, #end {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 6, 3, 0.45);
  animation: fadein 0.3s;
}
.help-inner { padding: 30px 40px; max-width: 900px; text-align: center; }
.help-inner.small { max-width: 520px; }
.help-inner h2 { font-family: var(--display); letter-spacing: 0.16em; color: var(--gold); margin: 0 0 18px; font-weight: 500; text-transform: uppercase; }
.help-inner h3 { font-family: var(--display); font-size: 14px; letter-spacing: 0.18em; color: var(--gold); font-weight: 500; text-transform: uppercase; margin: 0 0 6px; }
.help-inner p { font-size: 18px; margin: 6px 0; line-height: 1.45; }
.cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; text-align: left; margin-bottom: 24px; }
#endText { font-size: 20px; margin-bottom: 22px; font-style: italic; }

#flash { position: fixed; inset: 0; pointer-events: none; z-index: 20; opacity: 0; background: radial-gradient(ellipse at center, transparent 30%, var(--flash, #fff) 140%); transition: opacity 1.2s; }

@media (max-width: 760px) {
  .cols { grid-template-columns: 1fr; }
  #objectives { transform: scale(0.85); transform-origin: top left; }
  #messages { width: 90vw; top: 150px; }
}
