/* --------------------------------------------------------------------------
   CAP Educational · Ficha de indicio
   Escenario fijo 16:9 (1920 × 1080) escalado a la pantalla.
   -------------------------------------------------------------------------- */

@font-face {
  font-family: "Give You Glory";
  src: url("../assets/fonts/give-you-glory-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: block;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Give You Glory";
  src: url("../assets/fonts/give-you-glory-latin-ext.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: block;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
    U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113,
    U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --navy: #183c59;
  --navy-deep: #102a3f;
  --red: #c02031;
  --red-deep: #a41626;
  --ink: #1328e4;
  --paper-white: #ffffff;
  --desk-light: #efede7;
  --desk-mid: #e5e2da;
  --desk-dark: #d7d2c7;
  --stage-scale: 1;
  --pen-height: 372px;
  --font-ui: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial,
    sans-serif;
  --font-hand: "Give You Glory", "Segoe Print", "Bradley Hand", cursive;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-soft: cubic-bezier(0.25, 0.8, 0.25, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--desk-mid);
  font-family: var(--font-ui);
  color: var(--navy);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

/* --------------------------------------------------------------------------
   Mesa + escenario
   -------------------------------------------------------------------------- */

.desk {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(90% 65% at 50% 34%, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0) 68%),
    radial-gradient(120% 130% at 50% 45%, var(--desk-light) 0%, var(--desk-mid) 58%, var(--desk-dark) 100%);
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1920px;
  height: 1080px;
  transform: translate(-50%, -50%) scale(var(--stage-scale));
  transform-origin: center center;
  will-change: transform;
}

.paper-perspective {
  position: absolute;
  inset: 0;
  perspective: 1750px;
  perspective-origin: 50% 46%;
}

/* --------------------------------------------------------------------------
   La ficha (hoja de papel)
   -------------------------------------------------------------------------- */

.paper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 3px;
  background: var(--paper-white);
  box-shadow:
    0 1px 2px rgba(16, 42, 63, 0.12),
    0 16px 34px rgba(16, 42, 63, 0.13),
    0 52px 100px rgba(16, 42, 63, 0.15);
  transform-origin: 50% 52%;
  transform: translateZ(0);
  transform-style: preserve-3d;
  backface-visibility: hidden;
  will-change: transform, opacity, box-shadow;
}

.paper__surface {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #fff url("../assets/ficha/ficha-indicio-1920x1080.jpg") center / 100% 100%
    no-repeat;
  pointer-events: none;
}

.ficha {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
}

/* --------------------------------------------------------------------------
   Campos escritos a mano
   -------------------------------------------------------------------------- */

.field {
  --drop: 34px;
  --pad-bottom: 12px;
  position: absolute;
  left: var(--x);
  top: calc(var(--line) - var(--h) + var(--drop));
  width: var(--w);
  height: calc(var(--h) + var(--pad-bottom));
  margin: 0;
  padding: 0 2px var(--pad-bottom);
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-hand);
  font-size: var(--fs);
  /* Give You Glory solo distribuye 400; el navegador sintetiza el peso siguiente. */
  font-weight: 600;
  font-synthesis: weight;
  line-height: 1;
  letter-spacing: 0.005em;
  color: var(--ink);
  caret-color: var(--ink);
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.field::selection {
  background: rgba(19, 40, 228, 0.16);
}

.field:focus,
.field:focus-visible {
  outline: 0;
  box-shadow: none;
}

.field::-webkit-search-decoration,
.field::-webkit-search-cancel-button,
.field::-webkit-outer-spin-button,
.field::-webkit-inner-spin-button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
}

.field--numeric {
  padding: 0 0 var(--pad-bottom);
  text-align: center;
}

/* La descripción es un área continua: el texto fluye solo entre las
   cuatro líneas impresas. El interlineado coincide con el de la ficha. */
.field--area {
  top: 495px;
  left: 177px;
  width: 1548px;
  height: 280px;
  padding: 24px 0 0;
  display: block;
  overflow: hidden;
  resize: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 48px;
  line-height: 47px;
  text-align: left;
}

