:root {
  --ink: #1d1a17;
  --ink-soft: rgba(29, 26, 23, 0.84);
  --cream: #f3ead8;
  --cream-dim: #d8cfc0;
  --coral: #d97757;
  --coral-soft: #e8906c;
  --muted: #a89f91;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--serif);
  user-select: none;
}

canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

.hidden { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; }

#crosshair {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -52%);
  color: var(--cream);
  font-size: 22px;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
  opacity: 0.9;
  transition: color 0.15s, transform 0.15s;
}
#crosshair.active { color: var(--coral-soft); transform: translate(-50%, -52%) scale(1.2); }

#prompt {
  position: absolute; left: 50%; top: calc(50% + 26px);
  transform: translateX(-50%);
  font-family: var(--mono); font-size: 13px;
  color: var(--cream);
  background: var(--ink-soft);
  padding: 4px 10px; border-radius: 3px;
  opacity: 0; transition: opacity 0.15s;
}
#prompt.show { opacity: 1; }

#compass {
  position: absolute; top: 14px; left: 50%;
  width: 420px; height: 34px; transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, var(--ink-soft) 15%, var(--ink-soft) 85%, transparent);
  overflow: hidden;
  font-family: var(--mono);
}
#compass-track { position: absolute; inset: 0; }
.cardinal { position: absolute; top: 7px; font-size: 12px; color: var(--muted); transform: translateX(-50%); }
.cardinal.major { color: var(--cream); }
#compass-marker {
  position: absolute; top: 2px; left: 50%;
  transform: translateX(-50%);
  color: var(--coral); font-size: 14px;
  text-shadow: 0 0 6px rgba(217, 119, 87, 0.8);
}
#compass-marker.edge span { opacity: 0.6; }
#compass-label {
  position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--coral-soft); white-space: nowrap;
}

#context { position: absolute; top: 16px; right: 18px; width: 180px; font-family: var(--mono); font-size: 11px; }
.context-label { display: flex; justify-content: space-between; color: var(--cream-dim); margin-bottom: 4px; text-shadow: 0 1px 2px #000; }
.context-bar { height: 6px; background: rgba(29, 26, 23, 0.7); border: 1px solid rgba(243, 234, 216, 0.25); border-radius: 3px; overflow: hidden; }
#context-fill { height: 100%; width: 3%; background: linear-gradient(90deg, #c7b89f, var(--coral)); transition: width 1.2s ease; }
#context.full #context-fill { background: #f3ead8; }

#objectives {
  position: absolute; top: 16px; left: 18px; max-width: 360px;
  font-size: 15px; line-height: 1.35;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
#objectives .obj { padding: 2px 0 2px 20px; position: relative; color: var(--cream-dim); }
#objectives .obj::before { content: "·"; position: absolute; left: 6px; color: var(--muted); }
#objectives .obj.tracked { color: var(--cream); }
#objectives .obj.tracked::before { content: "✳"; left: 0; color: var(--coral); }
#objectives .obj.done { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(217, 119, 87, 0.6); }
#objectives .obj.done::before { content: "✓"; color: var(--coral-soft); left: 2px; }
#objectives .obj-head { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.08em; margin-bottom: 4px; }

#toasts { position: absolute; top: 90px; right: 18px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.toast {
  font-family: var(--mono); font-size: 12px;
  background: var(--ink-soft); color: var(--cream);
  padding: 6px 10px; border-left: 2px solid var(--coral);
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.5s;
}
.toast img { width: 18px; height: 18px; vertical-align: middle; margin-right: 6px; image-rendering: pixelated; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } }

body.in-dialog #bottom, body.in-dialog #prompt { opacity: 0; }
#bottom { transition: opacity 0.3s; position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#item-name { font-family: var(--mono); font-size: 13px; color: var(--cream); text-shadow: 0 1px 3px #000; opacity: 0; transition: opacity 0.3s; min-height: 18px; }
#item-name.show { opacity: 1; }
#coherence { align-self: flex-start; font-size: 16px; letter-spacing: 2px; text-shadow: 0 1px 2px #000; }
#coherence span { color: var(--coral); }
#coherence span.lost { color: rgba(243, 234, 216, 0.25); }
#coherence .label { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.06em; margin-left: 6px; vertical-align: middle; }

