:root {
  color-scheme: dark;
  --bg: #16241a;
  --panel: #213528;
  --panel-2: #2c4635;
  --text: #eef7ee;
  --muted: #9dbba4;
  --accent: #ffd23f;
  --wall: #8a5a33;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Encabezado y barra de puntos ---------- */

header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px 2px;
}
.back { color: var(--muted); text-decoration: none; font-size: 15px; padding: 6px 0; }
header h1 { margin: 0; font-size: 22px; letter-spacing: .06em; }
.tools { margin-left: auto; display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; font-size: 18px; background: transparent; }
.icon-btn.off { opacity: .3; }

.bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 4px 16px 6px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.stat { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat.muted { color: var(--muted); font-size: 18px; }
.pause-btn { margin-left: auto; width: 48px; height: 40px; font-size: 18px; }

/* ---------- Tablero ---------- */

.game {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 12px 10px;
}
.well {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  touch-action: none; /* deslizar el dedo mueve la víbora, no la página */
}
#board {
  display: block;
  border-radius: 12px;
  box-shadow: 0 0 0 4px var(--panel-2), 0 14px 32px rgba(0, 0, 0, .45);
}
.well.walls #board { box-shadow: 0 0 0 6px var(--wall), 0 14px 32px rgba(0, 0, 0, .45); }
.well.shake #board { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.keys { color: var(--muted); font-size: 13px; text-align: center; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--text);
  font: 600 11px/1.5 ui-monospace, Menlo, monospace;
}

/* ---------- Carteles ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.overlay[hidden] { display: none; }
.card {
  width: min(100%, 320px);
  max-height: 100%;
  overflow-y: auto;
  background: rgba(22, 36, 26, .95);
  border: 2px solid var(--panel-2);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.card h2 { margin: 0; font-size: 26px; }
.card p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.4; }
.card .big-score { font-size: 40px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; }
.card h3 { margin: 2px 0 -4px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.options { display: flex; flex-direction: column; gap: 6px; }
.options.row { flex-direction: row; }
.options.row button { flex: 1; }
.options button {
  padding: 10px;
  font-size: 16px;
  font-weight: 700;
  border: 2px solid transparent;
  text-align: left;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.options.row button { justify-content: center; }
.options button small { color: var(--muted); font-weight: 600; font-size: 13px; align-self: center; }
.options button.active { border-color: var(--accent); background: #3b4a2c; }
.primary {
  padding: 14px;
  font-size: 20px;
  font-weight: 800;
  background: var(--accent);
  color: #2a2200;
}
.secondary { padding: 10px; font-size: 16px; font-weight: 700; }

/* ---------- Flechas táctiles ---------- */

.dpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 92px));
  grid-template-areas: ". up ." "left down right";
  justify-content: center;
  gap: 8px;
  padding: 4px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}
.dpad button {
  height: clamp(52px, 8.5vh, 70px);
  font-size: 26px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .3);
}
.dpad .up { grid-area: up; }
.dpad .left { grid-area: left; }
.dpad .down { grid-area: down; }
.dpad .right { grid-area: right; }
.dpad button.pressed { transform: translateY(2px); box-shadow: none; background: var(--panel-2); }

@media (hover: hover) and (pointer: fine) {
  .dpad { display: none; }
}
@media not ((hover: hover) and (pointer: fine)) {
  .keys { display: none; }
}

/* ---------- Celular horizontal: flechas a la derecha ---------- */

@media (max-height: 500px) and (orientation: landscape) {
  header { display: none; }
  .bar { position: fixed; top: 6px; left: 12px; width: auto; flex-direction: column; align-items: flex-start; gap: 6px; padding: 0; z-index: 2; }
  .pause-btn { margin-left: 0; }
  .game { padding-top: 8px; }
  .dpad {
    position: fixed;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 0;
    grid-template-columns: repeat(3, 60px);
  }
  .dpad button { height: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  .well.shake #board { animation: none; }
}
