@import './tokens.css';

/* ── Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  letter-spacing: 0;
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

img, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ── Links ── */
a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.2s ease;
}

a:hover {
  border-bottom-color: var(--accent);
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
}

h1 { font-size: var(--text-5xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-xl); }

p {
  margin-bottom: var(--space-5);
  color: var(--text-secondary);
}

ul, ol {
  margin-bottom: var(--space-5);
  padding-left: var(--space-6);
}

li {
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
}

/* ── Layout utility ── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.container-wide {
  max-width: var(--max-width-wide);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.container-fluid {
  width: 100%;
  padding: 0 var(--space-6);
}

/* ── Lock screen utilities ──
 * These classes are referenced by LockScreen.svelte's template logic
 * (class:lock-visible, class:lock-fading) but are NOT defined in the
 * component's scoped <style> block. They MUST live in global CSS.
 */
.lock-visible {
  display: flex !important;
}

.lock-fading {
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

/* ── Content page styles ──
 * These style HTML injected by {@html data.html} from rendered MDX.
 * Because the markup is generated at build time and injected dynamically,
 * component-scoped CSS cannot target it. These rules MUST stay global.
 */
.content-page {
  padding-top: var(--space-4);
}

.content-page h1 {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-4);
  letter-spacing: -0.03em;
  font-weight: 500;
}

.content-page h2 {
  font-size: var(--text-2xl);
  margin-top: var(--space-8);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

.content-page h3 {
  font-size: var(--text-lg);
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
  color: var(--text-secondary);
  font-weight: 500;
}

.content-page p {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: var(--space-5);
}

.content-page a {
  color: var(--text);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.content-page a:hover {
  border-bottom-color: var(--accent);
}

.content-page img,
.content-page svg {
  border: 1px solid var(--border);
  margin: var(--space-6) 0;
}

.content-page .video-player svg,
.content-page .video-center-play svg {
  border: none;
  margin: 0;
}

.content-page table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-6) 0 var(--space-8);
  font-size: var(--text-sm);
  border: 1px solid var(--border);
}

.content-page th {
  background: var(--surface);
  font-weight: 500;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.content-page td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.content-page tr:last-child td {
  border-bottom: none;
}

.content-page code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface);
  padding: 2px 5px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.content-page pre {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: var(--space-4);
  overflow-x: auto;
  margin: var(--space-6) 0 var(--space-8);
}

.content-page pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: var(--text-sm);
}

.content-page ul, .content-page ol {
  margin-bottom: var(--space-5);
  padding-left: var(--space-5);
}

.content-page li {
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
}

.content-page blockquote {
	border-left: 2px solid var(--accent);
	padding-left: var(--space-5);
	margin: var(--space-6) 0;
	color: var(--text-muted);
	font-style: italic;
}

/* ── CV page ──
 * Editorial CV layout that works over any raw MDX: a vertical hairline
 * rail with an accent dot per section, uppercase section labels, a lead
 * paragraph, and dash list markers. All selectors target plain markdown
 * output (h2/p/ul/strong) — no custom markup required in the MDX.
 */
.cv-page {
	--cv-rail-pad: var(--space-10);
	position: relative;
	padding-left: var(--cv-rail-pad);
	padding-bottom: var(--space-16);
	counter-reset: cv-section;
}

.cv-page::before {
	content: '';
	position: absolute;
	left: calc(var(--space-4) + 3px);
	top: var(--space-2);
	bottom: var(--space-12);
	width: 1px;
	background: var(--border);
}

.cv-page h2 {
	position: relative;
	font-size: var(--text-xs);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.18em;
	color: var(--text-muted);
	border-bottom: none;
	padding-bottom: 0;
	margin: var(--space-12) 0 var(--space-6);
	counter-increment: cv-section;
}

.cv-page h2::after {
	content: '0' counter(cv-section);
	margin-left: var(--space-3);
	font-size: var(--text-xs);
	font-weight: 500;
	letter-spacing: 0.08em;
	color: var(--accent);
	opacity: 0.7;
}

