/* Taiwan ID Validator — paper-tech light theme, dashed borders, measured-reveal motion */

.idv-page {
  /* Map ink palette into the canonical chrome tokens — keeps shared
     header/footer text readable on this tool's cream theme. */
  --chrome-ink: #2a2440;
  --chrome-ink-muted: #6b6382;
  --idv-accent: #8b6bef;
  --idv-accent-mid: rgba(139, 107, 239, 0.55);
  --idv-accent-soft: rgba(139, 107, 239, 0.10);
  --idv-accent-glow: rgba(139, 107, 239, 0.16);
  --idv-ink: #2a2440;
  --idv-ink-soft: #6b6382;
  --idv-paper: #faf8f5;
  --idv-paper-warm: #f5f2ed;
  --idv-border: rgba(139, 107, 239, 0.22);
  --idv-success: #2d9a5e;
  --idv-success-soft: rgba(45, 154, 94, 0.10);
  --idv-error: #c9453a;
  --idv-error-soft: rgba(201, 69, 58, 0.10);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(139, 107, 239, 0.06), transparent 40%),
    linear-gradient(180deg, #f9f7f4 0%, #f3f0ec 50%, #eeebe6 100%);
  color: var(--idv-ink);
}

/* --- header / footer adaptation for light page --- */
.idv-page .site-header,
.idv-page .site-footer {
  background: rgba(250, 248, 245, 0.92);
  border-color: rgba(139, 107, 239, 0.12);
  backdrop-filter: blur(10px);
}

.idv-page .site-nav,
.idv-page .footer-copy,
.idv-page .footer-title {
  color: #5c5472;
}

/* --- tool-frame personality --- */
.idv-page .tool-frame {
  position: relative;
  overflow: hidden;
}

.idv-page .tool-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 85% 10%, rgba(139, 107, 239, 0.05), transparent 20%),
    linear-gradient(rgba(139, 107, 239, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 107, 239, 0.02) 1px, transparent 1px);
  background-size: auto, 20px 20px, 20px 20px;
  opacity: 0.6;
}

.idv-page .tool-header-block,
.idv-page .tool-shell,
.idv-page .tool-notes {
  position: relative;
  z-index: 1;
}

.idv-page .tool-shell {
  margin-top: -8px;
}

/* --- toolbar / header --- */
.idv-page .tool-header-block {
  max-width: none;
  position: relative;
  padding-right: 84px;
}

.idv-toolbar {
  margin-bottom: 6px;
}

.idv-title-stack {
  max-width: 42rem;
}

.idv-page .page-title {
  margin: 0 0 4px;
  font-size: clamp(2.2rem, 4vw, 2.7rem);
  color: #1e1832;
}

.idv-page .page-subtitle {
  margin: 0;
  max-width: 36rem;
  font-size: 17px;
  line-height: 1.45;
  color: var(--idv-ink-soft);
}

/* --- language toggle (light, crisp) --- */
.idv-language-toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1px dashed rgba(139, 107, 239, 0.28);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 2px 8px rgba(139, 107, 239, 0.06);
}

.idv-language-button {
  border: 0;
  border-radius: 999px;
  padding: 7px 11px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--idv-ink-soft);
  background: transparent;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.idv-language-button:hover {
  color: var(--idv-ink);
  background: rgba(139, 107, 239, 0.08);
}

.idv-language-button.is-active {
  color: #fff;
  background: linear-gradient(135deg, rgba(139, 107, 239, 0.92), rgba(113, 82, 218, 0.95));
  box-shadow: 0 4px 12px rgba(139, 107, 239, 0.22);
}

/* --- layout --- */
.idv-bench {
  display: grid;
  gap: 10px;
}

.idv-bench__layout {
  display: flex;
  gap: 12px;
  align-items: start;
}

.idv-panel--inputs {
  flex: 1 1 0;
}

.idv-panel--result {
  flex: 1 1 0;
}

.idv-bench__rail {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- chips & badges (document reference tabs) --- */
.idv-chip,
.idv-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.2;
}

.idv-chip {
  border: 1px dashed rgba(139, 107, 239, 0.30);
  padding: 5px 9px;
  color: var(--idv-ink-soft);
  background: rgba(255, 255, 255, 0.82);
  font-weight: 600;
}

.idv-badge {
  border: 1px solid rgba(45, 154, 94, 0.24);
  padding: 6px 9px;
  color: #2d7a4e;
  background: rgba(45, 154, 94, 0.08);
  font-weight: 700;
}

.idv-badge--quiet {
  border-color: rgba(139, 107, 239, 0.16);
  color: var(--idv-ink-soft);
  background: rgba(139, 107, 239, 0.05);
}

