:root {
  /* 🎨 Design System: 文房 (Study) — Ink & Paper */
  --color-primary: #1a1a2e;
  --color-accent: #e94560;
  --color-surface: #f8f7f4;
  --color-surface-2: #ffffff;
  --color-border: #e8e6e1;
  --color-muted: #9b9a97;
  --color-text: #1a1a2e;
  --color-text-secondary: #6b6b70;
  
  /* Ink brush palette */
  --ink-1: #1a1a2e;
  --ink-2: #4a4a55;
  --ink-3: #8a8a95;
  --paper: #f8f7f4;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  
  /* Radius */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(26,26,46,0.04);
  --shadow-sm: 0 2px 8px rgba(26,26,46,0.06);
  --shadow-md: 0 4px 16px rgba(26,26,46,0.08);
  --shadow-lg: 0 8px 32px rgba(26,26,46,0.10);
  --shadow-focus: 0 0 0 3px rgba(233,69,96,0.15);
  
  /* Typography */
  --font-sans: 'LXGW WenKai', 'PingFang SC', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-surface);
  color: var(--color-text);
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input { font: inherit; }

/* ─── Layout ─── */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-md) var(--space-lg);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.85);
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
  color: var(--color-text);
}

.logo-mark {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-mark svg {
  width: 18px;
  height: 18px;
  color: white;
}

.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.main {
  flex: 1;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* ─── Page System ─── */
.page {
  display: none;
  flex-direction: column;
  gap: var(--space-lg);
}

.page.active {
  display: flex;
}

/* ─── Card ─── */
.card {
  background: var(--color-surface-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.card-pad {
  padding: var(--space-lg);
}

/* ─── Home Page ─── */
.hero-card {
  background: linear-gradient(145deg, var(--color-surface-2) 0%, #f0efe9 100%);
  border: 1px solid var(--color-border);
  position: relative;
  overflow: hidden;
}

.hero-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(233,69,96,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.hero-content {
  position: relative;
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-md);
}

.hero-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--color-text-secondary);
  max-width: 320px;
}

/* ─── Character Canvas Card ─── */
.canvas-card .card-pad {
  padding: var(--space-md);
}

.canvas-wrapper {
  width: 100%;
  aspect-ratio: 1;
  max-width: 360px;
  margin: 0 auto;
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  overflow: hidden;
}

/* Grid background */
.canvas-wrapper::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(var(--color-border) 1px, transparent 1px),
    linear-gradient(90deg, var(--color-border) 1px, transparent 1px);
  background-size: calc(100% / 3) calc(100% / 3);
  opacity: 0.5;
  pointer-events: none;
}

/* Center crosshair */
.canvas-wrapper::after {
  content: '';
  position: absolute;
  inset: 15%;
  border: 1.5px dashed var(--color-border);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0.6;
}

#character-target {
  position: absolute;
  inset: 0;
  touch-action: none;
  cursor: crosshair;
}

/* ─── Progress Dots ─── */
.progress-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
}

.progress-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-border);
  transition: var(--transition-base);
  position: relative;
}

.progress-dot.done {
  background: var(--color-primary);
  transform: scale(0.85);
}

.progress-dot.active {
  background: var(--color-accent);
  transform: scale(1.15);
  box-shadow: 0 0 0 3px rgba(233,69,96,0.15);
}

.progress-label {
  font-size: 0.8rem;
  color: var(--color-muted);
  font-weight: 500;
  min-width: 80px;
  text-align: center;
}

/* ─── Action Buttons ─── */
.btn-row {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition-base);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  min-width: 90px;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn:active {
  transform: scale(0.96);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: #2a2a3e;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1.5px solid var(--color-border);
}

.btn-ghost:hover {
  background: var(--color-surface);
  border-color: var(--color-muted);
}

.btn-accent {
  background: var(--color-accent);
  color: white;
}

.btn-accent:hover {
  background: #d63854;
}

/* ─── Category Tabs ─── */
.tabs-scroll {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-xs);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tabs-scroll::-webkit-scrollbar { display: none; }

.tab {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  background: transparent;
  border: 1.5px solid transparent;
  transition: var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.tab.active {
  background: var(--color-primary);
  color: white;
}

/* ─── Character Grid ─── */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: var(--space-sm);
}

.char-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 600;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
  cursor: pointer;
  color: var(--color-text);
}

.char-btn:hover {
  border-color: var(--color-muted);
  background: var(--color-surface-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

.char-btn:active {
  transform: scale(0.94);
}

.char-btn.current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* ─── Input Row ─── */
.input-row {
  display: flex;
  gap: var(--space-sm);
  align-items: stretch;
}

.input-field {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 1.2rem;
  text-align: center;
  background: var(--color-surface-2);
  color: var(--color-text);
  transition: var(--transition-fast);
  outline: none;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.input-field::placeholder {
  font-weight: 400;
  font-size: 0.9rem;
  letter-spacing: 0;
  color: var(--color-muted);
}

.input-field:focus {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}

/* ─── Section Label ─── */
.section-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-sm);
}

/* ─── Divider ─── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-xs) 0;
}

/* ─── Success Overlay ─── */
.success-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
  gap: var(--space-lg);
}

.success-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.success-icon {
  width: 80px;
  height: 80px;
  background: var(--color-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: successPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.success-icon svg {
  width: 40px;
  height: 40px;
  color: white;
}

@keyframes successPop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.success-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.02em;
}

.success-sub {
  font-size: 1rem;
  color: rgba(255,255,255,0.6);
}

.success-actions {
  margin-top: var(--space-md);
  display: flex;
  gap: var(--space-md);
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(26,26,46,0.9);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-base);
  z-index: 2000;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
  .main { padding: var(--space-md); gap: var(--space-md); }
  .card-pad { padding: var(--space-md); }
  .hero-content { padding: var(--space-lg); }
  .hero-title { font-size: 1.5rem; }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
}

@media (min-width: 640px) {
  .canvas-wrapper { max-width: 400px; }
}

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page.active > * {
  animation: fadeIn 0.3s ease forwards;
}

.page.active > *:nth-child(2) { animation-delay: 0.05s; }
.page.active > *:nth-child(3) { animation-delay: 0.1s; }
.page.active > *:nth-child(4) { animation-delay: 0.15s; }
