/* Mr. Pomodoro — estilos 16 bits */
@font-face {
  font-family: 'Press Start 2P';
  src: url('../fonts/press-start-2p-latin-400-normal.woff2') format('woff2'),
       url('../fonts/press-start-2p-latin-400-normal.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --s: 0.5;
  --ctl-top: 320px;
  --col-left: 0px;
  --col-w: 340px;
  /* Paleta tomada de la ilustración */
  --sky: #00a8f9;
  --sky-dark: #007ee5;
  --cream: #fee5bc;
  --cream-2: #ffd9a0;
  --frame: #e2541f;
  --frame-dark: #9c2b10;
  --ink: #270c07;
  --tomato: #d8341f;
  --tomato-dark: #8f1a0e;
  --leaf: #58b428;
  --leaf-dark: #2a7a1c;
  --gold: #ffcc2a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--sky);
  /* Fondo escalonado para las bandas laterales (sin degradados suaves) */
  background-image: linear-gradient(to bottom,
    var(--sky-dark) 0 20%, #0a92ef 20% 40%, var(--sky) 40% 72%, #6cc23a 72% 74%, var(--leaf) 74% 100%);
  font-family: 'Press Start 2P', monospace;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font-family: inherit; color: inherit; touch-action: manipulation; }

/* ---------- Escena ---------- */
#stage {
  position: fixed; left: 0; top: 0;
  transform-origin: 0 0;
}
#scene {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
  pointer-events: none;
}

/* Interior del panel de tomates: el contador real va aquí */
.panel-inner {
  position: absolute;
  overflow: visible;
}
.status-label {
  position: absolute; left: 0; right: 0;
  top: calc(var(--s) * 10px);
  text-align: center;
  font-size: max(8px, calc(var(--s) * 19px));
  line-height: 1;
  color: var(--frame-dark);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
#clock {
  position: absolute; left: 0; right: 0;
  top: calc(var(--s) * 38px);
  height: calc(var(--s) * 112px);
  display: flex; justify-content: center;
}
#digits { height: 100%; width: auto; aspect-ratio: 34 / 10; overflow: visible; }
body[data-status="paused"] #digits { animation: pausedBlink 1.2s steps(1) infinite; }
@keyframes pausedBlink { 50% { opacity: 0.25; } }

.flash {
  position: absolute; inset: calc(var(--s) * 4px);
  background: #fff6c8;
  opacity: 0; pointer-events: none;
}
.flashing .flash { animation: flash 1s steps(2) 3; }
@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }
.status-label.blink { animation: lblBlink 0.5s steps(1) 10; color: var(--tomato); }
@keyframes lblBlink { 50% { opacity: 0; } }

.sparkles { position: absolute; inset: 0; pointer-events: none; }
.sparkles i {
  position: absolute; width: calc(var(--s) * 14px); height: calc(var(--s) * 14px);
  background: var(--gold);
  box-shadow: 0 0 0 calc(var(--s) * 4px) #fff;
  transform: scale(0);
  animation: spark 1.4s steps(4) 2 both;
}
@keyframes spark { 0% { transform: scale(0); } 40% { transform: scale(1) rotate(45deg); } 100% { transform: scale(0) rotate(90deg); } }

/* ---------- Barra superior ---------- */
#topbar {
  position: fixed; z-index: 5;
  top: calc(var(--safe-t) + 10px);
  right: calc(var(--safe-r) + 10px);
  display: flex; gap: 10px;
}
.icon-btn {
  width: 48px; height: 48px; padding: 10px;
  background: var(--cream); border: 0; cursor: pointer;
  box-shadow:
    0 0 0 3px var(--ink),
    inset -3px -4px 0 var(--cream-2),
    inset 3px 3px 0 #fff4dc,
    0 4px 0 3px var(--ink);
  margin-bottom: 4px;
}
.icon-btn svg { width: 100%; height: 100%; fill: var(--frame-dark); display: block; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 3px var(--ink), inset 3px 3px 0 var(--cream-2), 0 1px 0 3px var(--ink); }