/* --- panels (paper-tech, dashed borders) --- */
.idv-panel {
  display: grid;
  align-content: start;
  align-self: start;
  gap: 14px;
  grid-auto-rows: min-content;
  min-width: 0;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 2px dashed rgba(139, 107, 239, 0.22);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(252, 250, 247, 0.96) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 8px 24px rgba(139, 107, 239, 0.06);
}

.idv-panel--result {
  background:
    radial-gradient(circle at top right, rgba(139, 107, 239, 0.04), transparent 40%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(250, 248, 244, 0.96) 100%);
}

.idv-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.idv-panel__eyebrow {
  color: var(--idv-accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  font-weight: 700;
  margin: 0 0 2px;
}

.idv-panel__hint {
  color: var(--idv-ink-soft);
  font-size: 14px;
  line-height: 1.45;
  margin: 0;
}

/* --- fields --- */
.idv-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.idv-field {
  display: grid;
  gap: 5px;
}

.idv-field__label {
  font-size: 15px;
  font-weight: 700;
  color: var(--idv-ink);
}

.idv-input-wrap {
  position: relative;
}

.idv-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 1.25rem;
  font-family: "SF Mono", "Fira Mono", "Cascadia Code", monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
  border-radius: var(--radius-md);
  border: 2px dashed rgba(139, 107, 239, 0.25);
  background: rgba(255, 255, 255, 0.92);
  color: var(--idv-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.idv-input::placeholder {
  color: #a89ec0;
}

.idv-input:focus {
  outline: none;
  border-color: var(--idv-accent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 0 0 3px rgba(139, 107, 239, 0.12);
}

/* --- sample chips (document reference tabs) --- */
.idv-samples {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.idv-sample-chip {
  border: 1px dashed rgba(139, 107, 239, 0.28);
  background: rgba(255, 255, 255, 0.85);
  color: var(--idv-ink-soft);
  font-size: 12px;
  line-height: 1.2;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: border-color 200ms ease, color 200ms ease, background 200ms ease, transform 200ms ease;
}

.idv-sample-chip:hover {
  border-color: var(--idv-accent);
  color: var(--idv-ink);
  background: rgba(139, 107, 239, 0.06);
  transform: translateY(-1px);
}

/* --- actions --- */
.idv-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 10px 12px;
}

.idv-actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
}

.idv-actions__minor {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.idv-actions .button-primary {
  min-height: 44px;
  min-width: 160px;
  padding: 11px 24px;
  background:
    linear-gradient(135deg, rgba(139, 107, 239, 0.94), rgba(113, 82, 218, 0.92));
  border-color: rgba(139, 107, 239, 0.7);
  color: #fff;
  box-shadow: 0 6px 18px rgba(139, 107, 239, 0.20);
  font-size: 16px;
  transition: box-shadow 200ms ease, transform 200ms ease;
}

.idv-actions .button-primary:hover,
.idv-actions .button-primary:focus-visible {
  box-shadow: 0 8px 24px rgba(139, 107, 239, 0.30);
  transform: translateY(-1px);
}

.idv-actions .button-secondary {
  min-height: 38px;
  padding: 9px 16px;
  background: rgba(255, 255, 255, 0.80);
  border-color: rgba(139, 107, 239, 0.18);
  color: var(--idv-ink-soft);
  font-size: 15px;
  transition: background 200ms ease, color 200ms ease, border-color 200ms ease;
}

.idv-actions .button-secondary:hover,
.idv-actions .button-secondary:focus-visible {
  background: rgba(139, 107, 239, 0.06);
  border-color: rgba(139, 107, 239, 0.32);
  color: var(--idv-ink);
}

/* --- feedback --- */
.idv-feedback-slot {
  min-height: 18px;
}

.idv-feedback {
  margin: 0;
  font-size: 14px;
  color: var(--idv-ink-soft);
  line-height: 1.45;
}

.idv-feedback[data-state="success"] { color: var(--idv-success); }
.idv-feedback[data-state="error"]   { color: var(--idv-error); }

/* --- result card --- */
.idv-result {
  position: relative;
  display: grid;
  gap: 7px;
  padding: 20px 16px;
  min-height: 120px;
  border-radius: var(--radius-md);
  border: 2px dashed rgba(139, 107, 239, 0.18);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, var(--idv-paper) 100%);
  text-align: center;
  overflow: hidden;
  transition: border-color 350ms ease-out, background 350ms ease-out;
}

.idv-result[data-valid="true"] {
  border-color: rgba(45, 154, 94, 0.35);
  background:
    linear-gradient(180deg, rgba(240, 255, 246, 0.96) 0%, rgba(232, 250, 240, 0.92) 100%);
}

.idv-result[data-valid="false"] {
  border-color: rgba(201, 69, 58, 0.30);
  background:
    linear-gradient(180deg, rgba(255, 244, 242, 0.96) 0%, rgba(252, 237, 235, 0.92) 100%);
}

/* --- seal / stamp overlay (official stamp aesthetic) --- */
.idv-result__stamp {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%) rotate(-12deg) scale(0.8);
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  padding: 6px 16px;
  border: 4px double transparent;
  border-radius: 50%;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  letter-spacing: 0.08em;
}

.idv-result[data-valid="true"] .idv-result__stamp {
  color: var(--idv-success);
  border-color: var(--idv-success);
  animation: sealReveal 400ms 100ms ease-out forwards;
}

.idv-result[data-valid="false"] .idv-result__stamp {
  color: var(--idv-error);
  border-color: var(--idv-error);
  animation: sealReveal 400ms 100ms ease-out forwards;
}

/* reset animation when no data-valid */
.idv-result:not([data-valid="true"]):not([data-valid="false"]) .idv-result__stamp {
  opacity: 0;
  animation: none;
}

.idv-result__title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--idv-ink);
}

