:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f2e2c3;
  --muted: #bda98a;
  --ember: #d77732;
  --ember-soft: rgba(215, 119, 50, 0.2);
  --stone: rgba(24, 20, 16, 0.88);
  --stone-light: rgba(47, 39, 31, 0.94);
  --line: rgba(224, 183, 122, 0.32);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #11100d; }
body { touch-action: none; }
button, select { font: inherit; }
button { color: var(--ink); }

#application-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  background: radial-gradient(circle at 50% 30%, #5d6955 0, #1b211b 64%, #0e0f0d 100%);
}

#app-ui { position: fixed; inset: 0; pointer-events: none; }
.hud-safe { position: absolute; inset: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }

.chapter-ribbon {
  position: absolute;
  left: 18px;
  top: 16px;
  padding: 10px 14px;
  border-left: 3px solid var(--ember);
  background: linear-gradient(90deg, rgba(20, 15, 11, 0.92), rgba(20, 15, 11, 0.5));
  backdrop-filter: blur(8px);
  max-width: min(440px, 62vw);
}
.chapter-ribbon strong { display: block; font-family: Georgia, serif; font-size: clamp(17px, 2vw, 24px); letter-spacing: .02em; }
.eyebrow { display: block; color: #d2aa72; text-transform: uppercase; letter-spacing: .12em; font-size: 11px; margin-bottom: 3px; }

.objective-card {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  width: min(460px, 52vw);
  padding: 11px 16px 13px;
  background: rgba(20, 16, 12, 0.88);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  text-align: center;
}
.objective-kicker { color: #d49a59; text-transform: uppercase; letter-spacing: .15em; font-size: 10px; }
.objective-card h1 { font-family: Georgia, serif; margin: 3px 0 2px; font-size: clamp(17px, 2vw, 22px); font-weight: 500; }
.objective-card p { margin: 0; color: #e0cfb3; font-size: 13px; }
.objective-progress { height: 3px; margin-top: 9px; background: rgba(255,255,255,.08); overflow: hidden; border-radius: 999px; }
.objective-progress span { display: block; height: 100%; width: 0; background: var(--ember); transition: width .45s ease; }

.top-actions { position: absolute; right: 14px; top: 15px; display: flex; gap: 8px; pointer-events: auto; }
.round-button, .dialog-panel button, .journal-panel button, .settings-panel button, .settings-panel select {
  border: 1px solid var(--line);
  background: rgba(25, 19, 14, .9);
  border-radius: 999px;
  padding: 9px 13px;
  cursor: pointer;
}
.round-button:hover, .dialog-panel button:hover, .journal-panel button:hover, .settings-panel button:hover { border-color: #e1a15f; background: #3b281a; }

.story-toast {
  position: absolute;
  left: 50%;
  bottom: 120px;
  width: min(720px, calc(100vw - 36px));
  transform: translate(-50%, 18px);
  opacity: 0;
  padding: 13px 18px;
  background: rgba(19, 15, 12, .9);
  border: 1px solid rgba(223, 180, 119, .3);
  border-radius: 11px;
  color: #f2dfbd;
  text-align: center;
  font-family: Georgia, serif;
  line-height: 1.45;
  transition: .3s ease;
}
.story-toast.visible { opacity: 1; transform: translate(-50%, 0); }

.dialog-panel {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 18px);
  width: min(760px, calc(100vw - 28px));
  padding: 17px 19px;
  background: linear-gradient(160deg, rgba(35, 26, 18, .97), rgba(17, 14, 11, .97));
  border: 1px solid rgba(229, 174, 105, .42);
  border-radius: 15px;
  opacity: 0;
  visibility: hidden;
  pointer-events: auto;
  transition: .24s ease;
}
.dialog-panel.visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.speaker-row { display: flex; gap: 11px; align-items: center; }
.speaker-mark { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: #6a3d20; border: 2px solid #d39253; font-family: Georgia, serif; font-size: 20px; }
.speaker-name { font-family: Georgia, serif; font-size: 20px; }
.speaker-role { color: var(--muted); font-size: 12px; }
.dialog-panel p { margin: 13px 0 15px; font-family: Georgia, serif; font-size: clamp(16px, 2vw, 20px); line-height: 1.48; }
.dialog-panel button { float: right; }

.action-button {
  position: absolute;
  right: 30px;
  bottom: 38px;
  pointer-events: auto;
  min-width: 132px;
  min-height: 58px;
  border: 2px solid #efb168;
  background: radial-gradient(circle at 50% 20%, #9d5426, #4d2a18);
  border-radius: 50%;
  padding: 14px 18px;
  font-weight: 700;
  box-shadow: 0 0 0 5px rgba(0,0,0,.2);
  cursor: pointer;
}

.journal-panel, .settings-panel {
  position: absolute;
  inset: 3.5vh 4vw;
  background: rgba(20, 16, 12, .97);
  border: 1px solid rgba(224, 177, 111, .38);
  border-radius: 17px;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  pointer-events: auto;
  transform: scale(.98);
  transition: .2s ease;
  overflow: auto;
}
.journal-panel.visible, .settings-panel.visible { opacity: 1; visibility: visible; transform: scale(1); }
.journal-panel header, .settings-panel header { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.journal-panel h2, .settings-panel h2 { margin: 0; font-family: Georgia, serif; font-size: 27px; }
.journal-tabs { display: flex; gap: 7px; flex-wrap: wrap; margin: 20px 0 15px; }
.journal-tab.active { background: #6a3d20; border-color: #d89958; }
.journal-content { display: grid; gap: 12px; }
.journal-entry, .timeline-entry { border: 1px solid rgba(216, 174, 115, .18); background: rgba(255,255,255,.025); padding: 14px; border-radius: 11px; }
.journal-entry h3, .timeline-entry h3 { margin: 0 0 5px; font-family: Georgia, serif; font-size: 18px; }
.journal-entry p, .timeline-entry p { margin: 5px 0 0; color: #d2c1a6; line-height: 1.48; }
.journal-entry.locked, .timeline-entry.locked { opacity: .45; }
.timeline-entry { display: grid; grid-template-columns: 36px 1fr; gap: 10px; }
.timeline-entry > span { color: #d48948; font-weight: 700; }
.timeline-entry.active { border-color: #d18345; background: var(--ember-soft); }
.timeline-entry.complete h3::after { content: "  ✓"; color: #94b57a; }

.settings-panel { inset: auto 20px 20px auto; width: min(430px, calc(100vw - 40px)); max-height: calc(100vh - 40px); }
.settings-panel label { display: grid; gap: 7px; margin-top: 18px; color: #d8c7aa; }
.settings-panel select { width: 100%; border-radius: 8px; color: var(--ink); }
.switch-row { grid-template-columns: auto 1fr !important; align-items: center; }
.danger-button { margin-top: 22px; border-color: rgba(194, 88, 61, .5) !important; }
.fine-print { color: #ae9b80; font-size: 12px; line-height: 1.45; }

.mobile-controls { position: absolute; inset: 0; display: none; pointer-events: none; }
.joystick-zone { position: absolute; left: 26px; bottom: 25px; width: 126px; height: 126px; border-radius: 50%; border: 2px solid rgba(241, 214, 176, .35); background: rgba(15,12,9,.3); pointer-events: auto; }
.joystick-knob { position: absolute; width: 56px; height: 56px; left: 35px; top: 35px; border-radius: 50%; background: rgba(216, 139, 72, .72); border: 2px solid rgba(255,235,201,.5); }
.mobile-sprint { position: absolute; right: 39px; bottom: 116px; width: 74px; height: 74px; border-radius: 50%; border: 2px solid rgba(238, 195, 137, .5); background: rgba(62, 40, 24, .78); pointer-events: auto; }
.rotate-device { display: none; position: absolute; inset: 0; background: rgba(12,10,8,.97); z-index: 50; align-items: center; justify-content: center; flex-direction: column; gap: 8px; text-align: center; pointer-events: auto; }
.rotate-icon { font-size: 42px; color: var(--ember); }
.test-badge { position: absolute; right: 13px; bottom: 8px; color: rgba(238, 218, 188, .55); font-size: 10px; letter-spacing: .12em; }

@media (pointer: coarse), (max-width: 900px) {
  .mobile-controls { display: block; }
  .action-button { right: 35px; bottom: 25px; min-width: 104px; min-height: 104px; border-radius: 50%; font-size: 13px; }
  .chapter-ribbon { max-width: 43vw; }
  .objective-card { width: 48vw; }
  .top-actions { top: auto; bottom: 12px; left: 50%; right: auto; transform: translateX(-50%); }
  .story-toast { bottom: 142px; font-size: 14px; }
  .dialog-panel { bottom: 12px; width: calc(100vw - 20px); }
}

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-device { display: flex; }
}

@media (max-height: 580px) {
  .chapter-ribbon { top: 5px; left: 5px; padding: 7px 10px; }
  .objective-card { top: 5px; padding: 7px 10px; }
  .objective-card p { font-size: 11px; }
  .round-button { padding: 6px 9px; font-size: 11px; }
}

#boot-error {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 999;
  width: min(620px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid rgba(235, 135, 91, .7);
  border-radius: 14px;
  background: rgba(28, 14, 11, .97);
  color: #ffe1cf;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
}

#application-canvas.right-mouse-running { cursor: grabbing; }
.desktop-control-hint {
  position: absolute;
  left: 18px;
  bottom: 14px;
  max-width: min(640px, calc(100vw - 220px));
  padding: 8px 11px;
  border-left: 3px solid rgba(215, 119, 50, .72);
  background: rgba(18, 14, 11, .72);
  color: #d9c6a8;
  font-size: 11px;
  line-height: 1.35;
  pointer-events: none;
  backdrop-filter: blur(6px);
}
.desktop-control-hint strong { color: #f0d2a8; margin-right: 8px; font-weight: 600; }

@media (pointer: coarse), (max-width: 900px) {
  .desktop-control-hint { display: none; }
}



.movement-status {
  position: absolute;
  left: 18px;
  bottom: 54px;
  padding: 7px 11px;
  border: 1px solid rgba(224, 183, 122, .24);
  border-radius: 999px;
  background: rgba(18, 15, 12, .78);
  color: #d8c6a9;
  font-size: 11px;
  letter-spacing: .04em;
  backdrop-filter: blur(8px);
}
.movement-status[data-surface="river"] { color: #b6d9df; border-color: rgba(120, 188, 202, .38); }
.movement-status[data-surface="highGrass"] { color: #d7c98a; }

.threat-card {
  position: absolute;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 36px));
  padding: 9px 12px 11px;
  border: 1px solid rgba(197, 84, 50, .52);
  border-radius: 10px;
  background: rgba(31, 14, 10, .88);
  backdrop-filter: blur(8px);
}
.threat-row { display: flex; justify-content: space-between; gap: 15px; color: #efc0a4; font-size: 12px; }
.threat-row span:first-child { font-family: Georgia, serif; font-size: 15px; }
.threat-track { height: 5px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.08); }
.threat-track span { display: block; height: 100%; width: 0; background: #bf4b2f; transition: width .12s linear; }

.attack-button {
  position: absolute;
  right: 186px;
  bottom: 38px;
  pointer-events: auto;
  min-width: 112px;
  min-height: 54px;
  border: 2px solid rgba(218, 104, 67, .9);
  background: radial-gradient(circle at 50% 20%, #7b3022, #351713);
  color: #ffe2cf;
  border-radius: 50%;
  padding: 12px 16px;
  font-weight: 700;
  box-shadow: 0 0 0 5px rgba(0,0,0,.2);
  cursor: pointer;
}
.attack-button:hover { border-color: #ffae82; background: #692719; }
.attack-button:active { transform: scale(.96); }

@media (pointer: coarse), (max-width: 900px) {
  .attack-button {
    right: 35px;
    bottom: 145px;
    width: 80px;
    min-width: 80px;
    height: 80px;
    min-height: 80px;
    padding: 8px;
    font-size: 12px;
  }
  .mobile-sprint { right: 148px; bottom: 38px; }
  .movement-status { left: 164px; bottom: 22px; }
  .threat-card { bottom: 134px; width: min(300px, 44vw); }
}