.cv-page h2:first-child {
	margin-top: var(--space-2);
}

.cv-page h2::before {
	content: '';
	position: absolute;
	left: calc(-1 * var(--cv-rail-pad) + var(--space-4));
	top: 50%;
	transform: translateY(-50%);
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--accent);
	box-shadow: 0 0 0 4px var(--bg);
	animation: cv-dot-pulse 2.4s ease-in-out infinite;
}

@keyframes cv-dot-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.45; }
}

/* Lead paragraph: first paragraph of the page (Profile summary) */
.cv-page h2:first-child + p {
	font-size: var(--text-lg);
	line-height: 1.7;
	color: var(--text);
}

.cv-page p {
	line-height: 1.75;
	margin-bottom: var(--space-4);
}

.cv-page p strong {
	color: var(--text);
	font-weight: 600;
}

/* ── CV entry tables (Experience/Education) ──
 * GFM tables with an empty header row (hidden) give real columns from
 * raw MDX: entry title/school stacked in the left cell, dates pinned
 * right. Wrapping stays inside fixed cells, so rows align vertically.
 */
.cv-page table {
	width: 100%;
	border-collapse: collapse;
	margin: 0 0 var(--space-6);
	font-size: inherit;
	border: none;
}

.cv-page thead {
	display: none;
}

.cv-page th,
.cv-page td {
	background: none;
	border: none;
	text-transform: none;
	letter-spacing: normal;
	font-size: inherit;
	color: var(--text-secondary);
	text-align: left;
	vertical-align: top;
	line-height: 1.6;
}

.cv-page td {
	padding: var(--space-4) var(--space-6) var(--space-4) 0;
	border-bottom: 1px solid var(--border);
}

.cv-page td:last-child {
	padding-right: 0;
}

.cv-page tr:last-child td {
	border-bottom: none;
	padding-bottom: var(--space-2);
}

.cv-page td strong {
	color: var(--text);
	font-weight: 600;
}

/* Label tables (no right-aligned date column, e.g. Skills): a fixed
   label column guarantees the detail column always starts at the same
   position and can never collide with it, however long a term is. */
.cv-page table:not(:has(td[align='right'])) {
	table-layout: fixed;
}

.cv-page table:not(:has(td[align='right'])) th:first-child,
.cv-page table:not(:has(td[align='right'])) td:first-child {
	width: 30%;
}

.cv-page td {
	overflow-wrap: break-word;
}

/* Date column: pinned right, never wraps, aligned across rows.
   Keyed off the GFM alignment attribute (---:) so only date columns
   are affected — left-aligned tables (Skills) keep normal wrapping.
   Multi-part dates stack via <br>: "Sep 2012 –<br>Jun 2016". Lines are
   left-aligned inside the tight column so months align over months and
   years directly over years (use 3-letter month abbreviations); the
   trailing dash on line one marks the range. */
.cv-page td[align="right"] {
	width: 1%;
	white-space: nowrap;
	text-align: left;
	line-height: 1.45;
	color: var(--text-muted);
	font-variant-numeric: tabular-nums;
	transition: color 0.15s ease;
}

.cv-page tbody tr:hover td[align="right"] {
	color: var(--text-secondary);
}

/* Coursework line: micro label + muted items, rendered as two adjacent
   <em> elements. Both become inline-block boxes: the label gets a fixed
   track and the items box fills the remaining width, so wrapped course
   names always stay right of the label — never below it. */
.cv-page td em {
	display: inline-block;
	width: 120px;
	vertical-align: top;
	font-style: normal;
	font-size: var(--text-xs);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.12em;
	color: var(--text-muted);
}

.cv-page td em + em {
	width: calc(100% - 120px - var(--space-4));
	font-size: var(--text-sm);
	font-weight: 400;
	text-transform: none;
	letter-spacing: 0.01em;
}

.cv-page ul {
	list-style: none;
	padding-left: 0;
	margin: var(--space-4) 0 var(--space-6);
}