/* ---------- Controles ---------- */
#controls {
  position: fixed; z-index: 4;
  left: 50%; top: var(--ctl-top);
  transform: translateX(-50%);
  width: min(calc(100vw - 28px - var(--safe-l) - var(--safe-r)), 400px);
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
}
body.wide #controls {
  left: calc(var(--col-left)); top: calc(50% - 40px);
  transform: translateY(-50%);
  width: calc(var(--col-w) - var(--safe-r));
}
.btn-row { display: flex; gap: 10px; justify-content: center; align-items: flex-start; }
.px-btn.icon-only { width: 60px; min-height: 60px; padding: 0; flex: none; }
.px-btn.icon-only svg { width: 22px; height: 22px; }

.px-btn {
  position: relative;
  min-height: 48px; padding: 0 14px;
  font-size: 11px; line-height: 1;
  border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--cream); color: var(--ink);
  box-shadow:
    0 0 0 3px var(--ink),
    inset -3px -4px 0 var(--cream-2),
    inset 3px 3px 0 #fff4dc,
    0 5px 0 3px var(--ink);
  margin: 3px 3px 8px;
  text-transform: uppercase;
}
.px-btn svg { width: 12px; height: 12px; fill: currentColor; }
.px-btn:active, .px-btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 0 0 3px var(--ink), inset 3px 3px 0 var(--cream-2), 0 1px 0 3px var(--ink);
}
.px-btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .step:focus-visible, .close-btn:focus-visible {
  outline: 3px dashed #fff; outline-offset: 5px;
}
.px-btn.primary {
  min-height: 60px; flex: 1; max-width: 220px; min-width: 150px;
  font-size: 18px;
  background: var(--tomato); color: #fff3dc;
  text-shadow: 2px 2px 0 var(--tomato-dark);
  box-shadow:
    0 0 0 3px var(--ink),
    inset -4px -5px 0 var(--tomato-dark),
    inset 4px 4px 0 #ff7a5a,
    0 6px 0 3px var(--ink);
}
.px-btn.primary:active { box-shadow: 0 0 0 3px var(--ink), inset 4px 4px 0 var(--tomato-dark), 0 1px 0 3px var(--ink); }
body[data-phase="short"] .px-btn.primary, body[data-phase="long"] .px-btn.primary {
  background: var(--leaf); text-shadow: 2px 2px 0 var(--leaf-dark);
  box-shadow: 0 0 0 3px var(--ink), inset -4px -5px 0 var(--leaf-dark), inset 4px 4px 0 #8fe05a, 0 6px 0 3px var(--ink);
}
body[data-phase="short"] .px-btn.primary:active, body[data-phase="long"] .px-btn.primary:active {
  box-shadow: 0 0 0 3px var(--ink), inset 4px 4px 0 var(--leaf-dark), 0 1px 0 3px var(--ink);
}
.px-btn.tiny { min-height: 40px; font-size: 9px; padding: 0 10px; }
.px-btn:disabled { opacity: 0.5; }

