@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  /* ===== Light mode (default) ===== */
  :root {
    --ink-950: 255 255 255;
    --ink-900: 249 250 251;
    --ink-800: 243 244 246;
    --ink-700: 229 231 235;
    --ink-600: 209 213 219;
    --ink-500: 156 163 175;
    --ink-400: 107 114 128;
    --ink-300: 75 85 99;
    --ink-200: 55 65 81;
    --ink-100: 31 41 55;
    --ink-50:  17 24 39;

    --accent: 180 83 9;
    --accent-light: 217 119 6;
    --accent-dark: 146 64 14;
  }

  /* ===== Dark mode ===== */
  .dark {
    --ink-950: 8 8 12;
    --ink-900: 17 17 23;
    --ink-800: 26 26 35;
    --ink-700: 34 34 48;
    --ink-600: 42 42 56;
    --ink-500: 63 63 80;
    --ink-400: 92 92 110;
    --ink-300: 152 152 168;
    --ink-200: 192 192 204;
    --ink-100: 237 237 240;
    --ink-50:  248 248 250;

    --accent: 217 119 6;
    --accent-light: 245 158 11;
    --accent-dark: 180 83 9;
  }

  html {
    scroll-behavior: smooth;
  }

  body {
    @apply bg-ink-950 text-ink-100 font-sans antialiased;
    background-image:
      radial-gradient(ellipse 80% 50% at 50% -20%, rgb(var(--accent) / 0.04), transparent);
  }

  ::selection {
    @apply bg-accent/30;
    color: rgb(var(--ink-50));
  }
}