.cv-page li {
	position: relative;
	padding-left: var(--space-6);
	margin-bottom: var(--space-3);
	line-height: 1.7;
}

.cv-page li::before {
	content: '';
	position: absolute;
	left: 0;
	top: 0.75em;
	width: 12px;
	height: 1px;
	background: var(--accent);
	transition: width 0.2s ease;
}

.cv-page li:hover::before {
	width: 20px;
}

@media (max-width: 640px) {
	.cv-page {
		--cv-rail-pad: var(--space-8);
	}
}

/* ── Video player (injected via {@html}, must be global) ── */
.content-page video.video-demo {
	width: 100%;
	aspect-ratio: 1920 / 1242;
	background: var(--surface);
}

/* Hidden until the SW-media watcher takes over (data-sw-media), so the
   pre-enhance element never flashes an unplayable frame. */
.content-page video.video-demo:not([data-sw-media]) {
	opacity: 0;
}

.content-page .video-player {
	position: relative;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow: hidden;
	margin: var(--space-6) 0 var(--space-8);
	background: var(--surface);
}

.content-page .video-area {
	position: relative;
	aspect-ratio: 1920 / 1242;
}

.content-page .video-player video {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	cursor: pointer;
}

.content-page .video-center-play {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 96px;
	height: 96px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: none;
	border-radius: 50%;
	cursor: pointer;
	z-index: 5;
	pointer-events: auto;
	transition: transform 0.2s ease;
}

.content-page .video-center-play:hover {
	transform: translate(-50%, -50%) scale(1.08);
}

.content-page .video-center-play svg {
	width: 80px;
	height: 80px;
	color: #fff;
	filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
	margin-left: 6px;
}

.content-page .video-controls {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-2) var(--space-3);
	border-top: 1px solid var(--border);
	background: var(--surface);
	font-size: var(--text-xs);
	color: var(--text-muted);
	font-variant-numeric: tabular-nums;
}

.content-page .video-btn {
	background: none;
	border: none;
	color: var(--text-muted);
	cursor: pointer;
	padding: var(--space-1);
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--radius);
	transition: color 0.15s ease, background 0.15s ease;
	font-family: inherit;
	font-size: var(--text-xs);
	line-height: 1;
}

.content-page .video-btn:hover {
	color: var(--text);
	background: var(--bg);
}

.content-page .video-btn svg {
	width: 16px;
	height: 16px;
	display: block;
}

.content-page .video-time {
	white-space: nowrap;
	flex-shrink: 0;
	font-size: var(--text-xs);
	color: var(--text-muted);
	letter-spacing: 0.01em;
}

.content-page .video-progress {
	flex: 1;
	height: 4px;
	background: var(--border);
	border-radius: 2px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
	transition: height 0.15s ease;
}

.content-page .video-progress:hover {
	height: 6px;
}

.content-page .video-progress-fill {
	height: 100%;
	background: var(--accent);
	border-radius: 2px;
	transition: width 0.1s linear;
	pointer-events: none;
}

.content-page .video-progress-fill.video-dragging {
	transition: none;
}

.content-page .video-speed {
	min-width: 32px;
	text-align: center;
	font-weight: 500;
}

.content-page .video-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 200px;
	color: var(--text-muted);
	font-size: var(--text-sm);
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