.idv-result__value {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  font-family: "SF Mono", "Fira Mono", "Cascadia Code", monospace;
  letter-spacing: 0.1em;
  margin: 0;
  color: var(--idv-ink);
}

.idv-result__value[data-valid="true"]  { color: var(--idv-success); }
.idv-result__value[data-valid="false"] { color: var(--idv-error); }

.idv-result__detail {
  font-size: 14px;
  line-height: 1.45;
  color: var(--idv-ink-soft);
  margin: 0;
}

/* --- region card (document field feel) --- */
.idv-region {
  padding: 12px 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, var(--idv-paper) 100%);
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(139, 107, 239, 0.20);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.idv-region__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--idv-accent);
  margin: 0 0 4px;
}

.idv-region__value {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--idv-ink);
}

/* --- checksum ladder (printed form / document table) --- */
.idv-ladder {
  padding: 14px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(139, 107, 239, 0.04) 27px,
      rgba(139, 107, 239, 0.04) 28px
    ),
    linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, var(--idv-paper) 100%);
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(139, 107, 239, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.idv-ladder__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--idv-accent);
  margin: 0 0 8px;
}

.idv-ladder__table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.idv-ladder__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: "SF Mono", "Fira Mono", "Cascadia Code", monospace;
}

.idv-ladder__table th {
  text-align: left;
  padding: 5px 8px;
  color: var(--idv-ink-soft);
  border-bottom: 2px dashed rgba(139, 107, 239, 0.18);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.idv-ladder__table td {
  padding: 5px 8px;
  border-bottom: 1px dashed rgba(139, 107, 239, 0.10);
  color: var(--idv-ink);
}

/* Staggered row reveal — rows are visible by default.
   JS may add .is-revealed to trigger entrance animation. */
.idv-ladder__table tbody tr {
  opacity: 1;
  transform: none;
}

/* Stagger delays — set via CSS custom property or nth-child */
.idv-ladder__table tbody tr:nth-child(1).is-visible  { animation-delay: 0ms; }
.idv-ladder__table tbody tr:nth-child(2).is-visible  { animation-delay: 40ms; }
.idv-ladder__table tbody tr:nth-child(3).is-visible  { animation-delay: 80ms; }
.idv-ladder__table tbody tr:nth-child(4).is-visible  { animation-delay: 120ms; }
.idv-ladder__table tbody tr:nth-child(5).is-visible  { animation-delay: 160ms; }
.idv-ladder__table tbody tr:nth-child(6).is-visible  { animation-delay: 200ms; }
.idv-ladder__table tbody tr:nth-child(7).is-visible  { animation-delay: 240ms; }
.idv-ladder__table tbody tr:nth-child(8).is-visible  { animation-delay: 280ms; }
.idv-ladder__table tbody tr:nth-child(9).is-visible  { animation-delay: 320ms; }
.idv-ladder__table tbody tr:nth-child(10).is-visible { animation-delay: 360ms; }
.idv-ladder__table tbody tr:nth-child(11).is-visible { animation-delay: 400ms; }
.idv-ladder__table tbody tr:nth-child(12).is-visible { animation-delay: 440ms; }

.idv-ladder__summary {
  margin-top: 10px;
  font-size: 14px;
  color: var(--idv-ink-soft);
}

.idv-ladder__summary strong {
  color: var(--idv-ink);
}

/* --- tool notes (paper card) --- */
.idv-notes {
  max-width: none;
  grid-template-columns: minmax(0, 1.25fr) minmax(18rem, 0.75fr);
  align-items: start;
  gap: 14px 28px;
}

.idv-page .tool-notes {
  border: 1px dashed rgba(139, 107, 239, 0.16);
  background:
    radial-gradient(circle at top right, rgba(139, 107, 239, 0.04), transparent 30%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), var(--idv-paper));
  box-shadow: 0 8px 24px rgba(139, 107, 239, 0.05);
}

