@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..700;1,9..144,300..700&family=Inter:wght@300;400;500;700&display=swap');

:root {
  --bg: #f8f2e7;
  --card: #fffaf0;
  --ink: #2b1a0e;
  --muted: #6d5945;
  --primary: #2b1a0e;
  --primary-soft: #eadfca;
  --accent: #b06a2e;
  --border: #ddd0b6;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(30, 34, 53, .10);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior: none;
}
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 720px; margin: 0 auto; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 8px;
}
.title-wrap h1 { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 500; margin: 0; letter-spacing: 0; }
.badge-3d {
  background: var(--accent); color: #fff; font-size: 11px; padding: 2px 7px;
  border-radius: 999px; vertical-align: 3px; font-weight: 700;
}
.level-badge {
  font-size: 15px; color: var(--muted); margin-top: 2px; font-weight: 600;
  cursor: pointer; user-select: none; display: inline-block; padding: 2px 6px;
  border-radius: 8px; background: var(--primary-soft);
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.btn-home { min-width: 88px; min-height: 48px; padding: 11px 14px; font-size: 17px; }
.btn-home span { margin-left: 3px; }
@media (max-width: 430px) {
  #topbar { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .title-wrap h1 { font-size: 19px; }
  .top-actions { gap: 5px; }
  .top-actions .btn { padding: 11px 10px; min-height: 46px; }
  .btn-home { min-width: 52px; }
  .btn-home span { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
}

.btn {
  border: none; border-radius: 12px; padding: 13px 17px; font-size: 17px; font-weight: 700;
  font-family: inherit; cursor: pointer; color: var(--ink); background: var(--card);
  box-shadow: 0 2px 8px rgba(30,34,53,.08); transition: transform .06s ease, background .15s;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary.active { background: var(--ok); }
.btn-ghost { background: var(--card); }
.btn.big { font-size: 19px; padding: 16px 20px; width: 100%; }

#board-wrap { position: relative; flex: 1; min-height: 300px; }
#canvas-wrap { position: absolute; inset: 0; }
#scene { width: 100%; height: 100%; display: block; touch-action: none; }

.dir-pad {
  display: flex; gap: 10px; justify-content: center; padding: 4px 14px 8px; background: var(--bg);
}
.dir-btn {
  width: 64px; height: 46px; border: none; border-radius: 10px; background: var(--card); color: var(--ink);
  font-size: 20px; font-weight: 800; box-shadow: 0 2px 8px rgba(30,34,53,.15); cursor: pointer;
  touch-action: manipulation;
}
.dir-btn:active { transform: scale(.93); }

#grid2d-wrap {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 8px; background: var(--bg);
}
#grid2d { display: grid; gap: 4px; }
.cell2d {
  width: 100%; aspect-ratio: 1; border: none; border-radius: 8px; background: var(--card);
  font-size: clamp(19px, 5.5vw, 28px); font-weight: 800; color: var(--ink);
  box-shadow: inset 0 0 0 1.5px #e5e7eb; cursor: pointer; touch-action: manipulation;
}
.cell2d.sel { box-shadow: inset 0 0 0 2.5px var(--primary); background: var(--primary-soft); }
.cell2d.conflict { color: var(--bad); background: var(--bad-soft); }
.clue2d {
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(15px, 4.5vw, 22px); font-weight: 800; color: var(--muted);
  width: 100%; aspect-ratio: 1;
  user-select: none;
}
#grid2d.checking .clue2d:not(.off) { animation: clue-pulse 1.5s ease-in-out infinite; }
@keyframes clue-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.clue2d.ok { color: #16a34a; }
.clue2d.bad { color: #dc2626; }
.clue2d.off { color: #c3c9d6; }

#panel {
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 24px rgba(30,34,53,.10);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
#sel-info { text-align: center; font-size: 15px; color: var(--muted); font-weight: 600; min-height: 18px; }
#height-row { display: flex; gap: 8px; justify-content: center; margin: 8px 0 10px; flex-wrap: wrap; }
.hbtn {
  width: 56px; height: 62px; border: none; border-radius: 14px; font-size: 24px; font-weight: 800;
  font-family: inherit; color: #fff; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,.18);
  touch-action: manipulation; transition: transform .06s ease;
}
.hbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.hbtn.erase { background: #9ca3af !important; font-size: 18px; }
.hbtn:disabled { opacity: .35; }
#actions-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#actions-row .btn { font-size: 16px; padding: 11px 14px; }

#toast {
  position: fixed; left: 50%; bottom: 180px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: 16px; font-weight: 600; box-shadow: var(--shadow); z-index: 30;
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

#overlay, #help-modal, #level-modal, #pdf-modal {
  position: fixed; inset: 0; background: rgba(30,34,53,.45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 24px;
}
.card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 26px 22px; max-width: 420px; width: 100%; text-align: center;
  max-height: 85dvh; overflow-y: auto;
}
.card h2 { margin: 0 0 10px; }
.card p { color: var(--muted); font-size: 17px; line-height: 1.55; text-align: left; }
#overlay .card p { text-align: center; }
.overlay-emoji { font-size: 52px; margin-bottom: 6px; }
.card .btn.big { margin-top: 14px; }

.hidden { display: none !important; }

/* ocultar el banner 'Open Sandbox' de la vista previa de CodeSandbox */
iframe[id^="sb__open-sandbox"] { display: none !important; }

.modal-hint { text-align: center !important; font-size: 13px !important; }
#level-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; max-height: 50dvh; overflow-y: auto; }
.level-btn { width: 100%; }
.level-btn.current { background: var(--primary); color: #fff; }
#pdf-sizes { display: flex; gap: 8px; justify-content: center; margin: 10px 0; }
#pdf-sizes .btn { min-width: 62px; }
#pdf-sizes .btn.sel { background: var(--primary); color: #fff; }
#pdf-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; text-align: left; }
.pdf-item { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; color: var(--ink);
  background: var(--bg); border-radius: 10px; padding: 9px 10px; cursor: pointer; }
.pdf-item input { width: 18px; height: 18px; accent-color: var(--primary); }
#pdf-modal .btn.big { margin-top: 8px; }
#pdf-all { width: 100%; margin-bottom: 2px; }

.clue2d.empty { background: transparent; box-shadow: none; cursor: default; animation: none !important; }
.cell2d.seen2d { background: #fef3c7; box-shadow: inset 0 0 0 2.5px #f59e0b; }
.level-btn { background: var(--bg); }
.level-btn.current { background: var(--primary); }

/* captura de email post-partida (SendFox) */
.email-sep { border: none; border-top: 2px solid var(--bg); margin: 18px 0 12px; }
.email-title { text-align: center !important; font-weight: 700; color: var(--ink) !important; font-size: 17px !important; }
.email-note { text-align: center !important; font-size: 14px !important; margin-top: 10px; }

/* pantalla de inicio */
#start-screen { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f1e9d8 0%, #f8f2e7 70%); padding: 20px; }
#start-screen .card { max-width: 340px; }
#start-screen h2 { margin: 0 0 6px; font-size: 28px; }
#start-screen p { margin: 0 0 16px; color: var(--muted); font-size: 17px; text-align: center; }
.size-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.size-grid .btn { font-size: 22px; padding: 18px 0; }
#btn-continue { width: 100%; font-size: 17px; padding: 14px 0; }



/* Prueba visual de la suite Gimnasia Mental: solo envoltorio.
   Los colores de los edificios (.hbtn y escena 3D) se conservan intactos. */
#topbar { border-bottom: 1px solid var(--border); }
.badge-3d { letter-spacing: .8px; }
.level-badge { color: var(--accent); background: transparent; padding-left: 0; }
.btn { border: 1px solid var(--border); box-shadow: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #f8f2e7; border-radius: 999px; }
.btn-ghost { background: var(--card); }
.top-actions .btn { border-radius: 999px; }
.btn-home { color: var(--accent); border-color: var(--accent); }
.dir-btn { background: var(--card); color: var(--ink); border: 1px solid var(--border); box-shadow: none; border-radius: 999px; }
#panel { border-top: 1px solid var(--border); box-shadow: 0 -8px 28px rgba(43,26,14,.06); }
.card { border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 40px rgba(43,26,14,.10); }
.card h2 { font-family: 'Fraunces', serif; font-weight: 500; color: var(--ink); }
#start-screen .card { padding: 32px 24px 26px; }
#start-screen .card::before { content: 'NACHO RUIZ · TÉCNICAS VÉDICAS'; display: block; margin-bottom: 20px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 2px; }
#start-screen h2 { font-family: 'Fraunces', serif; font-size: 36px; font-weight: 500; }
#start-screen p { color: var(--muted); }
.size-grid .btn { border-radius: 999px; }
.cell2d { border: 1px solid var(--border); box-shadow: none; }
.cell2d.sel { box-shadow: inset 0 0 0 2px var(--accent); }
#grid2d-wrap { background: var(--bg); }
@media (max-width: 430px) {
  .title-wrap h1 { font-size: 20px; }
  #start-screen .card { padding: 28px 20px 22px; }
  #start-screen h2 { font-size: 34px; }
}

/* ===== Paleta de marca: Burdeos y oro (día) + Negro y oro (noche) ===== */
:root {
  --bg: #fcf6f1; --card: #fffdfb; --ink: #2a1320; --muted: #6b5560;
  --primary: #8c1c40; --onPrimary: #fff8f2; --primary-soft: #f4e6e2;
  --accent: #8c1c40; --gold: #f2b233; --border: #e8d6d3;
  --ok: #16a34a; --ok-soft: #dcfce7; --bad: #b3261e; --bad-soft: #fbe3e0;
  --cellEdge: #e8d6d3; --clueOff: #c9b3b9; --seenBg: #fdf0d2; --seenRing: #f2b233;
  --scrim: rgba(42,19,32,.5); --startGrad: linear-gradient(160deg, #f4e6e2 0%, #fcf6f1 70%);
  --shadow: 0 6px 24px rgba(42,19,32,.10);
  color-scheme: light;
}
:root[data-theme="night"] {
  --bg: #26221d; --card: #322d27; --ink: #f3ede2; --muted: #c9bfaf;
  --primary: #d9ae4a; --onPrimary: #26221d; --primary-soft: #3e3830;
  --accent: #d9ae4a; --gold: #d9ae4a; --border: #4d463c;
  --ok: #4ade80; --ok-soft: #173222; --bad: #f08a7e; --bad-soft: #3a1d1a;
  --cellEdge: #4d463c; --clueOff: #756b5e; --seenBg: #4a3b1c; --seenRing: #d9ae4a;
  --scrim: rgba(8,7,6,.7); --startGrad: linear-gradient(160deg, #322d27 0%, #26221d 70%);
  --shadow: 0 6px 24px rgba(0,0,0,.4);
  color-scheme: dark;
}
.badge-3d { background: var(--gold); color: #2a1320; }
.btn-primary, .btn-primary.big, .level-btn.current, #pdf-sizes .btn.sel { background: var(--primary); border-color: var(--primary); color: var(--onPrimary); }
:root:not([data-theme="night"]) .btn-primary { box-shadow: inset 0 0 0 2px var(--gold); }
.btn-primary.active { background: var(--ok); border-color: var(--ok); }
.cell2d { box-shadow: none; border-color: var(--cellEdge); }
.cell2d.sel { box-shadow: inset 0 0 0 2.5px var(--gold); background: var(--primary-soft); }
.cell2d.seen2d { background: var(--seenBg); box-shadow: inset 0 0 0 2.5px var(--seenRing); }
.clue2d.ok { color: var(--ok); } .clue2d.bad { color: var(--bad); } .clue2d.off { color: var(--clueOff); }
.hbtn.erase { background: var(--muted) !important; color: var(--bg); }
#toast { background: var(--ink); color: var(--bg); }
#overlay, #help-modal, #level-modal, #pdf-modal { background: var(--scrim); }
#start-screen { background: var(--startGrad); }
#panel { box-shadow: 0 -8px 28px rgba(42,19,32,.06); }
.card { box-shadow: var(--shadow); }
.theme-btn { font-size: 18px; line-height: 1; }
#start-screen .theme-btn { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
@media (max-width: 430px) {
  #btn-full { display: none; }
  .top-actions .theme-btn { padding: 11px 12px; }
}
@media (max-width: 430px) {
  .title-wrap { min-width: 0; }
  .title-wrap h1 { white-space: nowrap; }
  .top-actions .btn { white-space: nowrap; }
  .top-actions .theme-btn, #btn-help { padding: 11px 9px; min-width: 40px; }
  .top-actions { gap: 4px; }
}


/* The suite uses one Fraunces face across the start, game, and overlay headings. */
.title-wrap h1,#start-screen h2,.card h2{font-family:"Fraunces",Georgia,serif;font-weight:500}

/* Narrow phones: reserve a full title row above the controls. */
@media(max-width:390px){
 #topbar{position:relative;display:block;min-height:84px;padding:8px 10px 7px}
 .title-wrap{width:100%;min-width:0}
 .title-wrap h1{font-size:19px;white-space:nowrap;margin:0 0 2px}
 .title-wrap .level-badge{font-size:13px;margin:0}
 .top-actions{position:absolute;right:10px;bottom:7px;gap:4px}
 .top-actions .btn{min-height:34px;height:34px;padding:5px 7px;font-size:13px;border-radius:18px}
 .top-actions .theme-btn,#btn-help{min-width:34px;padding:5px 7px}
 .btn-home{min-width:34px}
}



/* Keep Rascacielos's own visual language; trial a centered heading only. */
#topbar{position:relative;display:block;min-height:115px;padding:10px 12px 42px;text-align:center}
#topbar .title-wrap{width:100%;min-width:0;margin:0 auto;text-align:center}
#topbar .title-wrap h1{font-size:clamp(21px,6vw,27px);white-space:nowrap;line-height:1.15;margin:0 auto 5px}
#topbar .title-wrap .level-badge{font-size:12px;margin:0 auto;text-align:center}
#topbar .top-actions{position:absolute;left:50%;right:auto;bottom:5px;transform:translateX(-50%);display:flex;justify-content:center;gap:4px;white-space:nowrap}
#topbar .top-actions .btn{min-height:34px;height:34px;padding:5px 7px;font-size:12px;border-radius:18px}
#topbar .top-actions .theme-btn,#topbar #btn-help{min-width:34px}
