/* ============================================================================
   Perisai Digital — Enterprise Design Tokens, Architectural Surface & Motion
   Standar: Borderless Editorial (Anthropic / Stripe / Linear / Vercel)
   100% Pure CSS (Nonce CSP Safe, Zero WebGL/Blobs/Neon, GPU-Accelerated 60fps)
   ============================================================================ */

:root {
  --ease-out-expo: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-micro: 150ms;
  --dur-view: 280ms;
  --dur-reveal: 320ms;

  /* Enterprise Editorial Surface Tokens (Light Mode — Warm Paper #FAF9F6) */
  --pd-canvas: #FAF9F6;
  --pd-surface-subtle: #F3F1EC;
  --pd-ink: #1A1A18;
  --pd-ink-muted: #5C5A54;
  --pd-rail-line: rgba(26, 26, 24, 0.08);
  --pd-grid-size: 36px;
  --pd-grid-line: rgba(26, 26, 24, 0.036);
  --pd-wash-color: rgba(214, 202, 178, 0.06);
  --pd-grain-opacity: 0.022;
  --pd-accent-line: var(--accent, var(--brand, #1B4D3E));
}

:root[data-theme="dark"],
html[data-theme="dark"] {
  /* Enterprise Editorial Surface Tokens (Dark Mode — Warm Charcoal #131312) */
  --pd-canvas: #131312;
  --pd-surface-subtle: #1B1B19;
  --pd-ink: #ECEAE4;
  --pd-ink-muted: #9A978E;
  --pd-rail-line: rgba(236, 234, 228, 0.09);
  --pd-grid-line: rgba(236, 234, 228, 0.045);
  --pd-wash-color: rgba(255, 255, 255, 0.045);
  --pd-grain-opacity: 0.026;
  --pd-accent-line: var(--accent, var(--brand, #7FB59E));
}

/* Global Font-Scale Sync (A- / Normal / A+ dari /pengaturan) */
html[data-font-scale="down"] { font-size: 92%; }
html[data-font-scale="up"] { font-size: 112.5%; }

/* ============================================================================
   1. FOUR-LAYER ARCHITECTURAL BACKGROUND + ANTI-LOCKOUT LAYERING
   L1: Warm Canvas (#FAF9F6 / #131312)
   L2: Precision Drafting Grid (36px) with radial top-ellipse edge fade
   L3: Monochromatic Ambient Top Wash (<= 6% opacity, zero neon)
   L4: Subtle Tactile Micro-Grain (SVG fractalNoise, opacity ~2.2%)
   ============================================================================ */
body {
  position: relative;
  isolation: isolate;
}

header,
main,
footer {
  position: relative;
  z-index: 1;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1 !important;
  pointer-events: none !important;
  user-select: none !important;
  background-image:
    radial-gradient(ellipse 82% 40% at 50% 0%, var(--pd-wash-color) 0%, transparent 72%),
    linear-gradient(to right, var(--pd-grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--pd-grid-line) 1px, transparent 1px);
  background-size:
    100% 100%,
    var(--pd-grid-size) var(--pd-grid-size),
    var(--pd-grid-size) var(--pd-grid-size);
  background-position: top center, top center, top center;
  -webkit-mask-image: radial-gradient(ellipse 92% 72% at 50% 10%, #000 0%, rgba(0, 0, 0, 0.5) 54%, transparent 100%);
  mask-image: radial-gradient(ellipse 92% 72% at 50% 10%, #000 0%, rgba(0, 0, 0, 0.5) 54%, transparent 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1 !important;
  pointer-events: none !important;
  user-select: none !important;
  opacity: var(--pd-grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 160px 160px;
}

/* Layer 5: Desktop Editorial Guide Rails (>= 1280px, Vercel/Linear framing) */
@media (min-width: 1280px) {
  .pd-rails {
    border-left: 1px solid var(--pd-rail-line);
    border-right: 1px solid var(--pd-rail-line);
  }
}

/* Pengaman Kritis: seluruh overlay/dialog/menu tertutup tidak pernah menangkap klik */
[role="dialog"].hidden,
#a11yMenu.hidden,
#commandBarBackdrop.hidden,
#tourBackdrop.hidden,
#verifikatorLoginModal.hidden,
#editScoreModal.hidden,
#aiAssistantDesk.hidden,
#privacyPolicyModal.hidden,
#deleteAccountModal.hidden {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* ============================================================================
   2. EDITORIAL TYPOGRAPHY, NUMBERING & MEASURE DISCIPLINE
   ============================================================================ */
h1 {
  letter-spacing: -0.03em;
}

h2 {
  letter-spacing: -0.025em;
}

.pd-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.pd-num-index {
  display: inline-block;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--pd-accent-line);
  font-variant-numeric: tabular-nums;
  margin-right: 8px;
}

.pd-measure {
  max-width: 65ch;
  line-height: 1.65;
}

.tabular-nums,
[data-numeric] {
  font-variant-numeric: tabular-nums;
}

/* ============================================================================
   3. PRECISION MOTION PRIMITIVES (GPU-ACCELERATED, ZERO BOUNCE, CLS = 0)
   ============================================================================ */

/* 3A. Staggered Editorial Reveal (< 380ms total for key focal elements) */
@keyframes pdRevealUp {
  from {
    opacity: 0;
    transform: translate3d(0, 8px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.pd-reveal {
  animation: pdRevealUp var(--dur-reveal) var(--ease-out-expo) both;
}

.pd-stagger > * {
  animation: pdRevealUp var(--dur-view) var(--ease-out-expo) both;
}
.pd-stagger > *:nth-child(1) { animation-delay: 0ms; }
.pd-stagger > *:nth-child(2) { animation-delay: 40ms; }
.pd-stagger > *:nth-child(3) { animation-delay: 80ms; }
.pd-stagger > *:nth-child(4) { animation-delay: 120ms; }
.pd-stagger > *:nth-child(5) { animation-delay: 160ms; }
.pd-stagger > *:nth-child(6) { animation-delay: 200ms; }
.pd-stagger > *:nth-child(7) { animation-delay: 240ms; }
.pd-stagger > *:nth-child(n+8) { animation-delay: 260ms; }

/* 3B. Gliding Active Hairline Indicator (GPU transform translate3d + scaleX) */
.pd-tabs-gliding {
  position: relative;
}

.pd-tab-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 2px;
  background-color: var(--pd-accent-line);
  transform-origin: left center;
  transform: translate3d(var(--ind-x, 0px), 0, 0) scaleX(var(--ind-w, 0));
  transition:
    transform var(--dur-view) var(--ease-out-expo),
    opacity var(--dur-micro) var(--ease-out-expo);
  pointer-events: none;
  will-change: transform;
  opacity: 0;
}

.pd-tab-indicator.is-ready {
  opacity: 1;
}

.pd-tabs-gliding.has-gliding-indicator .tab-btn-active,
.pd-tabs-gliding.has-gliding-indicator .tab-btn.active {
  border-bottom-color: transparent;
}

/* 3C. Smooth Grid-Row Accordion (grid-template-rows: 0fr -> 1fr) */
.pd-accordion {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
  transition:
    grid-template-rows var(--dur-view) var(--ease-out-expo),
    opacity 200ms var(--ease-out-expo);
}

.pd-accordion.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
  pointer-events: auto;
}

.pd-accordion-inner {
  overflow: hidden;
  min-height: 0;
}

/* 3D. Tactile Press Feedback & Precision Focus Hairline Sweep */
button,
[role="button"],
.btn-primary,
.btn-solid {
  transition:
    transform var(--dur-micro) var(--ease-out-expo),
    background-color var(--dur-micro) var(--ease-out-expo),
    color var(--dur-micro) var(--ease-out-expo),
    border-color var(--dur-micro) var(--ease-out-expo),
    opacity var(--dur-micro) var(--ease-out-expo);
}

button:not(:disabled):active,
[role="button"]:active,
.btn-primary:not(:disabled):active,
.btn-solid:not(:disabled):active {
  transform: scale(0.985);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
textarea,
select {
  background-image: linear-gradient(var(--pd-accent-line), var(--pd-accent-line));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  transition:
    background-size 240ms var(--ease-out-expo),
    border-color var(--dur-micro) var(--ease-out-expo),
    background-color var(--dur-micro) var(--ease-out-expo);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
textarea:focus,
select:focus {
  background-size: 100% 1px;
}

/* Copy Checkmark Micro-Feedback */
.pd-copy-done {
  color: var(--pd-accent-line) !important;
  font-weight: 600;
}

/* 3E. Precision File Inspector Dropzone (Drag-Over + 2px Top Progress Sweep) */
@keyframes pdProgressSweep {
  0% { transform: translate3d(-100%, 0, 0); }
  100% { transform: translate3d(260%, 0, 0); }
}

.pd-dropzone {
  position: relative;
  overflow: hidden;
  transition:
    border-color var(--dur-micro) var(--ease-out-expo),
    background-color var(--dur-micro) var(--ease-out-expo),
    transform var(--dur-micro) var(--ease-out-expo);
}

.pd-dropzone.is-dragover {
  border-color: var(--pd-accent-line) !important;
  background-color: var(--pd-surface-subtle);
}

.pd-dropzone::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 38%;
  height: 2px;
  background-color: var(--pd-accent-line);
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
  pointer-events: none;
  transition: opacity var(--dur-micro) var(--ease-out-expo);
}

.pd-dropzone.is-scanning::before {
  opacity: 1;
  animation: pdProgressSweep 1.15s var(--ease-out-expo) infinite;
}

/* 3F. Precision AI Streaming Cursor (Thin Vertical Bar, Vanishes on Done) */
@keyframes pdCaretBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.15; }
}

.pd-streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.14em;
  background-color: var(--pd-accent-line);
  animation: pdCaretBlink 0.9s steps(2, start) infinite;
}

/* 3G. Calm Live Dot, Stat Tick & Inline Confirm Row (Verifikator) */
@keyframes pdLivePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.48; transform: scale(0.88); }
}

.pd-live-dot,
.dot-online {
  animation: pdLivePulse 2.4s var(--ease-out-expo) infinite;
}

@keyframes pdStatTick {
  0% { opacity: 0.45; transform: translate3d(0, 3px, 0); }
  100% { opacity: 1; transform: translate3d(0, 0, 0); }
}

.pd-stat-bump {
  animation: pdStatTick 240ms var(--ease-out-expo) both;
}

/* 3H. Calm Toast Slide-Up & Quick Switcher Overlay Reveal */
@keyframes pdToastIn {
  from {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.pd-toast-in {
  animation: pdToastIn 240ms var(--ease-out-expo) both;
}

@keyframes pdDialogIn {
  from {
    opacity: 0;
    transform: translate3d(0, -6px, 0) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.pd-cmd-dialog {
  animation: pdDialogIn 220ms var(--ease-out-expo) both;
}

/* Terminal Execution Mode Tag (Minimal Editorial, Zero Neon) */
.pd-mode-tag {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-left: 6px;
  border-left: 1px solid var(--line-strong, var(--divider-strong));
}

/* ============================================================================
   4. ACCESSIBILITY: REDUCED MOTION (OS PREFERENCE + IN-APP TOGGLE)
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
  .pd-reveal,
  .pd-stagger > *,
  .pd-toast-in,
  .pd-cmd-dialog,
  .pd-stat-bump,
  .pd-live-dot,
  .dot-online,
  .pd-dropzone.is-scanning::before,
  .pd-streaming::after {
    animation: none !important;
    transform: none !important;
  }

  .pd-tab-indicator,
  .pd-accordion,
  button,
  [role="button"],
  input,
  textarea,
  select {
    transition-duration: 0.001ms !important;
  }

  button:not(:disabled):active,
  [role="button"]:active {
    transform: none !important;
  }
}

html.a11y-reduce-motion .pd-reveal,
html.a11y-reduce-motion .pd-stagger > *,
html.a11y-reduce-motion .pd-toast-in,
html.a11y-reduce-motion .pd-cmd-dialog,
html.a11y-reduce-motion .pd-stat-bump,
html.a11y-reduce-motion .pd-live-dot,
html.a11y-reduce-motion .dot-online,
html.a11y-reduce-motion .pd-dropzone.is-scanning::before,
html.a11y-reduce-motion .pd-streaming::after {
  animation: none !important;
  transform: none !important;
}

html.a11y-reduce-motion .pd-tab-indicator,
html.a11y-reduce-motion .pd-accordion {
  transition-duration: 0.001ms !important;
}