.idv-page .tool-notes .card-title {
  color: var(--idv-ink);
}

.idv-page .tool-notes .card-text {
  color: var(--idv-ink-soft);
}

.idv-notes .card-title {
  grid-column: 1 / -1;
}

.idv-notes .card-text {
  font-size: 15px;
  line-height: 1.65;
}

.idv-notes .card-text:first-of-type {
  grid-column: 1 / 2;
}

.idv-notes .card-text:not(:first-of-type) {
  grid-column: 2 / 3;
}

.idv-notes .card-text strong {
  color: var(--idv-ink);
}

/* --- keyframes: measured-reveal --- */

/* Seal badge: fade-in + scale-up, feels like an official stamp being pressed */
@keyframes sealReveal {
  0% {
    opacity: 0;
    transform: translateY(-50%) rotate(-12deg) scale(0.6);
  }
  60% {
    opacity: 0.30;
    transform: translateY(-50%) rotate(-14deg) scale(1.04);
  }
  100% {
    opacity: 0.28;
    transform: translateY(-50%) rotate(-12deg) scale(1);
  }
}

/* Ladder rows: sequential gentle reveal from below */
@keyframes ladderRowReveal {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Result card entrance */
@keyframes resultCardReveal {
  0% {
    opacity: 0.6;
    transform: scale(0.98);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.idv-result[data-valid="true"],
.idv-result[data-valid="false"] {
  animation: resultCardReveal 350ms ease-out;
}

/* --- responsive --- */
@media (max-width: 960px) {
  .idv-bench__layout {
    gap: 9px;
  }

  .idv-notes {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .idv-notes .card-text:first-of-type,
  .idv-notes .card-text:not(:first-of-type) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .idv-bench__layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .idv-panel--inputs,
  .idv-panel--result {
    flex: initial;
  }

  .idv-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .idv-page .tool-header-block {
    padding-right: 0;
  }

  .idv-language-toggle {
    position: static;
    margin-bottom: 8px;
  }

  .idv-page .page-title {
    font-size: clamp(1.8rem, 7vw, 2.2rem);
  }

  .idv-page .page-subtitle {
    max-width: 24rem;
    font-size: 15px;
    line-height: 1.5;
  }

  .idv-bench__rail {
    display: none;
  }

  .idv-panel {
    padding: 14px;
  }

  .idv-panel__hint {
    display: none;
  }

  .idv-input {
    font-size: 1.1rem;
    letter-spacing: 0.14em;
  }

  .idv-result__value {
    font-size: 1.4rem;
  }

  .idv-field__label {
    font-size: 14px;
  }

  .idv-chip,
  .idv-badge,
  .idv-sample-chip {
    font-size: 12px;
  }

  .idv-feedback,
  .idv-result__detail,
  .idv-notes .card-text {
    font-size: 14px;
  }
}

@media (max-width: 520px) {
  .idv-actions {
    gap: 8px;
  }

  .idv-actions .button-primary {
    min-width: 0;
    padding-inline: 20px;
  }

  .idv-actions__minor {
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .idv-result__stamp,
  .idv-ladder__table tbody tr,
  .idv-result,
  .idv-sample-chip,
  .idv-language-button {
    animation: none !important;
    transition: none !important;
  }

  .idv-ladder__table tbody tr {
    opacity: 1;
    transform: none;
  }

  .idv-result[data-valid="true"] .idv-result__stamp,
  .idv-result[data-valid="false"] .idv-result__stamp {
    opacity: 0.28;
    transform: translateY(-50%) rotate(-12deg) scale(1);
  }
}

/* Mobile tap targets — bring sample chips and small chrome controls up to
   WCAG 2.5.5 minimum (44×44) on phones. Desktop keeps the denser sizing. */
@media (max-width: 479px) {
  .idv-sample-chip { min-height: 44px; padding: 10px 14px; display: inline-flex; align-items: center; }
  .idv-language-button { min-height: 44px; }
}