/* Progreso diario */
.progress {
  position: fixed; z-index: 5;
  top: calc(var(--safe-t) + 13px);
  left: calc(var(--safe-l) + 13px);
  width: min(210px, calc(100vw - 160px - var(--safe-l) - var(--safe-r)));
  padding: 7px 8px 8px;
  background: rgba(39, 12, 7, 0.55);
  box-shadow: 0 0 0 3px rgba(39, 12, 7, 0.55);
  color: #fff3dc;
}
.progress-text { display: flex; justify-content: space-between; align-items: center; font-size: 9px; line-height: 1; margin-bottom: 6px; }
body.wide .progress {
  top: calc(50% + 20px); left: calc(var(--col-left) + 3px);
  width: calc(var(--col-w) - var(--safe-r) - 6px);
}
body.letterbox #stage { box-shadow: 0 0 0 4px var(--ink); }
.tomato-ico {
  display: inline-block; width: 9px; height: 9px; vertical-align: -1px;
  background: var(--tomato);
  box-shadow: inset -2px -2px 0 var(--tomato-dark), 0 -3px 0 -1px var(--leaf);
}
.bar { height: 10px; background: var(--ink); box-shadow: inset 0 0 0 2px #4a2414; }
.bar .fill {
  height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, var(--tomato) 0 6px, #ff6a48 6px 8px);
  transition: width 0.4s steps(6);
}
.progress.done .bar .fill { background: repeating-linear-gradient(90deg, var(--gold) 0 6px, #fff1a0 6px 8px); }

.toast {
  margin: 4px 3px 0;
  padding: 12px 12px;
  background: var(--cream);
  color: var(--ink);
  font-size: 10px; line-height: 1.6; text-align: center;
  box-shadow: 0 0 0 3px var(--frame), 0 0 0 6px var(--ink);
}
.toast[hidden] { display: none; }

/* ---------- Ventanas ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(9, 22, 60, 0.55); }
.backdrop[hidden] { display: none; }
.window {
  position: fixed; z-index: 21;
  left: 50%; top: calc(var(--safe-t) + 16px);
  transform: translateX(-50%);
  width: min(calc(100vw - 32px - var(--safe-l) - var(--safe-r)), 520px);
  max-height: calc(100% - var(--safe-t) - var(--safe-b) - 32px);
  display: flex; flex-direction: column;
  background: var(--cream);
  box-shadow: 0 0 0 4px var(--frame), 0 0 0 8px var(--ink), 8px 12px 0 8px rgba(0, 0, 0, 0.35);
}
.window[hidden] { display: none; }
.small-win { top: 50%; transform: translate(-50%, -50%); width: min(calc(100vw - 40px), 420px); }
.win-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 10px 16px;
  background: var(--frame); color: #fff3dc;
  box-shadow: inset 0 -4px 0 var(--frame-dark);
}
.win-head h2 { margin: 0; font-size: 14px; font-weight: 400; text-shadow: 2px 2px 0 var(--frame-dark); }
.close-btn {
  width: 44px; height: 44px; border: 0; cursor: pointer;
  background: var(--cream); color: var(--ink); font-size: 14px;
  box-shadow: inset -3px -3px 0 var(--cream-2), 0 0 0 3px var(--ink);
}
.close-btn:active { box-shadow: inset 3px 3px 0 var(--cream-2), 0 0 0 3px var(--ink); }
.win-body { padding: 14px 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.win-body h3 {
  margin: 18px 0 12px; font-size: 11px; font-weight: 400; color: var(--frame-dark);
  border-bottom: 3px solid var(--cream-2); padding-bottom: 8px;
}
.win-body h3:first-child { margin-top: 4px; }
.win-body p { font-size: 11px; line-height: 1.7; margin: 8px 0; }
#confirmText { font-size: 12px; line-height: 1.8; text-align: center; margin: 6px 0 18px; }
.hint { font-size: 9px !important; line-height: 1.7 !important; color: #6a3a22; margin: 4px 0 10px !important; }
.hint:empty { display: none; }
.tiny-txt { margin-top: 18px !important; opacity: 0.8; }

.chips { display: flex; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.chip {
  flex: 1; min-width: 56px; min-height: 44px; font-size: 12px; border: 0; cursor: pointer;
  background: #fff4dc; box-shadow: 0 0 0 3px var(--ink), inset -3px -3px 0 var(--cream-2);
  margin: 3px;
}
.chip.on { background: var(--leaf); color: #fff; text-shadow: 2px 2px 0 var(--leaf-dark); box-shadow: 0 0 0 3px var(--ink), inset -3px -3px 0 var(--leaf-dark); }

.stepper { display: flex; align-items: center; gap: 8px; margin: 8px 0; min-height: 48px; }
.stepper .lbl, .vol-row .lbl { flex: 1; font-size: 10px; line-height: 1.4; }
.step {
  width: 44px; height: 44px; border: 0; cursor: pointer; font-size: 16px;
  background: var(--frame); color: #fff3dc;
  box-shadow: 0 0 0 3px var(--ink), inset -3px -3px 0 var(--frame-dark), inset 3px 3px 0 #ff8a4a;
  margin: 3px;
}
.step:active { box-shadow: 0 0 0 3px var(--ink), inset 3px 3px 0 var(--frame-dark); }
.stepper .val {
  min-width: 76px; text-align: center; font-size: 12px;
  padding: 12px 4px; background: #fff; box-shadow: inset 0 0 0 3px var(--ink);
}

.toggle { display: flex; align-items: center; gap: 12px; min-height: 48px; margin: 4px 0; cursor: pointer; font-size: 10px; line-height: 1.5; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .sw {
  flex: none; position: relative; width: 52px; height: 28px;
  background: #b9a48a; box-shadow: 0 0 0 3px var(--ink); margin: 3px;
}
.toggle .sw::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  background: #fff4dc; box-shadow: inset -3px -3px 0 var(--cream-2);
}
.toggle input:checked + .sw { background: var(--leaf); }
.toggle input:checked + .sw::after { left: 27px; }
.toggle input:focus-visible + .sw { outline: 3px dashed var(--frame); outline-offset: 4px; }
.toggle input:disabled + .sw { opacity: 0.4; }
.toggle input:disabled ~ span:last-child { opacity: 0.55; }

.vol-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 6px; }
.vol-row input[type=range] {
  -webkit-appearance: none; appearance: none; flex: 2; height: 12px; background: var(--ink); min-width: 80px;
}
.vol-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 30px; background: var(--frame); border: 0;
  box-shadow: inset -3px -3px 0 var(--frame-dark), 0 0 0 3px var(--ink);
}
.vol-row input[type=range]::-moz-range-thumb {
  width: 22px; height: 30px; background: var(--frame); border: 3px solid var(--ink); border-radius: 0;
}
.vol-row input:disabled { opacity: 0.4; }

.win-actions { display: flex; justify-content: center; margin-top: 18px; }
.win-actions.two { gap: 14px; }
.win-actions.two .px-btn { flex: 1; min-width: 0; font-size: 11px; min-height: 48px; }

/* Estadísticas */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: #fff4dc; box-shadow: 0 0 0 3px var(--ink); padding: 12px 8px; text-align: center; margin: 3px; }
.stat b { display: block; font-size: 16px; font-weight: 400; color: var(--tomato); margin-bottom: 8px; }
.stat span { font-size: 8px; line-height: 1.5; }
.chart { display: flex; gap: 6px; align-items: flex-end; height: 150px; padding: 8px 4px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; gap: 6px; }
.chart .b { flex: 1; width: 100%; max-width: 32px; display: flex; align-items: flex-end; background: #f4d3a2; box-shadow: inset 0 0 0 2px #e5bd85; }
.chart .b > div { width: 100%; background: var(--tomato); box-shadow: inset -3px 0 0 var(--tomato-dark); min-height: 0; }
.chart .today .b > div { background: var(--leaf); box-shadow: inset -3px 0 0 var(--leaf-dark); }
.chart .n { font-size: 9px; }
.chart .d { font-size: 9px; }
.chart .today .d { color: var(--leaf-dark); }

@media (prefers-reduced-motion: reduce) {
  body[data-status="paused"] #digits { animation: none; opacity: 0.6; }
  .flashing .flash { animation: none; opacity: 0.5; }
  .status-label.blink { animation: none; }
  .sparkles i { animation-duration: 0.01s; }
  .bar .fill { transition: none; }
}