.paper.is-busy .field {
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Botón borrar + bandera + pista
   -------------------------------------------------------------------------- */

.clear-button,
.fullscreen-button,
.signature-button {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(24, 60, 89, 0.045);
  color: var(--navy);
  opacity: 0.34;
  cursor: pointer;
  transition:
    opacity 0.35s ease,
    background-color 0.35s ease,
    box-shadow 0.35s ease,
    transform 0.5s var(--ease-out);
}

.clear-button {
  left: 34px;
  bottom: 22px;
}

.fullscreen-button {
  top: 12px;
  right: 34px;
  opacity: 0.45;
}

.fullscreen-button[hidden] {
  display: none;
}

.signature-button {
  top: 920px;
  left: 1672px;
  z-index: 6;
  width: 40px;
  height: 40px;
  opacity: 0.5;
}

.signature-button.is-active {
  opacity: 0.9;
}

.clear-button::before,
.fullscreen-button::before,
.signature-button::before {
  content: "";
  position: absolute;
  inset: -20px;
  border-radius: 50%;
}

.clear-button svg,
.fullscreen-button svg,
.signature-button svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.signature-button svg {
  width: 22px;
  height: 22px;
}

.fullscreen-icon--exit {
  display: none;
}

.fullscreen-button.is-fullscreen .fullscreen-icon--enter {
  display: none;
}

.fullscreen-button.is-fullscreen .fullscreen-icon--exit {
  display: inline;
}

.clear-button:hover,
.clear-button:focus-visible,
.fullscreen-button:hover,
.fullscreen-button:focus-visible,
.signature-button:hover,
.signature-button:focus-visible {
  opacity: 1;
  background: #fff;
  box-shadow:
    0 1px 2px rgba(16, 42, 63, 0.12),
    0 10px 26px rgba(16, 42, 63, 0.16);
  transform: translateY(-1px) scale(1.045);
}

.clear-button:focus-visible,
.fullscreen-button:focus-visible,
.signature-button:focus-visible {
  outline: 2px solid rgba(24, 60, 89, 0.5);
  outline-offset: 3px;
}

.clear-button:active,
.fullscreen-button:active,
.signature-button:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

.clear-button:disabled {
  opacity: 0.16;
  pointer-events: none;
}

/* Firma: una sola imagen, revelada con un barrido de degradado. */
.signature-reveal {
  position: absolute;
  right: 273px;
  bottom: 114px;
  z-index: 5;
  width: 282px;
  height: 180px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.signature-reveal.is-visible {
  opacity: 1;
}

.signature-image {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -13px;
  width: 100%;
  height: 180px;
  object-fit: contain;
  object-position: right bottom;
  pointer-events: none;
  user-select: none;
}

.signature-reveal::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 150%;
  background: linear-gradient(90deg, #fff 0%, #fff 72%, rgba(255, 255, 255, 0) 100%);
  transform: translateX(0);
  transition: transform 0.95s cubic-bezier(0.25, 0.8, 0.25, 1);
  pointer-events: none;
}

.signature-reveal.is-revealed::after {
  transform: translateX(110%);
}

.signature-reveal.is-resetting::after {
  transition: none;
  transform: translateX(0);
}

.corner-flag {
  position: absolute;
  right: 38px;
  bottom: 22px;
  z-index: 4;
  width: auto;
  height: 64px;
  opacity: 0.9;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(16, 42, 63, 0.08));
}

.ficha-hint {
  position: absolute;
  left: 50%;
  bottom: 33px;
  z-index: 4;
  margin: 0;
  padding: 0;
  color: rgba(24, 60, 89, 0.48);
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.07em;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  transition:
    opacity 0.6s ease,
    transform 0.6s var(--ease-soft);
}

.ficha-hint span {
  padding: 0 0.25em;
  opacity: 0.65;
}

.ficha-hint.is-hidden {
  opacity: 0;
  transform: translate(-50%, 6px);
}

/* --------------------------------------------------------------------------
   Espejo invisible para medir la posición del caret
   -------------------------------------------------------------------------- */

.caret-mirror,
.line-mirror {
  position: fixed;
  top: 0;
  left: -12000px;
  width: auto;
  margin: 0;
  border: 0;
  padding: 0;
  box-sizing: border-box;
  visibility: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  z-index: -1;
}

.line-mirror {
  height: auto;
}

/* --------------------------------------------------------------------------
   Pluma
   -------------------------------------------------------------------------- */

.pen-layer {
  position: fixed;
  inset: 0;
  z-index: 900;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.pen-layer.is-visible {
  opacity: 1;
}

.pen {
  position: absolute;
  left: 0;
  top: 0;
  height: var(--pen-height);
  width: auto;
  transform-origin: 50% 100%;
  filter:
    drop-shadow(2px 13px 9px rgba(16, 42, 63, 0.1))
    drop-shadow(0 2px 3px rgba(16, 42, 63, 0.13));
  will-change: transform, opacity;
  user-select: none;
}

@media (hover: hover) and (pointer: fine) {
  html.pen-active,
  html.pen-active * {
    cursor: none !important;
  }
}

@media (pointer: coarse) {
  .pen-layer {
    display: none;
  }
}

/* En móviles los controles de la hoja ganan unos píxeles de presencia. */
@media (pointer: coarse) and (max-width: 900px) {
  .clear-button {
    left: 24px;
    bottom: 14px;
    width: 84px;
    height: 84px;
  }

  .fullscreen-button {
    top: 14px;
    right: 24px;
    width: 84px;
    height: 84px;
  }

  .signature-button {
    top: 908px;
    left: 1660px;
    width: 64px;
    height: 64px;
  }

  .clear-button svg,
  .fullscreen-button svg {
    width: 36px;
    height: 36px;
  }

  .signature-button svg {
    width: 30px;
    height: 30px;
  }

  .corner-flag {
    right: 26px;
    bottom: 16px;
    height: 80px;
  }
}

/* --------------------------------------------------------------------------
   Modal de confirmación
   -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: grid;
  place-items: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.26s ease,
    visibility 0.26s;
}

.modal[hidden] {
  display: none;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 20, 32, 0.48);
  backdrop-filter: blur(2.5px);
  -webkit-backdrop-filter: blur(2.5px);
}

.modal__dialog {
  position: relative;
  width: min(92vw, 520px);
  padding: clamp(28px, 4vw, 42px);
  border-radius: 24px;
  background: #fff;
  box-shadow:
    0 2px 4px rgba(9, 20, 32, 0.08),
    0 28px 70px rgba(9, 20, 32, 0.28);
  transform: translateY(12px) scale(0.94);
  transition: transform 0.4s var(--ease-out);
}

.modal.is-open .modal__dialog {
  transform: translateY(0) scale(1);
}

.modal__icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 22px;
  border-radius: 50%;
  background: rgba(192, 32, 49, 0.09);
  color: var(--red);
}

.modal__icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.modal__title {
  margin: 0 0 10px;
  color: var(--navy);
  font-size: clamp(22px, 2.4vw, 27px);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.015em;
}

.modal__text {
  margin: 0 0 30px;
  color: rgba(24, 60, 89, 0.7);
  font-size: 15.5px;
  line-height: 1.6;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.button {
  min-height: 48px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.25s var(--ease-out);
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0) scale(0.98);
}

.button:focus-visible {
  outline: 3px solid rgba(24, 60, 89, 0.25);
  outline-offset: 2px;
}

.button--ghost {
  border-color: rgba(24, 60, 89, 0.2);
  background: transparent;
  color: var(--navy);
}

.button--ghost:hover {
  border-color: rgba(24, 60, 89, 0.34);
  background: rgba(24, 60, 89, 0.05);
}

.button--danger {
  background: var(--red);
  color: #fff;
  box-shadow: 0 6px 16px rgba(192, 32, 49, 0.22);
}

.button--danger:hover {
  background: var(--red-deep);
  box-shadow: 0 8px 22px rgba(192, 32, 49, 0.28);
}

.button:disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Preloader
   -------------------------------------------------------------------------- */

.preloader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 32px;
  background: #fff;
  opacity: 1;
  visibility: visible;
  transition:
    opacity 0.6s var(--ease-soft),
    visibility 0.6s;
}

.preloader.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(84vw, 560px);
}

