:root {
  --ink: #2c241c;
  --paper: #f3ead6;
  --gold: #c9a24f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1612; font-family: var(--serif); color: var(--ink); user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; }
.hidden { display: none !important; }

#title { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 7vh; pointer-events: none; transition: opacity 1.4s; }
#title.gone { opacity: 0; }
#title h1 { margin: 0; font-size: clamp(36px, 6vw, 84px); font-weight: 400; letter-spacing: 0.08em; color: #f6e7c4; text-shadow: 0 2px 18px rgba(0,0,0,.65); font-style: italic; }
#title .sub { margin: 4px 0 18px; font-size: clamp(14px, 1.6vw, 20px); color: #e8d8b4; opacity: .85; font-style: italic; text-shadow: 0 1px 8px rgba(0,0,0,.7); }
#title .cta { margin: 0; font-size: 15px; color: #f3e3bc; letter-spacing: .12em; text-transform: uppercase; animation: breathe 2.8s ease-in-out infinite; text-shadow: 0 1px 8px rgba(0,0,0,.8); }
@keyframes breathe { 50% { opacity: .35; } }

#skip { position: fixed; right: 22px; bottom: 18px; font-size: 13px; color: #f3e3bc; opacity: .6; letter-spacing: .1em; text-shadow: 0 1px 6px rgba(0,0,0,.8); }

#hud { position: fixed; left: 22px; top: 18px; pointer-events: none; }
#objective { font-size: 18px; font-style: italic; color: #2c241c; background: rgba(243,234,214,.72); padding: 6px 14px; border-radius: 2px; box-shadow: 0 2px 10px rgba(60,40,20,.18); }
#senses { margin-top: 6px; font-size: 13px; color: #3b3025; opacity: .8; padding-left: 4px; text-shadow: 0 0 6px rgba(255,248,230,.9); }

#controls { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); font-size: 13px; color: #3b3025; background: rgba(243,234,214,.75); padding: 7px 16px; border-radius: 2px; width: max-content; max-width: 92vw; text-align: center; line-height: 1.6; pointer-events: none; animation: fadein 1s; }
#controls b { font-weight: 600; }

#prompt { position: fixed; left: 50%; top: 62%; transform: translateX(-50%); font-size: 16px; color: #2c241c; background: rgba(243,234,214,.85); padding: 5px 14px; border-radius: 2px; pointer-events: none; font-style: italic; }
kbd { font-family: var(--serif); font-style: normal; font-weight: 700; border: 1px solid #6b5a44; border-radius: 3px; padding: 0 6px; margin-right: 4px; background: #fffaf0; }

#toast { position: fixed; left: 50%; top: 14%; transform: translate(-50%, -8px); max-width: 80vw; text-align: center; font-size: 16px; font-style: italic; color: #2c241c; background: rgba(243,234,214,.85); padding: 7px 18px; border-radius: 2px; opacity: 0; transition: opacity .5s, transform .5s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#card { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.96); text-align: center; background: var(--paper); border: 2px solid var(--gold); outline: 1px solid var(--gold); outline-offset: 4px; padding: 22px 38px; box-shadow: 0 10px 40px rgba(40,25,10,.35); opacity: 0; transition: opacity .7s, transform .7s; pointer-events: none; }
#card.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#card .k { font-size: 12px; letter-spacing: .2em; text-transform: uppercase; opacity: .6; }
#card .n { font-size: 30px; margin: 6px 0; font-style: italic; }
#card .t { font-size: 15px; opacity: .85; }

#dialogue { position: fixed; left: 50%; bottom: 7vh; transform: translateX(-50%); width: min(640px, 90vw); background: var(--paper); border: 1px solid #8a7354; box-shadow: 0 8px 30px rgba(40,25,10,.3); padding: 14px 20px 12px; }
#dialogue .who { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; opacity: .55; margin-bottom: 6px; }
#dialogue .line { font-size: 20px; min-height: 28px; font-style: italic; }
#dialogue .choices { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
#dialogue .choices button { font-family: var(--serif); font-size: 15px; background: #fffaf0; border: 1px solid #8a7354; padding: 5px 14px; cursor: pointer; color: var(--ink); }
#dialogue .choices button:hover { background: #f0dfbd; }
#dialogue .next { text-align: right; font-size: 12px; opacity: .5; }

#journal { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, 92vw); max-height: 80vh; overflow: auto; background: var(--paper); border: 1px solid #8a7354; padding: 26px 34px; box-shadow: 0 14px 50px rgba(30,20,10,.45);
  background-image: repeating-linear-gradient(transparent 0 27px, rgba(120,100,70,.18) 27px 28px); }
#journal h2 { margin: 0; font-weight: 400; font-style: italic; font-size: 30px; }
#journal h3 { margin: 18px 0 6px; font-weight: 400; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; opacity: .6; }
#journal .hint { margin: 2px 0 14px; opacity: .6; font-style: italic; }
#journal ul { margin: 0; padding-left: 18px; }
#journal li { font-size: 17px; line-height: 28px; font-style: italic; }
#journal li.unk { list-style: none; opacity: .4; }
#journal .close { text-align: right; opacity: .4; font-size: 12px; margin: 14px 0 0; }

#epilogue { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
#epilogue p { font-size: clamp(22px, 3vw, 36px); font-style: italic; color: #f6e7c4; text-shadow: 0 2px 16px rgba(0,0,0,.8); animation: fadein 1.2s; margin: 0; }
@keyframes fadein { from { opacity: 0; } }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: #e8d8b4; font-style: italic; font-size: 20px; background: #1b1612; }

/* ---------- reloj de cuenta regresiva ---------- */
#clock { position: fixed; right: 22px; top: 18px; width: 92px; text-align: center; pointer-events: none; }
#clock.in { animation: clockin .8s cubic-bezier(.2,1.6,.4,1); }
#clock svg { width: 92px; height: 92px; filter: drop-shadow(0 3px 8px rgba(40,25,10,.35)); }
#clock .face { fill: #f4ecd8; stroke: #b08a3a; stroke-width: 3; }
#clock .tick { stroke: #3b3025; stroke-width: 1.4; }
#clock .hand { stroke: #2a2420; stroke-linecap: round; }
#clock .hub { fill: #b08a3a; }
#clock .num { margin-top: 2px; font-size: 26px; font-style: italic; color: #2c241c; text-shadow: 0 0 8px rgba(255,248,230,.95); }
#clock .num.jolt { animation: jolt .25s; }
#clock.late .num { color: #8a2a22; }
#clock.late svg { animation: tremble .12s infinite; }
#clock.ring svg { animation: tremble .05s infinite; }
#clock.ring .num { font-size: 34px; color: #8a2a22; }
@keyframes clockin { from { transform: scale(.2) rotate(-90deg); opacity: 0; } }
@keyframes jolt { 40% { transform: translateY(-3px) rotate(-4deg); } }
@keyframes tremble { 25% { transform: rotate(2deg); } 75% { transform: rotate(-2deg); } }

/* ---------- pausa desobediente ---------- */
#pause { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(40,28,18,.35); }
#pause .panel { position: relative; width: min(420px, 90vw); background: var(--paper); border: 2px solid var(--gold); outline: 1px solid var(--gold); outline-offset: 5px; padding: 24px 30px 18px; text-align: center; box-shadow: 0 16px 50px rgba(30,20,10,.45); transform: rotate(-1.2deg); }
#pause .panel.shake { animation: shake .4s; }
#pause h2 { margin: 0; font-weight: 400; font-style: italic; font-size: 34px; }
#pause .sub { margin: 4px 0 16px; font-style: italic; opacity: .6; }
#pause .buttons { display: flex; flex-direction: column; gap: 8px; align-items: center; }
#pause button { font-family: var(--serif); font-size: 18px; min-width: 190px; padding: 7px 18px; background: #fffaf0; border: 1px solid #8a7354; color: var(--ink); cursor: pointer; transition: transform .25s cubic-bezier(.3,1.6,.5,1), background .2s; }
#pause button:hover { background: #f0dfbd; }
#pause button.painted { cursor: default; background: repeating-linear-gradient(-12deg, #efe2c4 0 6px, #e6d4b0 6px 9px); border: 2px solid #6b5a44; border-radius: 3px 9px 4px 11px; font-style: italic; transform: rotate(1.5deg); }
#pause button.painted:hover { background: repeating-linear-gradient(-12deg, #efe2c4 0 6px, #e6d4b0 6px 9px); }
#pause button.shrink { transform: scale(.55); }
#pause button.fall { animation: fall .9s ease-in forwards; }
#pause .options { display: flex; flex-direction: column; gap: 10px; align-items: stretch; text-align: left; }
#pause .options label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 17px; }
#pause .options label.dis { opacity: .5; }
#pause .options i { font-size: 12px; }
#pause .options button { align-self: center; margin-top: 6px; }
#pause .foot { min-height: 22px; margin: 14px 0 0; font-style: italic; opacity: .8; }
#pause .foot.pop { animation: jolt .3s; }
@keyframes shake { 20% { transform: translateX(-8px) rotate(-2deg); } 40% { transform: translateX(7px) rotate(1deg); } 60% { transform: translateX(-5px) rotate(-1.5deg); } 80% { transform: translateX(3px); } }
@keyframes fall { to { transform: translateY(420px) rotate(38deg); opacity: 0; } }
#pocket { margin-top: 3px; font-size: 13px; color: #3b3025; opacity: .8; padding-left: 4px; font-style: italic; text-shadow: 0 0 6px rgba(255,248,230,.9); max-width: 60vw; }

/* ---------- celular / táctil ---------- */
html, body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#game { touch-action: none; }
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#touch.off > * { display: none; }
#touch.intro > *:not(#tJump) { display: none; }
#tStickZone { position: absolute; left: 0; bottom: 0; width: 45%; height: 65%; pointer-events: auto; touch-action: none; }
#tStick { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(243,234,214,.22); border: 2px solid rgba(243,234,214,.55); }
#tStick .knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(243,234,214,.85); box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.tbtn { position: absolute; pointer-events: auto; touch-action: none; font-family: var(--serif); font-style: italic; color: #2c241c; background: rgba(243,234,214,.82); border: 2px solid rgba(138,115,84,.8); border-radius: 50%; box-shadow: 0 3px 10px rgba(30,20,10,.3); user-select: none; -webkit-user-select: none; }
.tbtn.on { transform: scale(.92); background: rgba(240,223,189,.95); }
.tbtn.big { right: max(22px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom)); width: 92px; height: 92px; font-size: 17px; }
.tbtn.act { right: calc(max(22px, env(safe-area-inset-right)) + 104px); bottom: max(38px, env(safe-area-inset-bottom)); width: 76px; height: 76px; font-size: 13px; line-height: 1.1; padding: 4px; }
.tbtn.act.dim { opacity: .45; }
.tbtn.small { top: max(14px, env(safe-area-inset-top)); width: 44px; height: 44px; font-size: 18px; font-style: normal; }
#tPause { right: max(16px, env(safe-area-inset-right)); }
#tBook { right: calc(max(16px, env(safe-area-inset-right)) + 54px); }
#tRotate { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(243,234,214,.9); padding: 10px 16px; font-style: italic; border-radius: 2px; pointer-events: none; text-align: center; }
body.touch #prompt kbd { display: none; }
body.touch #clock { right: 120px; transform: scale(.75); transform-origin: top right; }
body.touch #controls { bottom: auto; top: 60px; white-space: normal; font-size: 12px; }
@media (max-height: 500px) {
  #dialogue { bottom: 10px; padding: 8px 14px; }
  #dialogue .line { font-size: 16px; }
  #title h1 { font-size: 40px; }
  #journal { max-height: 90vh; padding: 14px 20px; }
  #pause .panel { padding: 12px 20px; }
  #pause button { padding: 4px 14px; font-size: 15px; }
  #card { padding: 12px 22px; }
}
body.touch #dialogue { left: max(14px, env(safe-area-inset-left)); transform: none; width: auto; right: 250px; max-width: 640px; }
body.touch #controls { font-size: 11px; padding: 5px 12px; }
body.touch #prompt { top: auto; bottom: 140px; }
@media (max-width: 600px) { body.touch #dialogue { right: 14px; bottom: 140px; } }
body.touch #prompt { display: none !important; }
/* los paneles de la interfaz siempre por encima de los controles táctiles */
#dialogue, #journal, #pause, #epilogue, #card { z-index: 10; }
/* mientras hay diálogo o cuaderno, el joystick no captura toques */
#touch.busy #tStickZone { display: none; }

/* ---------- minijuego de la cuerda ---------- */
#stringGame { position: fixed; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center; background: rgba(30,20,12,.55); touch-action: none; }
#stringGame .sg-panel { width: min(760px, 94vw); background: var(--paper); border: 2px solid var(--gold); outline: 1px solid var(--gold); outline-offset: 4px; padding: 14px 18px 12px; box-shadow: 0 14px 50px rgba(20,10,5,.5); }
#stringGame .sg-title { font-style: italic; font-size: 24px; margin-bottom: 8px; text-align: center; }
#stringGame canvas { width: 100%; height: auto; display: block; background: #2a1d14; border-radius: 3px; }
#stringGame .sg-info { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-style: italic; font-size: 15px; }
#stringGame .sg-hint { opacity: .65; text-align: right; }
@media (max-height: 500px) { #stringGame .sg-title { font-size: 18px; margin-bottom: 4px; } #stringGame .sg-panel { padding: 8px 12px; } }
