/* Reset and base styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  font-family: "Noto Sans JP", "Sawarabi Gothic", system-ui, sans-serif;
  scroll-behavior: smooth;
  scrollbar-gutter: stable both-edges;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s ease, color 0.3s ease;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* View Transitions — 円形リビール（テーマ切替） */
@supports (view-transition-name: root) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
  }
  ::view-transition-old(root) { z-index: 1; }
  ::view-transition-new(root) { z-index: 2; }
}

/* CSS Variables - Light theme defaults */
:root {
  --bg-primary:   #efe9dc;
  --bg-secondary: #f7f1e4;
  --text-primary:   #231d15;
  --text-secondary: #8a7c66;
  --border-color: #c8bca4;
  --accent-color: #a83818;
  --card-bg:    #f7f1e4;
  --header-bg:  rgba(239, 233, 220, 0.95);
  --shadow:     0 2px 4px rgba(35, 29, 21, 0.08);

  color-scheme: light;

  --color-primary-500:   #a83818;
  --color-secondary-500: #8a7c66;

  --shadow-sm: 0 1px 3px rgba(35, 29, 21, 0.08), 0 1px 2px rgba(35, 29, 21, 0.05);
  --shadow-md: 0 4px 6px rgba(35, 29, 21, 0.08), 0 2px 4px rgba(35, 29, 21, 0.05);
  --shadow-lg: 0 10px 15px rgba(35, 29, 21, 0.08), 0 4px 6px rgba(35, 29, 21, 0.04);

  --glass-bg:              rgba(239, 233, 220, 0.12);
  --glass-bg-strong:       rgba(239, 233, 220, 0.22);
  --glass-backdrop:        blur(10px);
  --glass-backdrop-subtle: blur(5px);

  --font-family: "Noto Sans JP", "Sawarabi Gothic", system-ui, sans-serif;
  --font-serif:  "Noto Serif JP", "EB Garamond", serif;
  --font-mono:   "JetBrains Mono", ui-monospace, monospace;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;

  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;

  --code-bg: #f8f9fa;
  --code-text: #212529;
  --code-border: #dee2e6;
}

/* Dark theme colors */
.dark {
  --bg-primary:   #14110c;
  --bg-secondary: #1c1812;
  --text-primary:   #ebe3d0;
  --text-secondary: #8f8370;
  --border-color: #2e2920;
  --accent-color: #eb6b42;
  --card-bg:    #1c1812;
  --header-bg:  rgba(20, 17, 12, 0.95);
  --shadow:     0 2px 4px rgba(0, 0, 0, 0.4);

  color-scheme: dark;

  --color-primary-500:   #eb6b42;
  --color-secondary-500: #8f8370;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5), 0 4px 6px rgba(0, 0, 0, 0.4);

  --glass-bg:              rgba(20, 17, 12, 0.15);
  --glass-bg-strong:       rgba(20, 17, 12, 0.25);
  --glass-backdrop:        blur(10px);
  --glass-backdrop-subtle: blur(5px);

  --code-bg: #1c1812;
  --code-text: #ebe3d0;
  --code-border: #2e2920;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: 0.5em;
  color: var(--text-primary);
  transition: color 0.3s ease;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }
h5 { font-size: 0.9375rem; }
h6 { font-size: 0.875rem; }

p {
  margin-bottom: var(--space-md);
  color: var(--text-primary);
  line-height: 1.6;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.3s ease;
}

a:hover,
a:focus {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

a:focus,
a:focus-visible {
  outline: none;
}

/* Lists */
ul,
ol {
  margin-bottom: var(--space-md);
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.25rem;
  line-height: 1.6;
}

/* Code */
code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background-color: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-sm);
}

code {
  padding: 0.125rem 0.25rem;
  font-size: 0.875em;
}

pre {
  padding: var(--space-md);
  overflow-x: auto;
  margin-bottom: var(--space-md);
  border: 1px solid var(--code-border);
}

pre code {
  background: none;
  padding: 0;
}

/* Standalone code blocks use the legacy dark surface. */
pre:not(.article-content pre) {
  background-color: #1c1812 !important;
  color: #ebe3d0;
  border-color: #2e2920 !important;
}

/* Buttons */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--card-bg);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

button:hover,
.btn:hover,
button:focus,
.btn:focus {
  background-color: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  text-decoration: none;
  transform: translateY(-1px);
}

button:disabled,
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

[role="button"] {
  cursor: pointer;
}

/* Forms */
label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--card-bg);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: var(--shadow-sm), 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input[required],
textarea[required],
select[required] {
  border-left: 3px solid var(--accent-color);
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

th {
  background-color: var(--bg-secondary);
  font-weight: 600;
}

/* Layout utilities */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* Responsive utilities */
@media (max-width: 768px) {
  body { font-size: 16px; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.0625rem; }

  .container {
    padding: 0 var(--space-md);
    width: 100%;
    box-sizing: border-box;
  }
}

/* Focus styles for accessibility */
*:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

button:focus,
.btn:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--accent-color) !important;
  outline-offset: 2px !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --text-primary: #000000;
    --text-secondary: #333333;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --border-color: #333333;
    --accent-color: #0066cc;
  }

  .dark {
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --bg-primary: #000000;
    --bg-secondary: #222222;
    --border-color: #cccccc;
    --accent-color: #4d9fff;
  }

  button, .btn, input, textarea, select {
    border-width: 2px;
  }

  a {
    text-decoration: underline;
  }
}

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

  button:hover,
  .btn:hover,
  a:hover {
    transform: none !important;
  }
}