/* Scroll-triggered reveal */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered children animation */
.stagger > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.stagger.visible > *:nth-child(1) { transition-delay: 0.05s; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(2) { transition-delay: 0.1s; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(3) { transition-delay: 0.15s; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(4) { transition-delay: 0.2s; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(5) { transition-delay: 0.25s; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(6) { transition-delay: 0.3s; opacity: 1; transform: translateY(0); }

/* Timeline */
.timeline-line {
  @apply absolute left-0 top-0 bottom-0 w-px;
  background: linear-gradient(to bottom, rgb(var(--accent)) 0%, rgb(var(--ink-600)) 40%, transparent 100%);
}

.timeline-item {
  @apply relative pl-8;
}

.timeline-item::before {
  content: '';
  @apply absolute w-2.5 h-2.5 rounded-full -left-[5px] top-2;
  border: 2px solid rgb(var(--accent));
  background: rgb(var(--ink-950));
  box-shadow: 0 0 8px rgb(var(--accent) / 0.3);
}

.timeline-item:first-child::before {
  background: rgb(var(--accent));
  box-shadow: 0 0 12px rgb(var(--accent) / 0.5);
}

.dark .timeline-item::before {
  box-shadow: 0 0 8px rgb(var(--accent) / 0.4);
}

.dark .timeline-item:first-child::before {
  box-shadow: 0 0 12px rgb(var(--accent) / 0.6);
}

/* Vulnerability accordion */
.vuln-details {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.3s ease-out,
              padding 0.3s ease-out;
}

.vuln-details.expanded {
  max-height: 250px;
  opacity: 1;
  padding: 1rem 1.25rem;
}

/* Grain texture overlay */
.grain::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.02;
  pointer-events: none;
  z-index: 9999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.dark .grain::after {
  opacity: 0.012;
}

/* Card hover effect */
.card-hover {
  @apply transition-all duration-300;
}

.card-hover:hover {
  @apply border-ink-500 bg-ink-800/80;
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgb(0 0 0 / 0.06);
}

.dark .card-hover:hover {
  box-shadow: 0 8px 32px rgb(0 0 0 / 0.3);
}

/* Locale switcher buttons */
.locale-btn {
  @apply px-3 py-1.5 rounded-md text-sm font-medium transition-all duration-200
         text-ink-300 hover:text-ink-100 border border-transparent hover:border-ink-600;
}

.locale-btn.active {
  @apply text-accent border-accent/40 bg-accent/10;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: rgb(var(--ink-950));
}

::-webkit-scrollbar-thumb {
  background: rgb(var(--ink-600));
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgb(var(--ink-500));
}

/* Section navigation */
.section-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.375rem 0;
  text-decoration: none;
}

.section-nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: rgb(var(--ink-600));
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.section-nav-link:hover .section-nav-dot,
.section-nav-link.active .section-nav-dot {
  background: rgb(var(--accent));
  box-shadow: 0 0 8px rgb(var(--accent) / 0.4);
  width: 8px;
  height: 8px;
}

.section-nav-label {
  font-size: 0.6875rem;
  letter-spacing: 0.03em;
  color: rgb(var(--ink-500));
  opacity: 0;
  transform: translateX(-4px);
  transition: all 0.2s ease-out;
  white-space: nowrap;
  font-family: 'Outfit', system-ui, sans-serif;
}

.section-nav-link:hover .section-nav-label {
  opacity: 1;
  transform: translateX(0);
  color: rgb(var(--ink-300));
}

.section-nav-link.active .section-nav-label {
  opacity: 1;
  transform: translateX(0);
  color: rgb(var(--accent));
}

/* Vulnerability filtering */
.vendor-chip {
  cursor: pointer;
  transition: all 0.2s ease-out;
}

.vendor-chip:hover {
  border-color: rgb(var(--ink-500) / 0.5) !important;
}

.vendor-chip.active {
  border-color: rgb(var(--accent) / 0.5) !important;
  background: rgb(var(--accent) / 0.1) !important;
}

.vendor-chip.active span:last-child {
  color: rgb(var(--accent));
}

.vuln-card {
  transition: opacity 0.25s ease-out;
}

.vuln-card.filtered-out {
  display: none;
}

/* Mobile */
@media (max-width: 640px) {
  .vuln-details.expanded {
    max-height: 400px;
  }

  .vuln-component {
    display: none;
  }
}

/* =============================================
   Print styles — resume-grade PDF output
   ============================================= */
@media print {
  /* ---------- Page setup ---------- */
  /* margin-left/right/bottom 0 removes browser header/footer (URL, date, page number) */
  /* top margin gives breathing room on continuation pages */
  @page {
    size: A4;
    margin: 10mm 0 0 0;
  }

  /* First page: no top margin (body padding handles it) */
  @page :first {
    margin-top: 0;
  }

  /* ---------- Force light palette ---------- */
  :root, .dark {
    --ink-950: 255 255 255;
    --ink-900: 255 255 255;
    --ink-800: 249 250 251;
    --ink-700: 229 231 235;
    --ink-600: 209 213 219;
    --ink-500: 156 163 175;
    --ink-400: 107 114 128;
    --ink-300: 75 85 99;
    --ink-200: 55 65 81;
    --ink-100: 31 41 55;
    --ink-50: 17 24 39;
    --accent: 30 64 175;        /* professional blue for print */
    --accent-light: 37 99 235;
    --accent-dark: 30 58 138;
  }

  * {
    transition: none !important;
    animation: none !important;
  }

  /* ---------- Base & Fonts ---------- */
  html {
    font-size: 13px !important;
  }

  body {
    background: white !important;
    background-image: none !important;
    color: #1f2937 !important;
    line-height: 1.45 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    /* Use body padding instead of @page margin to avoid browser header/footer */
    margin: 0 !important;
    padding: 12mm 16mm !important;
    font-family: 'Noto Sans KR', 'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
    font-feature-settings: 'tnum' 1, 'cv01' 1, 'cv02' 1 !important; /* tabular numbers + alternates */
  }

  /* Headings — CJK first to prevent broken Korean/Japanese glyphs on Windows */
  h1, h2, h3 {
    font-family: 'Noto Sans KR', 'Noto Sans JP', 'Inter', -apple-system, sans-serif !important;
    font-weight: 700 !important;
  }

  /* Mono elements — Inter for numbers, fallback to JetBrains */
  .font-mono, code, pre {
    font-family: 'JetBrains Mono', 'SF Mono', monospace !important;
    font-feature-settings: 'tnum' 1 !important;
  }

  .grain::after {
    display: none !important;
  }

  main {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ---------- Hide UI chrome ---------- */
  #section-nav,
  #back-to-top,
  #pdf-export,
  .fixed.top-4.right-4,
  footer {
    display: none !important;
  }

  /* ---------- Disable animations ---------- */
  .reveal, .stagger > * {
    opacity: 1 !important;
    transform: none !important;
  }

  /* ==========================================
     HERO / PROFILE — compact resume header
     ========================================== */
  section[data-analytics-section="hero"] {
    margin-bottom: 1.25rem !important;
    padding-top: 0 !important;
    border-bottom: 2px solid rgb(var(--accent));
    padding-bottom: 1rem;
  }

  /* Profile image row */
  section[data-analytics-section="hero"] > div:first-child {
    gap: 1rem !important;
    margin-bottom: 0.5rem !important;
    align-items: center !important;
  }

  /* Hide image glow */
  section[data-analytics-section="hero"] .relative.group .absolute {
    display: none !important;
  }

  /* Profile image */
  section[data-analytics-section="hero"] img {
    width: 72px !important;
    height: 72px !important;
    border: 1.5px solid #d1d5db !important;
  }

  /* Name */
  section[data-analytics-section="hero"] h1 {
    font-size: 1.75rem !important;
    margin-bottom: 0.125rem !important;
    line-height: 1.2 !important;
  }

  /* Subtitle & bio */
  section[data-analytics-section="hero"] h1 + p {
    font-size: 0.875rem !important;
    margin-bottom: 0.125rem !important;
  }

  section[data-analytics-section="hero"] h1 ~ p {
    font-size: 0.75rem !important;
  }

  section[data-analytics-section="hero"] ul {
    margin-top: 0.25rem !important;
    font-size: 0.75rem !important;
    space-y: 0 !important;
  }

  section[data-analytics-section="hero"] ul li {
    margin-bottom: 0 !important;
  }

  /* Links row — inline text, no boxes */
  section[data-analytics-section="hero"] > div:last-child {
    gap: 0.25rem 0.75rem !important;
    margin-top: 0.5rem !important;
  }

  section[data-analytics-section="hero"] > div:last-child a {
    background: none !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    font-size: 0.7rem !important;
    color: rgb(var(--accent)) !important;
    text-decoration: underline !important;
  }

  section[data-analytics-section="hero"] > div:last-child a svg {
    display: none !important;
  }

  /* Show URL after link text for hero links */
  section[data-analytics-section="hero"] > div:last-child a::after {
    content: " (" attr(href) ")" !important;
    font-size: 0.6rem !important;
    color: #6b7280 !important;
    text-decoration: none !important;
  }

  /* ==========================================
     SECTION HEADINGS — clean line style
     ========================================== */
  section h2 {
    font-size: 0.95rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.08em !important;
    margin-bottom: 0.625rem !important;
    padding-bottom: 0.25rem !important;
    border-bottom: 1px solid rgb(var(--accent)) !important;
    color: rgb(var(--accent)) !important;
  }

  /* Hide accent bar */
  section h2 > span.bg-accent {
    display: none !important;
  }

  /* Section spacing */
  section {
    margin-bottom: 1rem !important;
  }

  /* ==========================================
     EDUCATION — compact
     ========================================== */
  #education .space-y-8 {
    gap: 0.375rem !important;
  }

  #education .space-y-8 > * + * {
    margin-top: 0.375rem !important;
  }

  /* Timeline — thin & subtle */
  .timeline-line {
    background: #d1d5db !important;
  }

  .timeline-item {
    padding-left: 1.25rem !important;
  }

  .timeline-item::before {
    width: 6px !important;
    height: 6px !important;
    left: -3px !important;
    box-shadow: none !important;
    border-color: rgb(var(--accent)) !important;
  }

  .timeline-item:first-child::before {
    box-shadow: none !important;
  }

  /* ==========================================
     WORK EXPERIENCE — tighter
     ========================================== */
  #work-experience {
    break-inside: auto !important;
  }

  #work-experience .space-y-10 > * + * {
    margin-top: 0.625rem !important;
  }

  #work-experience .timeline-item .mb-3 {
    margin-bottom: 0.25rem !important;
  }

  #work-experience ul {
    margin-top: 0.125rem !important;
  }

  #work-experience ul li {
    margin-bottom: 0.125rem !important;
    font-size: 0.8rem !important;
  }

  #work-experience .space-y-2 > * + * {
    margin-top: 0.125rem !important;
  }

  /* Each work item avoids mid-break, but the section flows freely */
  #work-experience .timeline-item {
    break-inside: avoid;
  }

  /* ==========================================
     CTF AWARDS — compact grid / list
     ========================================== */
  #ctf-awards .grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.375rem !important;
  }

  #ctf-awards .card-hover,
  #ctf-awards .bg-ink-900 {
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 4px !important;
    padding: 0.375rem 0.5rem !important;
  }

  #ctf-awards .card-hover:hover {
    transform: none !important;
    box-shadow: none !important;
  }

  #ctf-awards h3 {
    font-size: 0.8rem !important;
  }

  #ctf-awards .text-xs {
    font-size: 0.675rem !important;
  }

  #ctf-awards .mb-2 {
    margin-bottom: 0.125rem !important;
  }

  /* Award money — smaller */
  #ctf-awards .text-sm.font-semibold.text-accent {
    font-size: 0.7rem !important;
    margin-top: 0.125rem !important;
  }

  /* ==========================================
     VULNERABILITIES — compact table style
     ========================================== */
  /* Hide filter toolbar */
  #vulnerabilities > div[role="toolbar"] {
    display: none !important;
  }

  /* Sub-headings */
  .vuln-group h3 {
    font-size: 0.75rem !important;
    margin-bottom: 0.375rem !important;
    margin-left: 0 !important;
  }

  .vuln-group {
    margin-bottom: 0.5rem !important;
  }

  /* Vuln cards — flat rows */
  .vuln-card {
    background: white !important;
    border: none !important;
    border-bottom: 1px solid #f3f4f6 !important;
    border-radius: 0 !important;
  }

  .vuln-card.filtered-out {
    display: block !important;
  }

  /* Vuln button (row) */
  .vuln-card button {
    padding: 0.25rem 0 !important;
    cursor: default !important;
  }

  .vuln-card button > div:first-child {
    margin-bottom: 0 !important;
  }

  /* Hide chevron icon */
  .vuln-card button svg[id$="-icon"] {
    display: none !important;
  }

  /* Vuln title line — inline with identifier */
  .vuln-card button > p {
    display: inline !important;
    margin-left: 0.5rem !important;
    font-size: 0.7rem !important;
  }

  /* Vendor logo — small */
  .vuln-card img {
    width: 14px !important;
    height: 14px !important;
  }

  .vuln-card .font-mono.text-sm {
    font-size: 0.725rem !important;
  }

  /* Type badge */
  .vuln-type-badge {
    display: inline-block !important;
    font-size: 0.6rem !important;
    padding: 0 0.25rem !important;
  }

  /* CVSS badge */
  .vuln-card .text-xs.font-mono.font-bold {
    font-size: 0.6rem !important;
    padding: 0 0.25rem !important;
  }

  /* Hide vuln details (description + links) for compact resume */
  .vuln-details {
    display: none !important;
  }

  /* ==========================================
     TALKS — compact rows
     ========================================== */
  #talks .space-y-3 > * + * {
    margin-top: 0.25rem !important;
  }

  #talks .card-hover,
  #talks .bg-ink-900 {
    background: white !important;
    border: none !important;
    border-bottom: 1px solid #f3f4f6 !important;
    border-radius: 0 !important;
    padding: 0.25rem 0 !important;
  }

  #talks .card-hover:hover {
    transform: none !important;
    box-shadow: none !important;
  }

  #talks h3 {
    font-size: 0.8rem !important;
  }

  #talks p {
    font-size: 0.7rem !important;
  }

  /* ==========================================
     BLOGS — compact rows
     ========================================== */
  #blogs .space-y-3 > * + * {
    margin-top: 0.25rem !important;
  }

  #blogs .card-hover {
    background: white !important;
    border: none !important;
    border-bottom: 1px solid #f3f4f6 !important;
    border-radius: 0 !important;
    padding: 0.25rem 0 !important;
  }

  #blogs .card-hover:hover {
    transform: none !important;
    box-shadow: none !important;
  }

  #blogs h3 {
    font-size: 0.8rem !important;
  }

  /* Hide external link icon in blogs */
  #blogs svg {
    display: none !important;
  }

  #blogs .font-mono.text-xs {
    font-size: 0.65rem !important;
    color: #9ca3af !important;
  }

  /* ==========================================
     PAGE BREAK CONTROL
     ========================================== */
  section {
    break-inside: auto;
  }

  #vulnerabilities {
    break-inside: auto;
  }

  .vuln-card {
    break-inside: avoid;
  }

  #ctf-awards {
    break-inside: auto;
  }

  #ctf-awards .grid > div {
    break-inside: avoid;
  }

  /* ==========================================
     LINK DECORATION
     ========================================== */
  a[href]::after {
    content: none !important; /* Don't print URLs after links */
  }

  a {
    text-decoration: none !important;
    color: inherit !important;
  }

  /* Keep accent color only for explicit link sections */
  section[data-analytics-section="hero"] > div:last-child a {
    color: rgb(var(--accent)) !important;
    text-decoration: underline !important;
  }
}