#hotbar { display: flex; gap: 3px; padding: 4px; background: var(--ink-soft); border-radius: 4px; }
.slot {
  width: 50px; height: 50px; position: relative;
  background: rgba(243, 234, 216, 0.06);
  border: 2px solid rgba(243, 234, 216, 0.12);
  border-radius: 3px;
  pointer-events: auto;
}
.slot img { position: absolute; inset: 1px; width: 44px; height: 44px; image-rendering: pixelated; pointer-events: none; }
.slot .count { position: absolute; right: 3px; bottom: 1px; font-family: var(--mono); font-size: 12px; color: var(--cream); text-shadow: 1px 1px 0 #000; pointer-events: none; }
.slot .key { position: absolute; left: 3px; top: 1px; font-family: var(--mono); font-size: 9px; color: var(--muted); pointer-events: none; }
#hotbar .slot.selected { border-color: var(--coral); background: rgba(217, 119, 87, 0.18); }

#hint {
  position: absolute; bottom: 150px; left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 13px; color: var(--cream);
  background: var(--ink-soft); padding: 7px 14px; border-radius: 3px;
  opacity: 0; transition: opacity 0.6s; white-space: nowrap;
}
#hint.show { opacity: 1; }

#bubbles { position: absolute; inset: 0; }
.bubble {
  position: absolute; transform: translate(-50%, -100%);
  max-width: 240px; padding: 6px 10px;
  background: rgba(250, 244, 255, 0.92); color: #3a2a55;
  font-size: 13px; line-height: 1.3; border-radius: 10px;
  box-shadow: 0 2px 10px rgba(120, 90, 200, 0.4);
  text-align: center;
}
.bubble.marker { background: none; box-shadow: none; color: var(--coral); font-size: 26px; text-shadow: 0 0 8px rgba(217, 119, 87, 0.9); animation: bob 1.6s ease-in-out infinite; }
.bubble.name { background: var(--ink-soft); color: var(--cream-dim); font-family: var(--mono); font-size: 11px; border-radius: 3px; box-shadow: none; padding: 2px 6px; }
@keyframes bob { 50% { margin-top: -6px; } }

#chapter {
  position: fixed; top: 30%; left: 50%; transform: translateX(-50%);
  text-align: center; pointer-events: none;
  animation: chapter 5.5s ease forwards;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}
.chapter-turn { font-family: var(--mono); font-size: 13px; letter-spacing: 0.3em; color: var(--coral-soft); text-transform: uppercase; }
.chapter-title { font-size: 44px; font-style: italic; margin-top: 6px; }
@keyframes chapter { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

#subtitle {
  position: fixed; top: 22%; left: 50%; transform: translateX(-50%);
  font-size: 24px; font-style: italic; text-align: center; max-width: 760px;
  color: var(--cream); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  opacity: 0; transition: opacity 1.2s; pointer-events: none;
}
#subtitle.show { opacity: 1; }

#hurt { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.5s; background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 120, 230, 0.55)); }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: #f3ead8; transition: opacity 1.5s; }
#fade { position: fixed; inset: 0; pointer-events: none; background: #f3ead8; opacity: 0; transition: opacity 2.5s ease; }

#dialog {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  width: min(760px, 92vw);
  background: rgba(24, 21, 19, 0.92);
  border: 1px solid rgba(243, 234, 216, 0.14);
  border-radius: 6px;
  padding: 18px 24px 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