.preloader__logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: clamp(104px, 18vh, 186px);
  object-fit: contain;
  opacity: 0;
  transform-origin: 50% 55%;
  will-change: transform, opacity, filter;
}

.preloader__track {
  position: relative;
  width: clamp(190px, 25vw, 296px);
  height: 3px;
  margin-top: clamp(30px, 5vh, 48px);
  overflow: hidden;
  border-radius: 999px;
  background: rgba(24, 60, 89, 0.12);
}

.preloader__bar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--navy) 0%, #2b5d84 100%);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.55s var(--ease-soft);
}

.preloader__meta {
  display: flex;
  justify-content: space-between;
  width: clamp(190px, 25vw, 296px);
  margin-top: 14px;
  color: rgba(24, 60, 89, 0.55);
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   Aviso para móvil en vertical
   -------------------------------------------------------------------------- */

.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 850;
  display: none;
  place-items: center;
  padding: 28px;
  background: rgba(12, 31, 48, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.rotate-hint__card {
  max-width: 330px;
  padding: 34px 30px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.055);
  color: #fff;
  text-align: center;
}

.rotate-hint__card svg {
  width: 58px;
  height: 58px;
  fill: none;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: rotate-device 3.4s var(--ease-in-out) infinite;
}

.rotate-hint__card p {
  margin: 20px 0 7px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.rotate-hint__card span {
  color: rgba(255, 255, 255, 0.66);
  font-size: 14px;
  line-height: 1.5;
}

@keyframes rotate-device {
  0%,
  18% {
    transform: rotate(0deg);
  }
  46%,
  72% {
    transform: rotate(90deg);
  }
  100% {
    transform: rotate(90deg);
  }
}

@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) {
  .rotate-hint {
    display: grid;
  }
}

@media (max-width: 900px) {
  .ficha-hint {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Accesibilidad de movimiento
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .clear-button,
  .modal,
  .modal__dialog,
  .ficha-hint,
  .preloader {
    transition-duration: 0.01ms !important;
  }

  .rotate-hint__card svg {
    animation: none;
  }
}
