:root {
  --red: #D62828;
  --yellow: #F9C80E;
  --green: #2A9D3F;
  --blue14: #4CC9F0;
  --gold: #FFD166;
  --ui: #1B1B2F;
  --ui2: #27274a;
  --text: #f4f1ea;
  --muted: #b8b5c9;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs: 16px;
}
html[data-text="small"] { --fs: 13px; }
html[data-text="large"] { --fs: 19px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; background: #0d0d18; overflow: hidden; font-family: var(--font); font-size: var(--fs); color: var(--text); touch-action: none; user-select: none; -webkit-user-select: none; }

#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #0d0d18; }
#game { display: block; image-rendering: pixelated; image-rendering: crisp-edges; background: #1B1B2F; max-width: 100%; max-height: 100%; }

/* ===== Telas ===== */
#screens { position: absolute; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; pointer-events: auto; padding: 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); overflow-y: auto; background: rgba(13,13,24,0.72); backdrop-filter: blur(2px); }
.screen.active { display: flex; }
#screen-menu { background: transparent; justify-content: flex-start; padding-top: 2vh; }

.panel { background: var(--ui); border: 3px solid var(--yellow); border-radius: 14px; padding: 20px 24px; max-width: 720px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.6); max-height: 94vh; overflow-y: auto; }
.panel.narrow { max-width: 460px; }
.panel.wide { max-width: 900px; }
.panel h2 { margin: 0 0 10px; color: var(--yellow); letter-spacing: 1px; }
.panel h3 { margin: 10px 0 6px; color: var(--gold); }
.panel p { margin: 6px 0 10px; line-height: 1.4; }
.panel ul { margin: 4px 0 10px; padding-left: 20px; line-height: 1.5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.big { font-size: 2.2em; margin: 0 0 6px; }
.red { color: var(--red); text-shadow: 2px 2px 0 #000; }
.gold { color: var(--gold); text-shadow: 2px 2px 0 #000; }
.f22 { color: var(--green); }
.f14 { color: var(--blue14); }

.title-block { text-align: center; margin-top: 1vh; }
.title { font-size: clamp(26px, 6vw, 58px); margin: 0; line-height: 1; color: var(--yellow); text-shadow: 4px 4px 0 var(--red), 7px 7px 0 #000; letter-spacing: 2px; }
.title span { color: #fff; }
.subtitle { color: var(--text); font-style: italic; margin: 10px 0 14px; text-shadow: 1px 1px 0 #000; font-size: clamp(13px, 2.2vw, 20px); }

.menu { display: grid; grid-template-columns: repeat(2, minmax(150px, 220px)); gap: 8px; }
.menu-footer { margin-top: 10px; display: flex; gap: 14px; align-items: center; }

.btn { font: inherit; font-weight: 700; letter-spacing: 1px; color: #fff; background: var(--ui2); border: 2px solid var(--yellow); border-radius: 10px; padding: 10px 16px; cursor: pointer; width: 100%; margin: 4px 0; transition: transform .08s, background .12s; text-shadow: 1px 1px 0 #000; }
.btn:hover { background: #343468; transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--yellow); }
.btn.primary:hover { background: #f03a3a; }
.btn.small { padding: 6px 10px; font-size: .85em; width: auto; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--red); }
.row .btn { width: auto; min-width: 160px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.level-card { background: var(--ui2); border: 2px solid #444; border-radius: 10px; padding: 10px; cursor: pointer; text-align: left; font: inherit; color: var(--text); }
.level-card.done { border-color: var(--green); }
.level-card.unlocked { border-color: var(--yellow); }
.level-card.locked { opacity: .45; cursor: not-allowed; }
.level-card b { display: block; color: var(--gold); }
.level-card span { font-size: .8em; color: var(--muted); }

.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.shop-item { background: var(--ui2); border: 2px solid #444; border-radius: 10px; padding: 10px; }
.shop-item b { color: var(--gold); }
.shop-item .lvl { color: var(--yellow); font-size: .85em; }
.shop-item p { font-size: .85em; color: var(--muted); margin: 4px 0 8px; }

.howto-pages { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.howto-page { background: var(--ui2); border-radius: 10px; padding: 10px 14px; font-size: .92em; }

.records { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.records .rec { background: var(--ui2); border-radius: 10px; padding: 10px; }
.records .rec h3 { margin: 0 0 6px; font-size: 1em; }
.records ol { margin: 0; padding-left: 22px; font-size: .9em; }
.records li span { color: var(--gold); font-family: monospace; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.ach { background: var(--ui2); border-radius: 10px; padding: 8px 10px; border-left: 4px solid #444; font-size: .88em; }
.ach.done { border-left-color: var(--gold); }
.ach.locked { opacity: .55; }
.ach b { display: block; color: var(--gold); }

.settings label { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid #333; }
.settings input[type=range] { width: 50%; }
.settings select { font: inherit; padding: 4px; border-radius: 6px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; background: var(--ui2); border-radius: 10px; padding: 10px 14px; margin: 8px 0; font-size: .95em; }
.stats div span { float: right; color: var(--gold); font-weight: 700; }
.headline { font-style: italic; color: var(--gold); background: #000; padding: 8px 10px; border-left: 4px solid var(--red); }
.headlines { background: #000; border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-family: Georgia, serif; }
.headlines div { padding: 4px 0; border-bottom: 1px dashed #444; }

#initials-input { font: inherit; font-size: 2em; text-transform: uppercase; text-align: center; width: 140px; letter-spacing: 8px; border-radius: 8px; border: 2px solid var(--yellow); background: #000; color: var(--gold); padding: 6px; }

#rotate-hint { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: rgba(0,0,0,.85); font-size: 1.4em; text-align: center; padding: 20px; pointer-events: none; z-index: 50; }

/* ===== Touch ===== */
#touch { display: none; position: absolute; inset: 0; pointer-events: none; z-index: 20; }
body.touch-mode #touch.visible { display: block; }
#touch-left { position: absolute; left: 0; top: 60px; bottom: 0; width: 48%; pointer-events: auto; }
#joystick { display: none; position: absolute; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.35); pointer-events: none; }
#joystick-knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(249,200,14,.75); border: 2px solid #fff; }
#touch-right { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: auto; }
.touch-row { display: flex; gap: 8px; }
.tbtn { width: 52px; height: 52px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); background: rgba(27,27,47,.75); color: #fff; font-size: 20px; font-weight: 700; pointer-events: auto; }
.tbtn.big { width: 86px; height: 86px; border-radius: 50%; background: rgba(214,40,40,.8); font-size: 15px; }
.tbtn.ab { width: 46px; height: 46px; font-size: 19px; position: relative; }
.tbtn.cd { opacity: .45; }
.tbtn.on { background: rgba(42,157,63,.85); border-color: #9be09f; }
.tbtn.ab.cd::after { content: attr(data-cd); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; text-shadow: 1px 1px 0 #000; background: rgba(0,0,0,.45); border-radius: 50%; }
.tbtn:active { background: rgba(249,200,14,.8); color: #000; }
#tbtn-pause { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 44px; height: 44px; font-size: 18px; }

@media (max-width: 700px) {
  .menu { grid-template-columns: 1fr 1fr; }
  .btn { padding: 8px 10px; font-size: .9em; }
  .panel { padding: 14px; }
  .stats { grid-template-columns: 1fr; }
  .big { font-size: 1.7em; }
}
@media (max-height: 460px) {
  .title-block { margin-top: 0; }
  .subtitle { margin: 4px 0 6px; }
  .menu { gap: 4px; grid-template-columns: repeat(4, 1fr); }
  .btn { padding: 6px 8px; margin: 2px 0; }
  .panel { max-height: 96vh; padding: 10px 14px; }
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-hint { display: flex; }
}
