:root {
  color-scheme: dark;
  --gold: #e5bd61;
  --gold-light: #ffe6a0;
  --ink: #101719;
  --glass: rgba(14, 24, 25, 0.82);
  --line: rgba(255, 229, 162, 0.22);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #0d181b; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button { font: inherit; }
#game-shell, #game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; }
#game-shell { overflow: hidden; touch-action: none; background: radial-gradient(circle at 50% 20%, #5a7780 0%, #1b3035 52%, #0b1417 100%); }
#game-canvas { display: block; outline: none; touch-action: none; }
.hidden { display: none !important; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(22px + var(--safe-top)) calc(22px + var(--safe-right)) calc(22px + var(--safe-bottom)) calc(22px + var(--safe-left));
  background: radial-gradient(circle at 50% 30%, rgba(46, 72, 70, .35), rgba(5, 11, 12, .88));
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease, visibility .35s ease;
}
.overlay.visible { opacity: 1; visibility: visible; }
.start-overlay { background: linear-gradient(rgba(5, 11, 12, .34), rgba(5, 11, 12, .78)); }
.panel {
  width: min(620px, 100%);
  max-height: calc(100dvh - 34px);
  overflow: auto;
  padding: clamp(26px, 5vw, 50px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(22, 35, 35, .95), rgba(9, 17, 19, .95));
  box-shadow: 0 28px 100px rgba(0, 0, 0, .55), inset 0 1px rgba(255, 255, 255, .05);
  text-align: center;
  backdrop-filter: blur(16px);
}
.eyebrow { color: var(--gold); letter-spacing: .22em; font-weight: 800; font-size: 11px; margin-bottom: 14px; }
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 600; line-height: .96; text-wrap: balance; }
h1 { font-size: clamp(42px, 8vw, 76px); }
h2 { font-size: clamp(31px, 5vw, 52px); color: var(--gold-light); }
h1 span { color: var(--gold-light); }
.hero-panel > p, .victory-panel > p, .cinematic-card > p { color: #d2dad9; line-height: 1.62; max-width: 530px; margin: 22px auto; }
.hero-panel > p strong, .cinematic-card strong { color: var(--gold-light); }
.controls-help { display: grid; gap: 8px; margin: 22px 0; text-align: left; }
.controls-help div { display: grid; grid-template-columns: 76px 1fr; gap: 12px; padding: 11px 14px; border-radius: 12px; background: rgba(255,255,255,.045); border: 1px solid rgba(255,255,255,.055); }
.controls-help strong { color: var(--gold-light); }
.controls-help span { color: #aebdbc; font-size: 13px; line-height: 1.45; }
.main-button { min-height: 54px; padding: 0 28px; border: 0; border-radius: 999px; color: #1b1710; background: linear-gradient(180deg, #ffe19a, #d3a94e); font-weight: 900; letter-spacing: .08em; cursor: pointer; box-shadow: 0 9px 30px rgba(218, 174, 75, .22); transition: transform .18s, filter .18s; }
.main-button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.main-button:active { transform: translateY(1px) scale(.985); }
.text-button { border: 0; color: #d8c99e; background: transparent; font-weight: 800; font-size: 12px; letter-spacing: .08em; cursor: pointer; padding: 10px 12px; }
.rune { color: var(--gold-light); font-size: 30px; animation: runePulse 1.4s infinite ease-in-out; }
.loading-panel h1 { font-size: clamp(34px, 7vw, 58px); margin: 12px 0 24px; }
#loading-text { color: #d3dcdb; margin: 0 0 12px; }
.progress-track, .cinematic-progress { height: 7px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.08); }
#progress-bar, #cinematic-progress-bar { height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, #b68c3c, #ffe299); transition: width .2s linear; }
.tiny { color: #7e9290; font-size: 12px; margin-top: 14px; }

.cinematic-layer { position: absolute; inset: 0; z-index: 24; pointer-events: none; display: flex; align-items: flex-end; justify-content: center; padding: 24px calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left)); background: linear-gradient(transparent 30%, rgba(5, 10, 11, .72)); }
.cinematic-card { pointer-events: auto; width: min(760px, 100%); padding: 22px 28px 16px; border: 1px solid var(--line); border-radius: 20px; background: rgba(8, 17, 19, .82); box-shadow: 0 18px 60px rgba(0,0,0,.42); backdrop-filter: blur(12px); text-align: center; }
.cinematic-card h2 { font-size: clamp(27px, 5vw, 46px); }
.cinematic-card > p { margin: 13px auto 16px; }
.cinematic-progress { max-width: 460px; margin: 0 auto 5px; }
.cinematic-status { margin: 12px auto 6px; color: #f3e3b4; font-size: 13px; font-weight: 700; letter-spacing: .03em; }

#hud { position: absolute; z-index: 10; top: calc(14px + var(--safe-top)); left: calc(14px + var(--safe-left)); right: calc(14px + var(--safe-right)); display: flex; gap: 10px; align-items: center; pointer-events: none; }
.hud-card, .icon-button, #radar { background: var(--glass); border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.25); backdrop-filter: blur(12px); }
.hud-card { min-height: 57px; border-radius: 15px; padding: 9px 14px; display: flex; align-items: center; gap: 11px; }
.hud-card small { display: block; color: #94aaa7; font-size: 9px; letter-spacing: .13em; font-weight: 800; }
.hud-card strong { display: block; color: #f4eddb; margin-top: 2px; font-size: 16px; }
.book-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: #241b0c; background: linear-gradient(145deg, #ffe5a3, #bc8f39); font-size: 23px; transform: rotate(-5deg); }
.objective { margin: 0 auto; min-width: 235px; justify-content: center; text-align: center; }
.icon-button { pointer-events: auto; flex: 0 0 48px; height: 48px; border-radius: 14px; color: #f4ead2; font-size: 22px; cursor: pointer; }

#radar { position: absolute; z-index: 11; top: calc(84px + var(--safe-top)); right: calc(14px + var(--safe-right)); width: 188px; padding: 9px; border-radius: 18px; pointer-events: none; }
.radar-title { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 5px; }
.radar-title span { color: var(--gold-light); font-weight: 900; font-size: 11px; letter-spacing: .14em; }
.radar-title small { color: #91a5a3; font-size: 9px; }
#radar-canvas { display: block; width: 168px; height: 168px; border-radius: 12px; background: rgba(4, 10, 11, .68); border: 1px solid rgba(255,255,255,.08); }
.radar-legend { display: flex; justify-content: center; gap: 13px; padding-top: 6px; color: #aab9b7; font-size: 9px; }
.radar-legend span { display: flex; align-items: center; gap: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.red { background: #ff4141; box-shadow: 0 0 7px #ff4141; }
.dot.white { background: #fff8d8; box-shadow: 0 0 6px #fff8d8; }

#message { position: absolute; z-index: 14; left: 50%; top: 22%; transform: translate(-50%, -12px); min-width: min(420px, 80vw); padding: 13px 20px; border-radius: 14px; background: rgba(13, 23, 22, .86); border: 1px solid rgba(255, 225, 151, .3); color: #fff2ca; text-align: center; font-weight: 800; opacity: 0; transition: .25s; pointer-events: none; backdrop-filter: blur(10px); }
#message.show { opacity: 1; transform: translate(-50%, 0); }
#nearby-hint { position: absolute; z-index: 9; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 12px); padding: 9px 15px; border-radius: 999px; color: #ffe8a7; background: rgba(18, 27, 25, .78); border: 1px solid rgba(255, 224, 139, .25); opacity: 0; transition: .25s; pointer-events: none; font-size: 13px; font-weight: 800; }
#nearby-hint.visible { opacity: 1; transform: translate(-50%, 0); }

.knowledge-overlay { background: radial-gradient(circle, rgba(91, 68, 24, .24), rgba(4, 9, 10, .9)); }
.knowledge-panel { width: min(690px, 100%); }
.knowledge-icon { width: 82px; height: 82px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 24px; color: #2c210e; background: linear-gradient(145deg, #fff0b5, #c99c3d); box-shadow: 0 10px 35px rgba(226, 180, 72, .24); font-family: Georgia, serif; font-size: 39px; font-weight: 900; transform: rotate(-3deg); }
.knowledge-return { color: #f7edcf; font-size: clamp(17px, 2.5vw, 21px); line-height: 1.5; margin: 18px auto 14px; }
.knowledge-examples { display: grid; gap: 8px; margin: 18px 0; text-align: left; }
.knowledge-example { padding: 11px 13px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.06); color: #cbd5d3; line-height: 1.42; font-size: 14px; }
.knowledge-example strong { color: var(--gold-light); }
.knowledge-mission { color: #aebfbc; line-height: 1.55; margin: 19px auto 23px; }

#mobile-controls { position: absolute; z-index: 12; inset: 0; pointer-events: none; }
#joystick-zone { pointer-events: auto; position: absolute; left: calc(20px + var(--safe-left)); bottom: calc(20px + var(--safe-bottom)); width: 150px; height: 150px; display: grid; place-items: center; }
#joystick-base { position: relative; width: 112px; height: 112px; border-radius: 50%; border: 1px solid rgba(255,255,255,.19); background: radial-gradient(circle, rgba(255,255,255,.10), rgba(9,18,19,.38)); box-shadow: inset 0 0 25px rgba(0,0,0,.25); }
#joystick-base::before, #joystick-base::after { content: ""; position: absolute; background: rgba(255,255,255,.07); }
#joystick-base::before { width: 1px; top: 12px; bottom: 12px; left: 50%; }
#joystick-base::after { height: 1px; left: 12px; right: 12px; top: 50%; }
#joystick-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f5dfaa, #ad8237); border: 2px solid rgba(255,255,255,.24); box-shadow: 0 7px 18px rgba(0,0,0,.34); will-change: transform; }
.action-buttons { position: absolute; right: calc(22px + var(--safe-right)); bottom: calc(24px + var(--safe-bottom)); display: flex; gap: 11px; align-items: flex-end; pointer-events: auto; }
.action-button { width: 76px; height: 76px; border-radius: 50%; border: 1px solid rgba(255,235,185,.28); color: #fff0c5; background: rgba(14,25,25,.72); box-shadow: 0 8px 25px rgba(0,0,0,.28); font-weight: 900; font-size: 10px; letter-spacing: .06em; backdrop-filter: blur(9px); }
.action-button span { display: block; font-size: 21px; margin-bottom: 2px; }
.action-button.active { transform: scale(.94); background: rgba(171,126,48,.72); }
.dance-button { width: 72px; height: 72px; }
.jump-button { width: 88px; height: 88px; }

.victory-seal { display: grid; place-items: center; width: 82px; height: 82px; margin: 0 auto 18px; border-radius: 50%; color: #251e0d; background: linear-gradient(145deg, #ffe8a1, #c99b3d); font-size: 42px; font-weight: 900; box-shadow: 0 10px 40px rgba(220,173,67,.25); }
.result-row { display: flex; justify-content: space-between; margin: 24px 0; padding: 14px 17px; border-radius: 13px; background: rgba(255,255,255,.05); color: #aebdbb; }
.result-row strong { color: var(--gold-light); }
#rotate-notice { display: none; position: absolute; z-index: 100; inset: auto 14px calc(10px + var(--safe-bottom)); padding: 8px 13px; border-radius: 10px; color: #f5e9c8; background: rgba(7,13,14,.86); text-align: center; font-size: 12px; }
#error-box { position: absolute; z-index: 100; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(650px, calc(100% - 30px)); padding: 14px; border-radius: 12px; color: #ffe9e9; background: rgba(95, 23, 23, .94); border: 1px solid #d77; }

@keyframes runePulse { 50% { transform: scale(1.18) rotate(12deg); filter: drop-shadow(0 0 10px #ffd97c); } }

@media (max-width: 720px) {
  .panel { padding: 25px 21px; border-radius: 19px; }
  .hero-panel > p { margin: 16px auto; font-size: 14px; }
  .controls-help { margin: 16px 0; }
  .controls-help div { grid-template-columns: 63px 1fr; padding: 9px 11px; }
  #hud { right: calc(9px + var(--safe-right)); left: calc(9px + var(--safe-left)); top: calc(8px + var(--safe-top)); }
  .objective { display: none; }
  .hud-card { min-height: 48px; padding: 7px 10px; }
  .book-icon { width: 31px; height: 31px; }
  .icon-button { margin-left: auto; width: 43px; height: 43px; }
  #radar { top: calc(64px + var(--safe-top)); right: calc(9px + var(--safe-right)); width: 144px; padding: 7px; border-radius: 15px; }
  #radar-canvas { width: 128px; height: 128px; }
  .radar-title small, .radar-legend { display: none; }
  .radar-title { justify-content: center; }
  #nearby-hint { bottom: calc(125px + var(--safe-bottom)); white-space: nowrap; }
  .cinematic-layer { padding: 14px; }
  .cinematic-card { padding: 17px 18px 10px; }
  .cinematic-card > p { font-size: 13px; line-height: 1.45; }
  .knowledge-panel { padding: 24px 20px; }
  .knowledge-icon { width: 66px; height: 66px; font-size: 31px; }
  .knowledge-return { font-size: 16px; }
  .knowledge-example { font-size: 13px; padding: 9px 11px; }
}

@media (max-width: 580px) and (orientation: portrait) {
  #rotate-notice { display: block; }
  #joystick-zone { left: calc(8px + var(--safe-left)); bottom: calc(40px + var(--safe-bottom)); transform: scale(.86); transform-origin: bottom left; }
  .action-buttons { right: calc(10px + var(--safe-right)); bottom: calc(50px + var(--safe-bottom)); transform: scale(.87); transform-origin: bottom right; }
}

@media (max-height: 520px) {
  .hero-panel { padding: 18px 24px; }
  .hero-panel h1 { font-size: 42px; }
  .hero-panel > p { margin: 11px auto; font-size: 13px; }
  .controls-help { margin: 10px 0; grid-template-columns: 1fr 1fr; }
  .controls-help div { display: block; padding: 8px 10px; }
  .controls-help strong { display: block; margin-bottom: 3px; }
  .main-button { min-height: 45px; }
  #radar { top: calc(66px + var(--safe-top)); width: 132px; }
  #radar-canvas { width: 116px; height: 116px; }
  .cinematic-card { padding: 14px 20px 8px; }
  .cinematic-card h2 { font-size: 30px; }
  .cinematic-card > p { margin: 8px auto 10px; font-size: 12px; }
  .knowledge-panel { max-width: 720px; padding: 18px 28px; }
  .knowledge-icon { width: 55px; height: 55px; font-size: 27px; margin-bottom: 8px; }
  .knowledge-panel h2 { font-size: 32px; }
  .knowledge-return { margin: 10px auto 7px; font-size: 15px; }
  .knowledge-examples { grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
  .knowledge-example { font-size: 11px; padding: 7px 8px; }
  .knowledge-mission { margin: 10px auto 12px; font-size: 12px; }
}

/* Transição aérea até o personagem, inspirada nas trocas cinematográficas de jogos de mundo aberto. */
.cinematic-card { transition: opacity .55s ease, transform .55s ease; }
.cinematic-layer { transition: background .75s ease; }
.cinematic-layer.camera-diving { background: linear-gradient(transparent 70%, rgba(5, 10, 11, .12)); }
.cinematic-layer.camera-diving .cinematic-card { opacity: 0; transform: translateY(24px) scale(.98); pointer-events: none; }

/* V7: fluxo de menu, apresentação do mapa e narrativa */
.start-overlay {
  background: linear-gradient(rgba(5, 11, 12, .22), rgba(5, 11, 12, .72));
}
.menu-panel {
  width: min(520px, 100%);
  padding: clamp(24px, 4.5vw, 42px);
}
.menu-panel h1 { font-size: clamp(42px, 7.5vw, 70px); }
.menu-subtitle {
  color: #d2dad9;
  line-height: 1.55;
  max-width: 460px;
  margin: 18px auto 22px;
}
.name-field {
  display: grid;
  gap: 7px;
  margin: 0 auto 16px;
  text-align: left;
}
.name-field span {
  color: var(--gold-light);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
}
.name-field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(255, 231, 171, .18);
  border-radius: 14px;
  padding: 0 15px;
  color: #f4eddb;
  background: rgba(255,255,255,.055);
  outline: none;
}
.name-field input:focus {
  border-color: rgba(255, 226, 160, .55);
  box-shadow: 0 0 0 3px rgba(255, 226, 160, .09);
}
.menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.secondary-button {
  min-height: 54px;
  padding: 0 25px;
  border: 1px solid rgba(255, 232, 177, .2);
  border-radius: 999px;
  color: #f7edcf;
  background: rgba(255,255,255,.065);
  font-weight: 900;
  letter-spacing: .08em;
  cursor: pointer;
  transition: transform .18s, filter .18s, background .18s;
}
.secondary-button:hover { transform: translateY(-2px); background: rgba(255,255,255,.1); }
.secondary-button:active { transform: translateY(1px) scale(.985); }
.menu-tip { margin-bottom: 0; }

.ranking-panel { width: min(520px, 100%); }
.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 24px 0;
  display: grid;
  gap: 8px;
}
.leaderboard-list li {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  border-radius: 13px;
  color: #d8e1df;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.05);
  text-align: left;
}
.leaderboard-list li.empty {
  display: block;
  color: #95aaa7;
  text-align: center;
}
.rank-pos { color: var(--gold-light); font-weight: 900; text-align: center; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-time { color: #f8e7b4; font-weight: 900; }

/* A volta pelo mapa deve exibir somente o mundo 3D. */
.cinematic-layer {
  z-index: 24;
  pointer-events: none;
  display: block;
  padding: 0;
  background: transparent;
  transition: none;
}
.cinematic-layer.camera-diving { background: transparent; }

.story-overlay {
  background: linear-gradient(rgba(5, 10, 11, .08), rgba(5, 10, 11, .74));
  place-items: end center;
}
.story-panel {
  width: min(610px, 100%);
  padding: clamp(24px, 4vw, 38px);
  margin-bottom: clamp(4px, 3vh, 25px);
  background: linear-gradient(145deg, rgba(17, 28, 29, .94), rgba(8, 15, 16, .95));
}
.story-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 20px;
  color: #251d0d;
  background: linear-gradient(145deg, #ffe7a0, #c89b3d);
  font-size: 30px;
  font-weight: 900;
}
.story-text {
  max-width: 520px;
  margin: 20px auto 24px;
  color: #d6dfdd;
  font-size: 16px;
  line-height: 1.65;
}

@media (max-width: 720px) {
  .menu-panel { padding: 22px 20px; }
  .menu-panel h1 { font-size: clamp(38px, 11vw, 56px); }
  .menu-subtitle { font-size: 14px; margin: 14px auto 17px; }
  .story-panel { padding: 22px 20px; }
  .story-text { font-size: 14px; margin: 15px auto 19px; }
}

@media (max-width: 520px) {
  .menu-actions { grid-template-columns: 1fr; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .menu-panel {
    width: min(760px, 100%);
    padding: 14px 20px;
  }
  .menu-panel h1 { font-size: 39px; }
  .menu-subtitle { margin: 8px auto 10px; font-size: 12px; }
  .name-field { margin-bottom: 9px; }
  .name-field input { min-height: 40px; }
  .menu-actions { max-width: 430px; margin: 0 auto; }
  .main-button, .secondary-button { min-height: 42px; }
  .menu-tip { margin-top: 7px; }
  .story-panel {
    width: min(720px, 100%);
    padding: 14px 22px;
  }
  .story-icon { width: 44px; height: 44px; margin-bottom: 8px; font-size: 23px; }
  .story-panel h2 { font-size: 29px; }
  .story-text { margin: 9px auto 12px; font-size: 13px; line-height: 1.45; }
}

#game-version {
  position: absolute;
  z-index: 120;
  right: calc(10px + var(--safe-right));
  bottom: calc(8px + var(--safe-bottom));
  padding: 4px 8px;
  border-radius: 8px;
  color: rgba(255, 245, 218, .82);
  background: rgba(5, 11, 12, .52);
  border: 1px solid rgba(255, 229, 162, .13);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  pointer-events: none;
  backdrop-filter: blur(6px);
}

/* Correção do fluxo inicial: avisos de rotação não cobrem os menus. */
#loading-screen.visible ~ #rotate-notice,
#start-screen.visible ~ #rotate-notice,
#ranking-screen.visible ~ #rotate-notice,
#story-screen.visible ~ #rotate-notice,
#knowledge-screen.visible ~ #rotate-notice,
#victory-screen.visible ~ #rotate-notice {
  display: none !important;
}


/* ===== V8 UI refresh ===== */
.start-overlay {
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 220, 132, .10), transparent 28%),
    radial-gradient(circle at 80% 20%, rgba(91, 145, 139, .14), transparent 32%),
    linear-gradient(rgba(4, 10, 11, .36), rgba(4, 10, 11, .82));
}
.chrome-panel {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 226, 145, .08), transparent 30%),
    linear-gradient(145deg, rgba(19, 31, 32, .95), rgba(8, 14, 16, .96));
  border: 1px solid rgba(255, 229, 162, .2);
  box-shadow: 0 30px 90px rgba(0,0,0,.56), inset 0 1px 0 rgba(255,255,255,.05), inset 0 0 0 1px rgba(255, 222, 160, .04);
}
.chrome-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,.045), transparent 24%, transparent 76%, rgba(255,232,177,.035));
}
.panel-crest {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  font-size: 28px;
  border-radius: 20px;
  color: #241a0f;
  background: linear-gradient(145deg, #ffe5a1, #c59033);
  box-shadow: 0 12px 28px rgba(197, 145, 51, .25);
}
.menu-panel {
  width: min(720px, 100%);
  background:
    radial-gradient(circle at center top, rgba(255, 233, 162, .08), transparent 32%),
    linear-gradient(145deg, rgba(15, 25, 27, .96), rgba(6, 12, 14, .97));
}
.menu-subtitle {
  max-width: 600px;
  margin: 14px auto 22px;
  color: #dbe6e4;
  line-height: 1.68;
  font-size: 15px;
}
.menu-help { margin-top: 18px; }
.menu-tip { color: #a8b9b6; margin-top: 14px; font-size: 12px; }
.name-field { display: grid; gap: 8px; text-align: left; margin: 0 auto 16px; max-width: 440px; }
.name-field span { color: var(--gold-light); font-weight: 800; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.name-field input {
  min-height: 50px;
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255, 231, 171, .18);
  padding: 0 15px;
  color: #f4eddb;
  background: rgba(255,255,255,.055);
  outline: none;
}
.name-field input:focus { border-color: rgba(255, 226, 160, .55); box-shadow: 0 0 0 3px rgba(255, 226, 160, .09); }
.menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 12px;
  max-width: 460px;
  margin: 0 auto;
}
.secondary-button {
  min-height: 54px;
  padding: 0 25px;
  border: 1px solid rgba(255, 232, 177, .2);
  border-radius: 999px;
  color: #f7edcf;
  background: rgba(255,255,255,.065);
  font-weight: 900;
  letter-spacing: .08em;
  cursor: pointer;
  transition: transform .18s, filter .18s, background .18s;
}
.secondary-button:hover { transform: translateY(-2px); background: rgba(255,255,255,.1); }
.secondary-button:active { transform: translateY(1px) scale(.985); }
.ranking-panel { width: min(560px, 100%); }
.leaderboard-list { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 8px; }
.leaderboard-list li {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  color: #d8e1df;
  background: linear-gradient(145deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.05);
  text-align: left;
}
.leaderboard-list li.empty { display: block; color: #95aaa7; text-align: center; }
.rank-pos { color: var(--gold-light); font-weight: 900; text-align: center; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-time { color: #f8e7b4; font-weight: 900; }
.cinematic-layer { z-index: 24; pointer-events: none; display: block; padding: 0; background: transparent; transition: none; }
.cinematic-layer.camera-diving { background: transparent; }
.story-overlay {
  background: linear-gradient(rgba(5, 10, 11, .08), rgba(5, 10, 11, .72));
  place-items: end center;
}
.story-panel {
  width: min(640px, 100%);
  padding: clamp(24px, 4vw, 38px);
  margin-bottom: clamp(4px, 3vh, 25px);
  background:
    radial-gradient(circle at center top, rgba(255, 231, 170, .07), transparent 30%),
    linear-gradient(145deg, rgba(17, 28, 29, .94), rgba(8, 15, 16, .96));
}
.story-icon {
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 22px;
  color: #251d0d;
  background: linear-gradient(145deg, #ffe7a0, #c89b3d);
  font-size: 34px;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(200, 155, 61, .28);
}
.story-text { max-width: 520px; margin: 20px auto 24px; color: #d6dfdd; font-size: 16px; line-height: 1.65; }
.knowledge-overlay {
  background:
    radial-gradient(circle at top, rgba(255,255,255,.08), transparent 28%),
    linear-gradient(rgba(6, 12, 14, .22), rgba(6, 12, 14, .88));
}
.knowledge-panel {
  width: min(760px, 100%);
  text-align: left;
  padding: clamp(24px, 4vw, 38px);
}
.knowledge-panel h2, .knowledge-panel .eyebrow, .knowledge-icon { text-align: center; }
.knowledge-return { max-width: 620px; margin-left: auto; margin-right: auto; text-align: center; }
.knowledge-mission { text-align: center; max-width: 620px; margin-left: auto; margin-right: auto; }
.knowledge-examples { margin-top: 18px; }
.knowledge-example {
  border-radius: 16px;
  padding: 14px 16px;
  background: linear-gradient(145deg, rgba(255,255,255,.06), rgba(255,255,255,.035));
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
#knowledge-screen[data-theme="matematica"] .knowledge-panel {
  background: radial-gradient(circle at top, rgba(117, 201, 255, .13), transparent 28%), linear-gradient(145deg, rgba(10, 29, 45, .96), rgba(7, 15, 26, .97));
}
#knowledge-screen[data-theme="matematica"] { background: radial-gradient(circle at top, rgba(91, 174, 255, .15), transparent 24%), linear-gradient(rgba(4,10,18,.28), rgba(4,10,18,.88)); }
#knowledge-screen[data-theme="portugues"] .knowledge-panel {
  background: radial-gradient(circle at top, rgba(255, 196, 126, .13), transparent 28%), linear-gradient(145deg, rgba(50, 28, 16, .96), rgba(24, 12, 7, .97));
}
#knowledge-screen[data-theme="portugues"] { background: radial-gradient(circle at top, rgba(255, 178, 91, .16), transparent 24%), linear-gradient(rgba(21,11,6,.28), rgba(21,11,6,.9)); }
#knowledge-screen[data-theme="ciencias"] .knowledge-panel {
  background: radial-gradient(circle at top, rgba(133, 255, 202, .12), transparent 28%), linear-gradient(145deg, rgba(10, 42, 34, .96), rgba(7, 20, 16, .97));
}
#knowledge-screen[data-theme="ciencias"] { background: radial-gradient(circle at top, rgba(93, 255, 194, .16), transparent 24%), linear-gradient(rgba(4,16,12,.3), rgba(4,16,12,.9)); }
#knowledge-screen[data-theme="geografia"] .knowledge-panel {
  background: radial-gradient(circle at top, rgba(141, 198, 255, .10), transparent 28%), linear-gradient(145deg, rgba(18, 38, 44, .96), rgba(10, 19, 22, .97));
}
#knowledge-screen[data-theme="geografia"] { background: radial-gradient(circle at top, rgba(93, 162, 255, .14), transparent 24%), linear-gradient(rgba(5,12,18,.28), rgba(5,12,18,.9)); }
#knowledge-screen[data-theme="artes"] .knowledge-panel {
  background: radial-gradient(circle at top, rgba(255, 138, 228, .12), transparent 28%), linear-gradient(145deg, rgba(47, 16, 43, .96), rgba(20, 8, 20, .97));
}
#knowledge-screen[data-theme="artes"] { background: radial-gradient(circle at top, rgba(255, 119, 221, .16), transparent 24%), linear-gradient(rgba(19,6,18,.28), rgba(19,6,18,.9)); }
#knowledge-screen[data-theme="matematica"] .knowledge-icon { background: linear-gradient(145deg, #8be2ff, #2e7bb2); color: #082033; }
#knowledge-screen[data-theme="portugues"] .knowledge-icon { background: linear-gradient(145deg, #ffd694, #be7333); color: #2d1504; }
#knowledge-screen[data-theme="ciencias"] .knowledge-icon { background: linear-gradient(145deg, #b6ffd8, #38a973); color: #09291a; }
#knowledge-screen[data-theme="geografia"] .knowledge-icon { background: linear-gradient(145deg, #c4e5ff, #4d8dbf); color: #092030; }
#knowledge-screen[data-theme="artes"] .knowledge-icon { background: linear-gradient(145deg, #ffc6f4, #bf4eb0); color: #2a0822; }
#game-version {
  position: absolute;
  z-index: 120;
  right: calc(10px + var(--safe-right));
  bottom: calc(18px + var(--safe-bottom));
  padding: 5px 10px;
  border-radius: 10px;
  color: rgba(255, 245, 218, .84);
  background: rgba(5, 11, 12, .56);
  border: 1px solid rgba(255, 229, 162, .13);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  pointer-events: none;
  backdrop-filter: blur(6px);
}
@media (max-width: 720px) {
  .menu-panel { padding: 22px 20px; }
  .menu-panel h1 { font-size: clamp(38px, 11vw, 56px); }
  .menu-subtitle { font-size: 14px; margin: 14px auto 17px; }
  .story-panel { padding: 22px 20px; }
  .story-text { font-size: 14px; margin: 15px auto 19px; }
  #game-version { bottom: calc(24px + var(--safe-bottom)); }
}
@media (max-width: 520px) { .menu-actions { grid-template-columns: 1fr; } }
@media (max-height: 520px) and (orientation: landscape) {
  .menu-panel { width: min(760px, 100%); padding: 14px 20px; }
  .menu-panel h1 { font-size: 39px; }
  .menu-subtitle { margin: 8px auto 10px; font-size: 12px; }
  .name-field { margin-bottom: 9px; }
  .name-field input { min-height: 40px; }
  .menu-actions { max-width: 430px; margin: 0 auto; }
  .main-button, .secondary-button { min-height: 42px; }
  .menu-tip { margin-top: 7px; }
  .story-panel { width: min(720px, 100%); padding: 14px 22px; }
  .story-icon { width: 44px; height: 44px; margin-bottom: 8px; font-size: 23px; }
  .story-panel h2 { font-size: 29px; }
  .story-text { margin: 9px auto 12px; font-size: 13px; line-height: 1.45; }
}
#loading-screen.visible ~ #rotate-notice,
#start-screen.visible ~ #rotate-notice,
#ranking-screen.visible ~ #rotate-notice,
#story-screen.visible ~ #rotate-notice,
#knowledge-screen.visible ~ #rotate-notice,
#victory-screen.visible ~ #rotate-notice { display: none !important; }


/* ===== Ajustes finos dos painéis de livros ===== */
.knowledge-panel {
  max-height: min(88dvh, 760px);
  scroll-padding-bottom: 18px;
}
.knowledge-panel .main-button {
  display: block;
  width: min(100%, 340px);
  margin: 14px auto 0;
}

@media (max-width: 720px) {
  .knowledge-panel {
    max-height: calc(100dvh - 24px);
    padding: 20px 18px 18px;
  }
  .knowledge-panel .main-button {
    width: min(100%, 300px);
    min-height: 46px;
    margin-top: 10px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .knowledge-panel {
    width: min(760px, 100%);
    max-height: calc(100dvh - 12px);
    padding: 14px 18px 16px;
  }
  .knowledge-icon {
    width: 50px;
    height: 50px;
    margin: 0 auto 8px;
    font-size: 24px;
    border-radius: 16px;
  }
  .knowledge-panel h2 {
    font-size: 27px;
  }
  .knowledge-return {
    margin: 8px auto 8px;
    font-size: 13px;
    line-height: 1.36;
  }
  .knowledge-examples {
    grid-template-columns: 1fr;
    gap: 5px;
    margin: 8px 0;
  }
  .knowledge-example {
    font-size: 11px;
    padding: 7px 9px;
    line-height: 1.28;
    border-radius: 12px;
  }
  .knowledge-mission {
    margin: 8px auto 10px;
    font-size: 11px;
    line-height: 1.34;
  }
  .knowledge-panel .main-button {
    position: sticky;
    bottom: 0;
    min-height: 38px;
    margin-top: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,.22);
  }
}


/* ===== Ajustes da tela final ===== */
.victory-panel {
  width: min(760px, 100%);
  max-height: min(88dvh, 760px);
}
.victory-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
}
.victory-actions .main-button,
.victory-actions .secondary-button {
  width: 100%;
}

@media (max-width: 620px) {
  .victory-actions { grid-template-columns: 1fr; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .victory-panel {
    width: min(860px, 100%);
    max-height: calc(100dvh - 12px);
    padding: 14px 18px 16px;
  }
  .victory-seal {
    width: 56px;
    height: 56px;
    margin: 0 auto 8px;
    font-size: 28px;
  }
  .victory-panel h2 {
    font-size: 42px;
    line-height: .92;
  }
  .victory-panel > p {
    margin: 10px auto 12px;
    font-size: 13px;
    line-height: 1.4;
    max-width: 680px;
  }
  .result-row {
    margin: 10px auto 12px;
    max-width: 520px;
    padding: 10px 14px;
  }
  .victory-actions {
    max-width: 560px;
    gap: 10px;
  }
  .victory-actions .main-button,
  .victory-actions .secondary-button {
    min-height: 42px;
  }
}


/* ===== Ajustes extras da tela final ===== */
.victory-panel { overflow: auto; }
.victory-actions { padding-bottom: 2px; }

@media (max-height: 520px) and (orientation: landscape) {
  .victory-panel {
    width: min(900px, 100%);
    max-height: calc(100dvh - 8px);
    padding: 12px 16px 14px;
  }
  .victory-panel .eyebrow {
    margin-bottom: 6px;
    font-size: 10px;
    letter-spacing: .18em;
  }
  .victory-seal {
    width: 48px;
    height: 48px;
    margin: 0 auto 6px;
    font-size: 24px;
  }
  .victory-panel h2 {
    font-size: 34px;
    line-height: .92;
    margin-bottom: 6px;
  }
  .victory-panel > p {
    margin: 8px auto 10px;
    font-size: 12px;
    line-height: 1.32;
    max-width: 760px;
  }
  .result-row {
    margin: 8px auto 10px;
    max-width: 520px;
    padding: 8px 12px;
    font-size: 12px;
  }
  .victory-actions {
    max-width: 620px;
    gap: 8px;
  }
  .victory-actions .main-button,
  .victory-actions .secondary-button {
    min-height: 38px;
    font-size: 12px;
    padding: 0 14px;
  }
}

/* Loading legível e com transição suave entre mensagens */
#loading-text {
  min-height: 1.6em;
  transition: opacity .16s ease, transform .16s ease;
}
#loading-text.changing {
  opacity: 0;
  transform: translateY(4px);
}
#progress-bar {
  transition: width .08s linear;
}


/* ===== Posições fixas, códices e direção de áudio ===== */
#audio-button { margin-left: auto; font-family: Georgia, serif; font-weight: 900; }
#audio-button.muted { opacity: .58; }

.story-panel,
.knowledge-panel {
  --subject-accent: #8a6428;
  border-radius: 8px 22px 8px 22px !important;
  border: 1px solid rgba(75, 55, 26, .72) !important;
  background:
    linear-gradient(90deg, rgba(80,58,27,.16), transparent 7%, transparent 48.9%, rgba(91,67,32,.18) 50%, transparent 51.1%, transparent 93%, rgba(80,58,27,.16)),
    linear-gradient(145deg, #f1e3b8, #d9c492) !important;
  color: #332817;
  box-shadow: 0 28px 80px rgba(0,0,0,.52), inset 0 0 30px rgba(94,66,26,.13) !important;
  backdrop-filter: none !important;
}
.story-panel::after,
.knowledge-panel::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(91,66,31,.28);
  border-radius: 4px 15px 4px 15px;
  pointer-events: none;
}
.story-panel .eyebrow,
.knowledge-panel .eyebrow { color: #76501e; }
.story-panel h2,
.knowledge-panel h2 { color: #342617; text-shadow: none; }
.story-panel .story-text,
.knowledge-return,
.knowledge-mission { color: #51412a !important; }
.story-panel { text-align: left; }
.story-panel .story-icon { margin-left: 0; background: #8a6428; color: #fff0c1; box-shadow: none; border-radius: 6px 16px 6px 16px; }
.story-panel .main-button { display: block; margin-left: auto; }

.knowledge-panel { text-align: left !important; }
.knowledge-panel h2,
.knowledge-panel .eyebrow { text-align: left !important; padding-left: 92px; }
.knowledge-icon {
  position: absolute;
  left: clamp(24px, 4vw, 38px);
  top: clamp(24px, 4vw, 38px);
  width: 66px;
  height: 66px;
  margin: 0;
  border-radius: 6px 18px 6px 18px;
  color: #fff3cf !important;
  background: var(--subject-accent) !important;
  box-shadow: none !important;
  transform: rotate(-2deg);
}
.knowledge-return { margin-top: 30px; text-align: left !important; font-family: Georgia, serif; font-size: clamp(18px,2.4vw,22px); font-weight: 700; }
.knowledge-examples { gap: 4px; margin: 15px 0; }
.knowledge-example {
  display: grid;
  grid-template-columns: minmax(115px, .42fr) 1fr;
  gap: 14px;
  padding: 10px 12px;
  border: 0;
  border-left: 4px solid var(--subject-accent);
  border-radius: 0 8px 8px 0;
  background: rgba(255,255,255,.24);
  color: #4a3a25;
  box-shadow: none;
}
.knowledge-example strong { color: #3d2b18; font-family: Georgia, serif; font-size: 15px; }
.knowledge-example p { margin: 0; line-height: 1.4; }
.knowledge-mission { margin: 14px 0 18px; text-align: left !important; font-style: italic; }
.knowledge-panel .main-button { margin-left: auto; margin-right: 0; }
#knowledge-screen[data-theme="matematica"] .knowledge-panel { --subject-accent: #356f95; }
#knowledge-screen[data-theme="portugues"] .knowledge-panel { --subject-accent: #9a5428; }
#knowledge-screen[data-theme="ciencias"] .knowledge-panel { --subject-accent: #2f7655; }
#knowledge-screen[data-theme="geografia"] .knowledge-panel { --subject-accent: #477698; }
#knowledge-screen[data-theme="artes"] .knowledge-panel { --subject-accent: #984c88; }

@media (max-width: 720px) {
  #hud { gap: 7px; }
  #audio-button, #fullscreen-button { flex-basis: 42px; width: 42px; height: 42px; font-size: 18px; }
  .knowledge-panel h2, .knowledge-panel .eyebrow { padding-left: 76px; }
  .knowledge-icon { width: 58px; height: 58px; left: 18px; top: 19px; }
  .knowledge-example { grid-template-columns: 1fr; gap: 3px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .story-panel, .knowledge-panel { border-radius: 5px 16px 5px 16px !important; }
  .knowledge-icon { width: 44px; height: 44px; top: 14px; left: 18px; font-size: 23px; }
  .knowledge-panel h2, .knowledge-panel .eyebrow { padding-left: 58px; }
  .knowledge-return { margin-top: 12px; font-size: 14px; }
  .knowledge-example { grid-template-columns: 110px 1fr; padding: 6px 8px; font-size: 11px; }
  .knowledge-example strong { font-size: 12px; }
  .knowledge-mission { margin: 7px 0 9px; }
}


/* ===== HUD sem radar ===== */
#book-progress {
  position: absolute;
  z-index: 11;
  top: calc(84px + var(--safe-top));
  right: calc(14px + var(--safe-right));
  min-width: 178px;
  min-height: 72px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 18px;
  color: #f4eddb;
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  backdrop-filter: blur(12px);
  pointer-events: none;
}
#book-progress.hidden { display: none !important; }
.book-progress-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 12px;
  color: #241b0c;
  background: linear-gradient(145deg, #ffe5a3, #bc8f39);
  font-size: 25px;
  transform: rotate(-4deg);
}
#book-progress small {
  display: block;
  color: #a9bbb7;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
}
#book-progress strong {
  display: block;
  margin-top: 3px;
  color: #fff0c4;
  font-size: 21px;
  line-height: 1;
}

/* Os botões permanecem no alto; o selo fica grudado no canto inferior. */
#game-version {
  right: calc(10vw + 3px + var(--safe-right)) !important;
  bottom: calc(2px + var(--safe-bottom)) !important;
  padding: 3px 6px !important;
  border-radius: 7px !important;
  font-size: 8px !important;
  line-height: 1.1 !important;
  z-index: 13 !important;
}

@media (max-width: 720px) {
  #book-progress {
    top: calc(61px + var(--safe-top));
    right: calc(8px + var(--safe-right));
    min-width: 145px;
    min-height: 58px;
    padding: 8px 10px;
    gap: 9px;
    border-radius: 15px;
  }
  .book-progress-icon {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    font-size: 20px;
  }
  #book-progress small { font-size: 8px; }
  #book-progress strong { font-size: 17px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  #book-progress {
    top: calc(59px + var(--safe-top));
    min-width: 136px;
    min-height: 52px;
    padding: 7px 9px;
  }
  .book-progress-icon {
    width: 31px;
    height: 31px;
    flex-basis: 31px;
    font-size: 18px;
  }
  #game-version {
    right: calc(10vw + 2px + var(--safe-right)) !important;
    bottom: calc(1px + var(--safe-bottom)) !important;
  }
}

/* ===== Versão 10 reconstruída: derrota e missão final ===== */
.defeat-panel {
  width: min(720px, 100%);
  max-height: min(88dvh, 760px);
  overflow: auto;
}
.danger-seal {
  background: linear-gradient(145deg, #ffd2b8, #b85b42);
  color: #35110a;
  box-shadow: 0 10px 40px rgba(166, 69, 43, .28);
}
#defeat-screen .chrome-panel {
  background:
    radial-gradient(circle at top, rgba(255, 188, 153, .12), transparent 28%),
    linear-gradient(145deg, rgba(43, 20, 15, .96), rgba(17, 8, 6, .97));
}
#defeat-screen .eyebrow { color: #ffd5b9; }
#defeat-screen .result-row strong { color: #ffe8d3; }

@media (max-height: 520px) and (orientation: landscape) {
  .defeat-panel {
    width: min(900px, 100%);
    max-height: calc(100dvh - 8px);
    padding: 12px 16px 14px;
  }
  .defeat-panel .eyebrow {
    margin-bottom: 6px;
    font-size: 10px;
    letter-spacing: .18em;
  }
  .defeat-panel h2 {
    font-size: 34px;
    line-height: .92;
    margin-bottom: 6px;
  }
  .defeat-panel > p {
    max-width: 760px;
    margin: 8px auto 10px;
    font-size: 12px;
    line-height: 1.32;
  }
}

#defeat-screen.visible ~ #rotate-notice {
  display: none !important;
}

/* ===== Versão 24 · Códice dos Livros ===== */
#book-progress {
  pointer-events: auto;
  min-width: 255px;
}
.book-progress-copy { flex: 1 1 auto; }
.codex-button {
  min-width: 72px;
  height: 38px;
  padding: 0 11px;
  border: 1px solid rgba(255, 229, 162, .32);
  border-radius: 12px;
  color: #30210e;
  background: linear-gradient(145deg, #ffe7a6, #c9953a);
  box-shadow: 0 5px 14px rgba(0,0,0,.25), inset 0 1px rgba(255,255,255,.45);
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: .08em;
  cursor: pointer;
  touch-action: manipulation;
}
.codex-button:active { transform: translateY(1px) scale(.97); }
.codex-button.new-book { animation: codexPulse .55s ease-in-out 3; }
@keyframes codexPulse {
  50% { transform: scale(1.12); filter: brightness(1.25); box-shadow: 0 0 22px rgba(255,218,119,.75); }
}

.codex-overlay,
.knowledge-overlay {
  background:
    radial-gradient(circle at center, rgba(255, 222, 151, .12), transparent 38%),
    rgba(10, 8, 5, .78);
  backdrop-filter: blur(5px);
}
.parchment-panel,
#knowledge-screen .knowledge-panel {
  position: relative;
  width: min(830px, calc(100vw - 24px));
  max-height: calc(100dvh - 22px);
  overflow: auto;
  padding: clamp(28px, 4vw, 48px);
  border: 0;
  border-radius: 12px 28px 12px 28px;
  color: #49351f;
  background:
    linear-gradient(90deg, rgba(104,66,28,.08), transparent 7%, transparent 93%, rgba(104,66,28,.08)),
    radial-gradient(circle at 20% 12%, rgba(255,255,255,.34), transparent 20%),
    repeating-linear-gradient(0deg, rgba(91,55,24,.025) 0 1px, transparent 1px 5px),
    linear-gradient(145deg, #f8e6b4, #dfbd78 52%, #f0d99f);
  box-shadow: 0 26px 70px rgba(0,0,0,.48), inset 0 0 0 2px rgba(105,65,25,.18), inset 0 0 38px rgba(105,65,25,.13);
}
.parchment-panel::before,
.parchment-panel::after,
#knowledge-screen .knowledge-panel::before,
#knowledge-screen .knowledge-panel::after {
  content: '';
  position: absolute;
  left: 18px;
  right: 18px;
  height: 13px;
  border-radius: 50%;
  background: rgba(107,65,27,.12);
  filter: blur(5px);
  pointer-events: none;
}
.parchment-panel::before,
#knowledge-screen .knowledge-panel::before { top: 5px; }
.parchment-panel::after,
#knowledge-screen .knowledge-panel::after { bottom: 5px; }
.codex-ribbon {
  width: fit-content;
  margin: 0 auto 8px;
  padding: 7px 18px;
  border-radius: 999px;
  color: #fff3ca;
  background: linear-gradient(145deg, #845127, #4f2c16);
  box-shadow: 0 7px 16px rgba(72,39,16,.26);
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: .18em;
}
.codex-panel h2 {
  margin: 8px 0;
  color: #3c2816;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(30px, 5vw, 48px);
  text-align: center;
}
.codex-intro {
  max-width: 650px;
  margin: 0 auto 22px;
  color: #684c2d;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  line-height: 1.5;
  text-align: center;
}
.codex-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(112px, 1fr));
  gap: 11px;
  margin: 18px 0 24px;
}
.codex-book {
  min-height: 150px;
  padding: 16px 10px 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 2px solid rgba(93,56,22,.28);
  border-radius: 7px 18px 7px 18px;
  color: #4a321d;
  background: linear-gradient(145deg, rgba(255,252,231,.58), rgba(207,164,92,.32));
  box-shadow: 0 7px 13px rgba(83,47,18,.12), inset 0 1px rgba(255,255,255,.52);
  font-family: inherit;
  cursor: pointer;
  transition: transform .17s ease, filter .17s ease;
}
.codex-book.unlocked:hover { transform: translateY(-4px) rotate(-1deg); filter: brightness(1.06); }
.codex-book.locked {
  opacity: .56;
  filter: grayscale(.55);
  cursor: default;
}
.codex-book-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: #fff1c4;
  background: linear-gradient(145deg, #87542b, #4b2915);
  font-size: 28px;
  box-shadow: 0 7px 13px rgba(67,35,13,.2);
}
.codex-book-name {
  min-height: 34px;
  display: grid;
  place-items: center;
  color: #3c2817;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
}
.codex-book small {
  color: #76593a;
  font-size: 9px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}
.parchment-button {
  min-height: 48px;
  padding: 0 24px;
  display: block;
  margin: 0 auto;
  border: 1px solid rgba(62,35,14,.42);
  border-radius: 999px;
  color: #fff2c8;
  background: linear-gradient(145deg, #825026, #4d2a15);
  box-shadow: 0 8px 18px rgba(74,40,16,.25), inset 0 1px rgba(255,255,255,.18);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: .09em;
  cursor: pointer;
}
.parchment-button:active { transform: translateY(1px) scale(.985); }

/* Teatro de cada livro */
#knowledge-screen .knowledge-panel {
  --subject-accent: #7d532a;
  text-align: left;
}
#knowledge-screen .knowledge-panel h2 {
  color: #392515;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(30px, 5vw, 48px);
}
#knowledge-screen .knowledge-panel .eyebrow {
  color: #7a5632;
}
#knowledge-screen .knowledge-return {
  color: #4d3821;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(17px, 2.3vw, 22px);
  line-height: 1.5;
}
#knowledge-screen .knowledge-example {
  color: #49341f;
  background: rgba(255,255,255,.27);
  border-left: 5px solid var(--subject-accent);
}
#knowledge-screen .knowledge-example strong { color: #392413; }
#knowledge-screen .knowledge-mission {
  padding: 12px 14px;
  border-radius: 8px;
  color: #3e2b19;
  background: rgba(113,75,34,.10);
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 700;
}
#knowledge-screen[data-theme="historia"] .knowledge-panel { --subject-accent: #8b6335; }
#knowledge-screen[data-theme="historia"] .knowledge-icon {
  color: #fff4cf !important;
  background: linear-gradient(145deg, #a77b42, #65401f) !important;
}
#knowledge-screen .parchment-button { margin-left: auto; margin-right: 0; }

@media (max-width: 760px) {
  #book-progress { min-width: 214px; }
  .codex-button { min-width: 61px; height: 34px; padding: 0 8px; font-size: 9px; }
  .codex-list { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .codex-book:last-child { grid-column: 1 / -1; min-height: 112px; }
}

@media (max-height: 540px) and (orientation: landscape) {
  .parchment-panel,
  #knowledge-screen .knowledge-panel {
    max-height: calc(100dvh - 8px);
    padding: 15px 20px 16px;
  }
  .codex-ribbon { margin-bottom: 3px; padding: 4px 13px; font-size: 8px; }
  .codex-panel h2 { margin: 3px 0; font-size: 27px; }
  .codex-intro { margin-bottom: 8px; font-size: 11px; line-height: 1.3; }
  .codex-list {
    grid-template-columns: repeat(5, minmax(92px, 1fr));
    gap: 7px;
    margin: 8px 0 10px;
  }
  .codex-book,
  .codex-book:last-child {
    grid-column: auto;
    min-height: 92px;
    padding: 7px 5px;
    gap: 3px;
  }
  .codex-book-icon { width: 34px; height: 34px; border-radius: 10px; font-size: 18px; }
  .codex-book-name { min-height: 25px; font-size: 11px; }
  .codex-book small { font-size: 7px; }
  .parchment-button { min-height: 36px; padding: 0 18px; font-size: 9px; }
  #knowledge-screen .knowledge-panel h2 { font-size: 27px; }
  #knowledge-screen .knowledge-return { margin-top: 9px; font-size: 12px; line-height: 1.3; }
  #knowledge-screen .knowledge-examples { margin: 7px 0; }
  #knowledge-screen .knowledge-example { padding: 5px 7px; font-size: 10px; }
  #knowledge-screen .knowledge-mission { margin: 5px 0 7px; padding: 6px 8px; font-size: 10px; }
}


/* ===== Versão 26: diálogo final com o Mago Preguiça ===== */
.final-dialogue-overlay {
  z-index: 37;
  align-items: flex-end;
  padding: clamp(18px, 4vh, 42px) clamp(14px, 4vw, 48px);
  background: linear-gradient(to top, rgba(10, 12, 15, .84), rgba(10, 12, 15, .18) 58%, rgba(10, 12, 15, .04));
}
.final-dialogue-panel {
  width: min(760px, 100%);
  min-height: 230px;
  margin: 0 auto;
  padding: clamp(22px, 4vw, 34px);
  text-align: left;
  border-radius: 7px 22px 7px 22px !important;
}
.final-dialogue-heading {
  width: max-content;
  max-width: 100%;
  margin: -44px auto 16px;
  padding: 9px 22px;
  border: 1px solid #6d481a;
  border-radius: 4px 12px 4px 12px;
  background: linear-gradient(180deg, #9a6a29, #684217);
  color: #fff0c8;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .16em;
  text-align: center;
  box-shadow: 0 7px 18px rgba(34, 21, 8, .3);
}
.final-dialogue-character {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 15px;
}
.final-dialogue-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 2px solid rgba(91, 61, 24, .6);
  border-radius: 50%;
  background: rgba(113, 77, 31, .15);
  font-size: 30px;
}
.final-dialogue-character small {
  display: block;
  color: #7d5723;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
}
.final-dialogue-character h2 {
  margin: 2px 0 0;
  color: #352515;
  font: 900 clamp(22px, 4vw, 34px)/1 Georgia, serif;
}
.final-dialogue-text {
  min-height: 72px;
  margin: 0 0 18px;
  color: #4c3a24;
  font: 700 clamp(15px, 2.5vw, 19px)/1.55 Georgia, serif;
}
.final-dialogue-panel .parchment-button {
  display: block;
  margin-left: auto;
}
@media (max-height: 520px) {
  .final-dialogue-overlay { padding-top: 12px; padding-bottom: 12px; }
  .final-dialogue-panel { min-height: 0; padding: 17px 20px; }
  .final-dialogue-heading { margin-top: -28px; margin-bottom: 9px; padding: 6px 16px; }
  .final-dialogue-icon { width: 44px; height: 44px; font-size: 23px; }
  .final-dialogue-text { min-height: 45px; margin-bottom: 10px; font-size: 14px; line-height: 1.35; }
}
