/* ========================================
   textdiff - Text Comparison Tool
   ======================================== */

/* Web Fonts (Self-hosted) */
@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/textdiff/fonts/fraunces.woff2') format('woff2');
}

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/textdiff/fonts/dm-sans.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('/textdiff/fonts/jetbrains-mono.woff2') format('woff2');
}

/* CSS Variables */
:root {
  /* Colors - Light Mode */
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-surface-alt: #f5f3f0;
  --color-text: #1a1a1a;
  --color-text-muted: #666666;
  --color-border: #e5e2de;
  --color-accent: #3b82f6;
  --color-accent-hover: #2563eb;

  /* Diff Colors - Light Mode */
  --color-deleted-bg: #ffeef0;
  --color-deleted-char: #ffc9ce;
  --color-deleted-text: #9f1239;
  --color-added-bg: #e6ffec;
  --color-added-char: #abf2bc;
  --color-added-text: #166534;
  --color-unchanged-bg: transparent;

  /* Typography */
  --font-display: 'Fraunces', serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f0f0f;
    --color-surface: #1a1a1a;
    --color-surface-alt: #242424;
    --color-text: #f0f0f0;
    --color-text-muted: #a0a0a0;
    --color-border: #333333;
    --color-accent: #60a5fa;
    --color-accent-hover: #93c5fd;

    /* Diff Colors - Dark Mode */
    --color-deleted-bg: #3d1f24;
    --color-deleted-char: #6b2c36;
    --color-deleted-text: #fca5a5;
    --color-added-bg: #1a3d25;
    --color-added-char: #2d5a3d;
    --color-added-text: #86efac;
  }
}

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

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

body {
  font-family: var(--font-body);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Skip Link (Accessibility) */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-accent);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  text-decoration: none;
  z-index: 1000;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-md);
}

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
}

@media (min-width: 768px) {
  .container {
    padding: var(--space-xl) var(--space-lg);
  }
}

/* Header */
.header {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.header h1 {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.tagline {
  font-size: 1.1rem;
  color: var(--color-text-muted);
}

/* Privacy Banner */
.privacy-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-xl);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.privacy-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--color-accent);
}

/* Input Section */
.input-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

@media (min-width: 768px) {
  .input-section {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
  }
}

/* Input Panel */
.input-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}

.panel-header h2 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

/* File Upload Button */
.file-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast);
}

.file-upload-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-accent);
}

.file-upload-btn svg {
  width: 14px;
  height: 14px;
}

/* Textarea Wrapper */
.textarea-wrapper {
  position: relative;
}

.textarea-wrapper.drag-over::after {
  content: 'ファイルをドロップ';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.1);
  border: 2px dashed var(--color-accent);
  border-radius: 0;
  font-size: 1rem;
  color: var(--color-accent);
  pointer-events: none;
}

textarea {
  width: 100%;
  min-height: 250px;
  padding: var(--space-md);
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-text);
  resize: vertical;
}

textarea::placeholder {
  color: var(--color-text-muted);
  opacity: 0.6;
}

/* Action Section */
.action-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

/* Compare Button */
.compare-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.compare-btn:hover {
  background: var(--color-accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.compare-btn:active {
  transform: translateY(0);
}

.compare-btn svg {
  width: 20px;
  height: 20px;
}

/* Clear & Swap Buttons */
.clear-btn,
.swap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.875rem;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast);
}

.clear-btn:hover,
.swap-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.swap-btn {
  padding: var(--space-sm);
}

.swap-btn svg {
  width: 20px;
  height: 20px;
}

/* Result Section */
.result-section {
  margin-top: var(--space-xl);
}

.result-section[hidden] {
  display: none;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.result-header h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
}

.result-stats {
  display: flex;
  gap: var(--space-md);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.result-stats .stat-added {
  color: var(--color-added-text);
}

.result-stats .stat-deleted {
  color: var(--color-deleted-text);
}

/* Diff Container */
.diff-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

@media (min-width: 768px) {
  .diff-container {
    grid-template-columns: 1fr 1fr;
  }
}

.diff-panel {
  overflow: hidden;
}

@media (min-width: 768px) {
  .diff-panel.diff-left {
    border-right: 1px solid var(--color-border);
  }
}

@media (max-width: 767px) {
  .diff-panel.diff-left {
    border-bottom: 1px solid var(--color-border);
  }
}

.diff-panel-header {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.diff-content {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  overflow-x: auto;
}

/* Diff Lines */
.diff-line {
  display: flex;
  min-height: 1.6em;
  white-space: pre;
}

.diff-line-number {
  flex-shrink: 0;
  width: 3.5em;
  padding: 0 var(--space-sm);
  text-align: right;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  border-right: 1px solid var(--color-border);
  user-select: none;
}

.diff-line-content {
  flex: 1;
  padding: 0 var(--space-md);
  overflow-x: auto;
}

/* Diff Line Types */
.diff-line.deleted {
  background: var(--color-deleted-bg);
}

.diff-line.deleted .diff-line-number {
  background: var(--color-deleted-char);
  color: var(--color-deleted-text);
}

.diff-line.added {
  background: var(--color-added-bg);
}

.diff-line.added .diff-line-number {
  background: var(--color-added-char);
  color: var(--color-added-text);
}

.diff-line.empty {
  background: var(--color-surface-alt);
  opacity: 0.5;
}

.diff-line.empty .diff-line-content::after {
  content: ' ';
}

/* Character-level highlighting */
.diff-char-deleted {
  background: var(--color-deleted-char);
  border-radius: 2px;
}

.diff-char-added {
  background: var(--color-added-char);
  border-radius: 2px;
}

/* Footer */
.footer {
  text-align: center;
  padding: var(--space-xl) 0 var(--space-md);
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.footer a {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer a:hover {
  color: var(--color-accent);
}

/* Focus States (Accessibility) */
button:focus-visible,
textarea:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: more) {
  :root {
    --color-border: #000000;
    --color-text-muted: #333333;
  }
}

/* Print Styles */
@media print {
  .privacy-banner,
  .action-section,
  .file-upload-btn,
  .footer {
    display: none;
  }

  .container {
    max-width: none;
    padding: 0;
  }

  .diff-container {
    box-shadow: none;
    border: 1px solid #000;
  }
}