.dialog-speaker { font-family: var(--mono); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 8px; min-height: 15px; }
.dialog-text { font-size: 20px; line-height: 1.5; min-height: 60px; }
.dialog-text.narrator { font-style: italic; color: var(--cream-dim); }
.dialog-text.echo { font-style: italic; }
.dialog-text.chorus { letter-spacing: 0.02em; }
.dialog-choices { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.dialog-choices button {
  text-align: left; font-family: var(--serif); font-size: 17px;
  background: rgba(217, 119, 87, 0.08); color: var(--cream);
  border: 1px solid rgba(217, 119, 87, 0.35); border-radius: 4px;
  padding: 9px 14px; cursor: pointer;
}
.dialog-choices button:hover, .dialog-choices button:focus-visible { background: rgba(217, 119, 87, 0.25); border-color: var(--coral); outline: none; }
.dialog-choices button .num { font-family: var(--mono); font-size: 12px; color: var(--coral-soft); margin-right: 10px; }
.dialog-continue { position: absolute; right: 16px; bottom: 8px; font-family: var(--mono); font-size: 10px; color: var(--muted); opacity: 0; transition: opacity 0.3s; }
.dialog-continue.show { opacity: 1; }

.panel {
  position: fixed; inset: 0;
  background: rgba(18, 16, 14, 0.72);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.panel-inner {
  display: flex; gap: 36px;
  background: rgba(29, 26, 23, 0.96);
  border: 1px solid rgba(243, 234, 216, 0.14);
  border-radius: 8px; padding: 26px 30px;
  max-height: 86vh;
}
.panel-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel h2 { font-weight: normal; font-style: italic; font-size: 22px; margin: 0 0 4px; color: var(--cream); }
.slot-grid { display: grid; grid-template-columns: repeat(9, 50px); gap: 3px; }
.hotbar-grid { margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(243, 234, 216, 0.16); }
.panel .slot { cursor: pointer; }
.panel .slot:hover { border-color: rgba(217, 119, 87, 0.7); }
#inv-detail { min-height: 64px; max-width: 480px; font-size: 15px; color: var(--cream-dim); line-height: 1.4; }
#inv-detail b { color: var(--cream); font-weight: normal; font-style: italic; display: block; font-size: 17px; }
.recipes-col { width: 340px; }
#recipes { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.recipe {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 4px;
  border: 1px solid rgba(243, 234, 216, 0.08);
  background: rgba(243, 234, 216, 0.03);
  cursor: pointer;
}
.recipe.ready { border-color: rgba(217, 119, 87, 0.45); }
.recipe.ready:hover { background: rgba(217, 119, 87, 0.15); }
.recipe.locked { opacity: 0.45; cursor: default; }
.recipe img { width: 32px; height: 32px; image-rendering: pixelated; }
.recipe .r-name { flex: 1; font-size: 15px; }
.recipe .r-name small { display: block; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.recipe .r-needs { display: flex; gap: 4px; font-family: var(--mono); font-size: 11px; color: var(--cream-dim); align-items: center; }
.recipe .r-needs img { width: 20px; height: 20px; }
.recipe .r-needs .short { color: #e07a6a; }
.panel-foot { font-family: var(--mono); font-size: 11px; color: var(--muted); margin: 6px 0 0; }
.panel-foot.centered { text-align: center; margin-top: 12px; }
#cursor-stack { position: fixed; width: 44px; height: 44px; pointer-events: none; transform: translate(-50%, -50%); }
#cursor-stack img { width: 44px; height: 44px; image-rendering: pixelated; }
#cursor-stack .count { position: absolute; right: 0; bottom: -2px; font-family: var(--mono); font-size: 12px; text-shadow: 1px 1px 0 #000; }

#journal .panel-col { width: 380px; max-height: 70vh; overflow-y: auto; }
#notes { margin: 0; padding-left: 22px; font-size: 16px; line-height: 1.45; color: var(--cream-dim); }
#notes li { margin-bottom: 8px; }
#notes li::marker { color: var(--coral); font-family: var(--mono); font-size: 12px; }
#echo-count { font-family: var(--mono); font-style: normal; font-size: 12px; color: var(--muted); }
.echo-entry { margin-bottom: 14px; font-style: italic; font-size: 15px; line-height: 1.45; color: var(--cream-dim); border-left: 2px solid var(--coral); padding-left: 12px; }
.echo-entry.unread { color: var(--muted); border-color: rgba(243, 234, 216, 0.15); font-style: normal; font-family: var(--mono); font-size: 12px; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#pause { background: rgba(18, 16, 14, 0.6); }
.card { background: rgba(29, 26, 23, 0.96); border: 1px solid rgba(243, 234, 216, 0.14); border-radius: 8px; padding: 28px 34px; width: min(520px, 92vw); text-align: center; }
.card h2 { font-weight: normal; font-style: italic; font-size: 30px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; text-align: left; font-family: var(--mono); font-size: 12px; color: var(--cream-dim); margin: 18px 0; }
kbd { display: inline-block; min-width: 54px; font-family: var(--mono); color: var(--coral-soft); }
.slider { display: flex; align-items: center; justify-content: center; gap: 12px; font-family: var(--mono); font-size: 12px; color: var(--cream-dim); margin-bottom: 16px; }
.slider input { accent-color: var(--coral); }

button {
  font-family: var(--mono); font-size: 14px;
  background: var(--coral); color: var(--ink);
  border: none; border-radius: 4px;
  padding: 10px 22px; cursor: pointer;
}
button:hover { background: var(--coral-soft); }
button:disabled { background: rgba(243, 234, 216, 0.15); color: var(--muted); cursor: wait; }
button.quiet { background: transparent; color: var(--muted); border: 1px solid rgba(243, 234, 216, 0.2); }
button.quiet:hover { color: var(--cream); }

#title { background: radial-gradient(ellipse at center, rgba(29, 26, 23, 0.25), rgba(29, 26, 23, 0.8)); }
.title-wrap { text-align: center; max-width: 620px; padding: 20px; }
.title-mark { font-size: 54px; color: var(--coral); animation: spin 24s linear infinite; display: inline-block; text-shadow: 0 0 24px rgba(217, 119, 87, 0.6); }
@keyframes spin { to { transform: rotate(360deg); } }
#title h1, #credits h1 { font-weight: normal; font-style: italic; font-size: 64px; margin: 8px 0 4px; letter-spacing: -0.01em; text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6); }
.title-sub { font-family: var(--mono); font-size: 13px; letter-spacing: 0.2em; color: var(--coral-soft); text-transform: uppercase; margin: 0 0 28px; }
.title-note { font-size: 18px; line-height: 1.5; color: var(--cream-dim); margin-bottom: 26px; }
.title-echo { font-style: italic; color: var(--coral-soft); margin: -10px 0 22px; }
.title-foot { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 22px; }

#ending { background: #f3ead8; color: var(--ink); flex-direction: column; opacity: 0; transition: opacity 3s; }
#ending.show { opacity: 1; }
#ending-lines { text-align: center; max-width: 700px; }
#ending-lines p { font-size: 26px; font-style: italic; line-height: 1.5; opacity: 0; transition: opacity 2s; margin: 0 0 18px; }
#ending-lines p.show { opacity: 1; }
#ending-lines p.small { font-size: 18px; color: #7a6f62; }
#ending-echo { text-align: center; width: min(560px, 90vw); }
#ending-echo p { font-size: 22px; font-style: italic; }
#echo-input {
  width: 100%; height: 120px; resize: none;
  font-family: var(--serif); font-size: 18px; font-style: italic; line-height: 1.5;
  background: #fbf6ec; color: var(--ink);
  border: 1px solid #d8cbb3; border-radius: 6px; padding: 14px;
  user-select: text;
}
#echo-input:focus { outline: 2px solid var(--coral); }
.ending-buttons { display: flex; justify-content: center; gap: 12px; margin-top: 14px; }
#ending .quiet { color: #7a6f62; border-color: #cfc2aa; }
#ending .quiet:hover { color: var(--ink); }
#credits { text-align: center; max-width: 600px; }
#credits .credits-body { font-size: 18px; line-height: 1.55; }
#credits .muted { color: #7a6f62; }
#credits button { margin-top: 18px; }

#error { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--ink); color: var(--cream); font-size: 18px; padding: 40px; text-align: center; white-space: pre-wrap; }
