@font-face {
  font-family: 'Bitter';
  src: url('/assets/fonts/Bitter-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Bitter';
  src: url('/assets/fonts/Bitter-SemiBoldItalic.woff2') format('woff2');
  font-weight: 600;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Bitter';
  src: url('/assets/fonts/Bitter-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Bitter';
  src: url('/assets/fonts/Bitter-BoldItalic.woff2') format('woff2');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/assets/fonts/IBMPlexSans-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/assets/fonts/IBMPlexSans-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/assets/fonts/IBMPlexSans-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/assets/fonts/IBMPlexSans-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'DM Mono';
  src: url('/assets/fonts/DMMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'DM Mono';
  src: url('/assets/fonts/DMMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Oswald';
  src: url('/assets/fonts/Oswald-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
/* ══ TOKENS ═══════════════════════════════════════════════════════════════ */
:root {
  --bg:          #eceae4;
  --paper:       #ffffff;
  --paper-mid:   #f2efe8;
  --paper-dark:  #e8e4da;
  --ink:         #18140a;
  --ink-mid:     #42381e;
  --ink-muted:   #7a6e52;
  --ink-faint:   #b0a480;
  --band:        #e8820a;
  --band-dark:   #c46a00;
  --green:       #1a6b3a;
  --green-bg:    #dff2e8;
  --red:         #b81818;
  --red-bg:      #fce8e8;
  --border:      #d4cbb8;
  --border-mid:  #c0b498;
  --shadow:      0 2px 2px rgba(0,0,0,0.04), 0 8px 40px rgba(0,0,0,0.10);
  --font-title:  'Bitter', Georgia, serif;
  --font-body:   'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:   'DM Mono', monospace;
  --radius:      3px;
  --doc-pad:     36px;
}

/* ══ RESET ════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--ink);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 44px 16px 72px;
  overflow-y: scroll;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

/* ══ PAGE ═════════════════════════════════════════════════════════════════ */
.page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 680px;
}

/* ══ SCREENS ══════════════════════════════════════════════════════════════ */
.screen {
  width: 100%;
  animation: docIn 0.45s cubic-bezier(0.22,1,0.36,1) both;
}
.screen.hidden { display: none; }

@keyframes docIn {
  from { opacity: 0; transform: translateY(20px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ══ DOC CONTAINER ════════════════════════════════════════════════════════ */
.doc {
  background: var(--paper);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* ══ DOC BAND ═════════════════════════════════════════════════════════════ */
/*
  La banda naranja es la firma visual del juego.
  Es siempre naranja en las 3 pantallas: solo cambia el texto.
  Altura suficiente para mostrar el contenido (30px).
*/
.doc-band {
  background: var(--band);
  height: 10px;
  padding: 0 var(--doc-pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.band-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.92);
}

.band-ref {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.06em;
}

.band-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.92);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffdd44;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.2; }
}

.band-ok {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #ffffff;
  font-weight: 500;
}

/* ══ DOC TOP ══════════════════════════════════════════════════════════════ */
.doc-top {
  padding: var(--doc-pad) var(--doc-pad) 28px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.doc-top-left { flex: 1; }

.doc-main-title {
  font-family: var(--font-title);
  font-size: clamp(34px, 7vw, 54px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 18px;
}

.doc-main-title em {
  font-style: italic;
  color: var(--band);
}

.doc-lead {
  font-size: 17px;
  line-height: 1.75;
  color: var(--ink);
  max-width: 400px;
}

/* ══ DOC DIVIDER ══════════════════════════════════════════════════════════ */
.doc-divider {
  height: 1px;
  margin: 0 var(--doc-pad);
  background: repeating-linear-gradient(
    90deg,
    var(--border) 0, var(--border) 5px,
    transparent 5px, transparent 10px
  );
}

/* ══ FACTORS ══════════════════════════════════════════════════════════════ */
.doc-factors {
  padding: 24px var(--doc-pad) 36px;
}

.factors-title {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mid);
  margin-bottom: 6px;
}

.factors-subtitle {
  font-size: 15px;
  color: var(--ink-mid);
  line-height: 1.7;
  margin-top: 6px;
  margin-bottom: 20px;
  max-width: 100%;
}

.factors-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 0px;
}

.factor {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
}

.factor-up   { background: var(--green-bg); border-left-color: var(--green); }
.factor-down { background: var(--red-bg);   border-left-color: var(--red); }

.factor-icon {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  line-height: 1.3;
  color: var(--ink-mid);
}

.factor-text {
  flex: 1;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.factor-val {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.factor-up   .factor-val { color: var(--green); }
.factor-down .factor-val { color: var(--red); }

.factors-more {
  font-size: 13px;
  color: var(--ink-faint);
  font-style: italic;
}

/* ══ INPUT ════════════════════════════════════════════════════════════════ */
.doc-input-area {
  padding: 24px var(--doc-pad) 18px;
  background: var(--paper-mid);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.input-row {
  display: flex;
  gap: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin-bottom: 0;
}

.name-input {
  flex: 1;
  height: 56px;
  padding: 0 20px;
  font-family: var(--font-title);
  font-size: 21px;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--border-mid);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  outline: none;
  transition: border-color 0.15s ease;
  letter-spacing: -0.01em;
}

.name-input:focus { border-color: var(--band); }

.name-input::placeholder {
  color: var(--ink-faint);
  font-style: italic;
  font-weight: 400;
  font-size: 17px;
}

.btn-calc {
  height: 56px;
  padding: 0 28px;
  background: var(--band);
  color: #ffffff;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.01em;
  transition: background 0.12s ease, transform 0.08s ease;
}

.btn-calc:hover  { background: var(--band-dark); }
.btn-calc:active { transform: scale(0.98); }

/* El mensaje de error ocupa siempre su espacio (min-height)
   para que no mueva el layout al aparecer */
.input-note {
  font-size: 12px;
  color: var(--ink-faint);
  font-style: italic;
  min-height: 0;
  margin: 6px 0 0 0;
  transition: color 0.15s ease;
}

/* ══ CALC HEADER ══════════════════════════════════════════════════════════ */
.calc-header {
  padding: var(--doc-pad) var(--doc-pad) 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.calc-header > div {
  min-width: 0;
  flex: 1;
}

.calc-tag {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mid);
  margin-bottom: 8px;
}

.calc-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

.calc-name {
  font-family: var(--font-title);
  font-size: clamp(30px, 7vw, 48px);
  font-weight: 700;
  font-style: italic;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.calc-icon {
  font-size: 40px;
  opacity: 0.25;
  flex-shrink: 0;
}

/* ══ CALC BODY ════════════════════════════════════════════════════════════ */
.calc-body {
  padding: 20px var(--doc-pad) 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calc-steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 120px;
  max-height: 300px;
  /* overflow-y: auto permite el scroll que usa scrollTop en JS */
  overflow-y: auto;
  /* Scroll suave */
  scroll-behavior: smooth;
}

/* Scrollbar discreta acorde al diseño */
.calc-steps::-webkit-scrollbar { width: 4px; }
.calc-steps::-webkit-scrollbar-track { background: transparent; }
.calc-steps::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 2px;
}

.calc-step {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 9px 12px 9px 14px;
  border-left: 3px solid transparent;
  font-size: 13px;
  color: var(--ink-mid);
  animation: stepIn 0.25s ease both;
  background: var(--paper-mid);
  /* Evita que los pasos se encojan si el container tiene poco espacio */
  flex-shrink: 0;
}

.calc-step.s-up   { border-left-color: var(--green); background: var(--green-bg); }
.calc-step.s-down { border-left-color: var(--red);   background: var(--red-bg); }

@keyframes stepIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.calc-step-desc { flex: 1; line-height: 1.4; }

.calc-step-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.calc-step-val.up   { color: var(--green); }
.calc-step-val.down { color: var(--red); }

.calc-progress-wrap {
  height: 3px;
  background: var(--paper-dark);
  overflow: hidden;
}

.calc-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--band), #ffaa44);
  transition: width 0.35s ease;
}

.calc-status {
  font-size: 11px;
  color: var(--ink-mid);
  letter-spacing: 0.04em;
  min-height: 16px;
}

/* ══ RESULT HEADER ════════════════════════════════════════════════════════ */
.result-header {
  padding: var(--doc-pad) var(--doc-pad) 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.result-header-left {
  min-width: 0;
  flex: 1;
}

.result-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.result-name {
  font-family: var(--font-title);
  font-size: clamp(30px, 7vw, 48px);
  font-weight: 700;
  font-style: italic;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.result-stamp {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.3em;
  color: var(--green);
  border: 4px solid var(--green);
  outline: 2px solid var(--green);
  outline-offset: -6px;
  padding: 10px 16px;
  flex-shrink: 0;
  opacity: 0;
  transform: rotate(-5deg) translateY(-8px);
  animation: none;
}

.stamp-azul    { color: #1a8fb5;    border-color: #1a8fb5;    outline-color: #1a8fb5; }
.stamp-rojo    { color: var(--red);   border-color: var(--red);   outline-color: var(--red); }
.stamp-negro   { color: var(--ink);    border-color: var(--ink);    outline-color: var(--ink); }
.stamp-naranja { color: var(--band);  border-color: var(--band);  outline-color: var(--band); }
.stamp-verde   { color: var(--green); border-color: var(--green); outline-color: var(--green); }
.stamp-dorado  { color: #b8860b;      border-color: #b8860b;      outline-color: #b8860b; }

@keyframes stamp {
  from { opacity: 0; transform: rotate(-5deg) translateY(-8px) scale(1.4); }
  to   { opacity: 1; transform: rotate(-5deg) translateY(-8px) scale(1); }
}

/* ══ RESULT PRICE ═════════════════════════════════════════════════════════ */
.result-price-section {
  padding: 20px var(--doc-pad) 28px;
  background: var(--paper-mid);
}

.price-label {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mid);
  margin-bottom: 10px;
}

.price-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.price-number {
  font-family: var(--font-mono);
  font-size: clamp(54px, 14vw, 92px);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1;
}

.price-red { color: var(--red) !important; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.price-shake {
  animation: shake 0.5s ease both;
}

@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.price-pulse {
  animation: pulse 0.4s ease both;
  color: var(--band) !important;
}

.price-pulse-green {
  animation: pulse 0.4s ease both;
  color: var(--green) !important;
}

.price-pulse-blue {
  animation: pulse 0.4s ease both;
  color: #1a8fb5 !important;
}

@keyframes flash-gold {
  0%   { transform: scale(1);    color: var(--ink); }
  30%  { transform: scale(1.12); color: #b8860b; }
  60%  { transform: scale(0.98); color: #b8860b; }
  100% { transform: scale(1);    color: #b8860b; }
}

.price-flash-gold {
  animation: flash-gold 0.6s ease both;
}

.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

.price-eur {
  font-family: var(--font-mono);
  font-size: clamp(26px, 5vw, 40px);
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* ══ BREAKDOWN ════════════════════════════════════════════════════════════ */
.result-breakdown-section {
  padding: 24px var(--doc-pad);
}

.section-title {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mid);
  margin-bottom: 16px;
}

.breakdown-list { display: flex; flex-direction: column; }

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row:nth-last-child(2) { border-bottom: none; }

.bd-desc {
  font-size: 15px;
  color: var(--ink-mid);
  flex: 1;
  line-height: 1.4;
}

.bd-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.bd-val.pos   { color: var(--green); }
.bd-val.neg   { color: var(--red); }
.bd-val.total { color: var(--ink); font-size: 16px; font-weight: 600; }
.bd-total-desc { font-weight: 600; font-size: 16px; color: var(--ink); }

/* ══ VERDICT ══════════════════════════════════════════════════════════════ */
.result-verdict-section {
  margin: 0 var(--doc-pad) 0;
  margin-top: 16px;
  padding: 40px 28px 28px;
  position: relative;
  font-family: var(--font-title);
  font-size: 18px;
  font-style: italic;
  line-height: 1.75;
  color: var(--ink);
  border: 2px solid var(--ink);
}

.result-verdict-section::before {
  content: '\201C';
  font-family: 'Arial Black', 'Helvetica Neue', sans-serif;
  font-size: 55px;
  font-weight: 900;
  font-style: normal;
  color: var(--ink);
  position: absolute;
  top: -24px;
  left: 20px;
  line-height: 1;
  background: var(--paper);
  padding: 0 6px;
}

.result-verdict-section::after {
  content: '\201D';
  font-family: 'Arial Black', 'Helvetica Neue', sans-serif;
  font-size: 55px;
  font-weight: 900;
  font-style: normal;
  color: var(--ink);
  position: absolute;
  bottom: -39.5px;
  right: 20px;
  line-height: 1;
  background: var(--paper);
  padding: 0 6px;
}

/* ══ COMPARISON ═══════════════════════════════════════════════════════════ */
.result-comparison-section {
  padding: 16px var(--doc-pad);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.65;
}

/* ══ ACTIONS ══════════════════════════════════════════════════════════════ */
.result-actions {
  padding: 20px var(--doc-pad) 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.result-fine {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  font-style: italic;
  letter-spacing: 0.02em;
  line-height: 1.5;
  flex: 1;
}

.btn-repeat {
  height: 56px;
  padding: 0 28px;
  background: var(--band);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.01em;
  transition: background 0.12s ease, transform 0.08s ease;
}

.btn-repeat:hover {
  background: var(--band-dark);
}

.btn-repeat:active {
  transform: scale(0.98);
}

.doc-factors { padding-bottom: 36px; }
.calc-body { padding-bottom: 36px; }
.result-actions { padding-bottom: 36px; }

/* ══ MOBILE ═══════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  :root { --doc-pad: 18px; }
  body {
    background: var(--paper);
    padding: 0 0 40px;
  }

  .doc {
    border: none;
    box-shadow: none;
  }
  .grain { display: none; }
  .doc-band { padding: 0 18px; }
  .doc-top { flex-direction: column; gap: 20px; padding-top: 40px; }
  .valuation-box { width: 100%; }
  .factors-grid { grid-template-columns: 1fr; }
  .doc-factors { padding-top: 24px; padding-bottom: 0; }
  .calc-body { padding-bottom: 0; }
  .result-comparison-section { padding-bottom: 0; }
  .calc-header { padding-top: 40px; }
  .result-header { padding-top: 40px; }
  .result-stamp {
    min-width: 160px;
    min-height: 44px;
    font-size: 11px;
    padding: 4px 11px;
    border-width: 3px;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .result-verdict-section::before {
    font-family: 'Oswald', sans-serif;
    top: -18.7px;
  }
  .result-verdict-section::after {
    font-family: 'Oswald', sans-serif;
    bottom: -43px;
  }
  .input-row { flex-direction: column; }
  .name-input {
    border-right: 2px solid var(--border-mid);
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 19px;
    height: 56px !important;
    min-height: 56px;
  }
  .btn-calc {
    border-radius: 0 0 var(--radius) var(--radius);
    width: 100%;
    height: 56px;
  }
  .price-number { font-size: 52px; }
  .result-actions {
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    padding-bottom: 0;
  }
}