/* ── Video fullscreen overlay ── */
.content-page .video-player:fullscreen,
.content-page .video-player:-webkit-full-screen {
	width: 100vw;
	height: 100vh;
	background: #000;
	border: none;
	border-radius: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

.content-page .video-player:fullscreen video,
.content-page .video-player:-webkit-full-screen video {
	max-width: 100vw;
	max-height: 100vh;
	width: auto;
	height: auto;
	object-fit: contain;
}

.content-page .video-player:fullscreen .video-area,
.content-page .video-player:-webkit-full-screen .video-area,
.content-page .video-player.video-fs .video-area {
	aspect-ratio: auto;
}

.content-page .video-player.video-fs .video-controls {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	background: rgba(0, 0, 0, 0.7);
	border-top: none;
	opacity: 0;
	transform: translateY(8px);
	transition: opacity 0.25s ease, transform 0.25s ease;
	z-index: 10;
	padding: var(--space-3) var(--space-4);
}

.content-page .video-player.video-fs.video-fs-show .video-controls {
	opacity: 1;
	transform: translateY(0);
}

.content-page .video-player.video-fs .video-controls .video-btn,
.content-page .video-player.video-fs .video-controls .video-time {
	color: #fff;
}

.content-page .video-player.video-fs .video-controls .video-btn:hover {
	background: rgba(255, 255, 255, 0.15);
}

.content-page .video-player.video-fs .video-controls .video-progress {
	background: rgba(255, 255, 255, 0.2);
}

.content-page .video-player.video-fs .video-controls .video-progress-fill {
	background: #fff;
}

/* ── Architecture diagram (injected via {@html}, must be global) ──
 * Based on the Cocoon-AI architecture-diagram-generator design system.
 * Dark-themed container with inline SVG diagram and summary cards.
 */
.content-page .arch-diagram {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 1.25rem;
  margin: var(--space-6) 0 var(--space-8);
  overflow: hidden;
  font-family: var(--font-mono);
}

.content-page .arch-diagram-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  color: #f5f5f5;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.content-page .arch-pulse-dot {
  width: 8px;
  height: 8px;
  background: #22d3ee;
  border-radius: 50%;
  animation: arch-pulse 2s infinite;
  flex-shrink: 0;
}

@keyframes arch-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.content-page .arch-diagram svg {
  width: 100%;
  height: auto;
  border: none;
  margin: 0;
  display: block;
}

.content-page .arch-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.content-page .arch-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #1e293b;
  border-radius: 0.5rem;
  padding: 0.875rem 1rem;
}

.content-page .arch-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.content-page .arch-card-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.content-page .arch-card-dot.cyan { background: #22d3ee; }
.content-page .arch-card-dot.emerald { background: #34d399; }
.content-page .arch-card-dot.violet { background: #a78bfa; }
.content-page .arch-card-dot.amber { background: #fbbf24; }
.content-page .arch-card-dot.rose { background: #fb7185; }
.content-page .arch-card-dot.orange { background: #fb923c; }

.content-page .arch-card h4 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #e2e8f0;
  margin: 0;
  line-height: 1.3;
}

.content-page .arch-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.content-page .arch-card li {
  color: #94a3b8;
  font-size: 0.7rem;
  line-height: 1.5;
  margin-bottom: 0.2rem;
  padding: 0;
}

.content-page .arch-card li:last-child {
  margin-bottom: 0;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  html {
    font-size: 15px;
  }

  .container {
    padding: 0 var(--space-5);
  }

  .content-page h1 {
    font-size: var(--text-3xl);
  }
}

/* ── Prism syntax highlighting tokens ── */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--prism-comment, #6e7781);
  font-style: italic;
}

.token.punctuation {
  color: var(--prism-punctuation, #8b949e);
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: var(--prism-property, #79c0ff);
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: var(--prism-string, #a5d6ff);
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: var(--prism-operator, #d2a8ff);
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: var(--prism-keyword, #ff7b72);
}

.token.function,
.token.class-name {
  color: var(--prism-function, #d2a8ff);
}

.token.regex,
.token.important,
.token.variable {
  color: var(--prism-variable, #e3b341);
}

.token.important,
.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}

.token.entity {
  cursor: help;
}

.token.namespace {
  opacity: 0.7;
}

.token.tag {
  color: var(--prism-tag, #7ee787);
}

.token.attr-value {
  color: var(--prism-string, #a5d6ff);
}

.token.builtin {
  color: var(--prism-builtin, #79c0ff);
}

.token.parameter {
  color: var(--prism-parameter, #ffa657);
}
