:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --text: #1f2937;
  --text-muted: #5b6472;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;
  --code-bg: #f3f4f6;
  --radius: 10px;
  --max-width: 820px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover {
  opacity: 0.8;
}

/* Header & Footer */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
}

.site-header__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.site-title a {
  color: var(--text);
  text-decoration: none;
}

.site-tagline {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.site-footer {
  margin-top: 3rem;
  padding: 2rem 1.25rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.site-footer__nav {
  margin: 0 0 0.5rem;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.site-footer__nav a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer__nav a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Main container */
.site-main {
  max-width: var(--max-width);
  margin: 1.75rem auto 0;
  padding: 0 1rem;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

/* Article Header */
.article-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.article-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.category-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  padding: 0.15rem 0.65rem;
}

.article-title {
  margin: 0 0 0.75rem;
  font-size: 1.65rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Table of Contents */
.toc {
  margin: 1.5rem 0 2rem;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.toc summary {
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.toc-list {
  margin: 0.75rem 0 0;
  padding-left: 1.25rem;
}

.toc-list li {
  margin: 0.25rem 0;
}

.toc-list .toc-h3 {
  margin-left: 1rem;
  list-style-type: circle;
  font-size: 0.88rem;
}

.toc-list a {
  color: var(--text);
  text-decoration: none;
}

.toc-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Article Body Typography */
.article-body > :first-child {
  margin-top: 0;
}

.article-body h2 {
  margin: 2.4rem 0 1rem;
  padding: 0.45rem 0 0.45rem 0.85rem;
  font-size: 1.32rem;
  line-height: 1.45;
  border-left: 4px solid var(--accent);
  border-bottom: 1px solid var(--border);
}

.article-body h3 {
  margin: 1.85rem 0 0.75rem;
  padding-bottom: 0.25rem;
  font-size: 1.1rem;
  line-height: 1.5;
  border-bottom: 1px dashed var(--border);
}

.article-body h4 {
  margin: 1.4rem 0 0.5rem;
  font-size: 1rem;
}

.article-body p {
  margin: 0 0 1.25rem;
  overflow-wrap: anywhere;
}

.article-body ul,
.article-body ol {
  margin: 0 0 1.25rem;
  padding-left: 1.5rem;
}

.article-body li {
  margin-bottom: 0.35rem;
}

.article-body pre {
  margin: 1.25rem 0;
  padding: 1rem 1.15rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.6;
}

.article-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.article-body p code,
.article-body li code {
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* Info Box (migrated from Cocoon info-box) */
.info-box {
  margin: 1.25rem 0 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  font-size: 0.95rem;
}

.info-box p:last-child {
  margin-bottom: 0;
}

/* Toggle Box (migrated from Cocoon toggle-box) */
.toggle-box {
  margin: 1.25rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.toggle-box summary {
  padding: 0.75rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle-box__content {
  padding: 0 1rem 1rem;
}

/* Embed Cards (internal links, external links) */
.embed-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 1.25rem 0;
  padding: 0.95rem 1.15rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.embed-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  opacity: 1;
}

.embed-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

.embed-card__title {
  font-weight: 700;
  line-height: 1.45;
}

.embed-card__url {
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
}

/* YouTube Responsive Embed */
.video-embed {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 1.5rem 0;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Interactive JS Tool Block Styling */
.tool-block {
  margin: 1.5rem 0;
  padding: 1.25rem 1.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tool-block label:has(> select, > input[type="number"], > input[type="text"]) {
  display: block;
  margin-bottom: 0.85rem;
  font-weight: 500;
}

.tool-block input[type="number"],
.tool-block input[type="text"],
.tool-block select {
  padding: 0.4rem 0.6rem;
  margin: 0.2rem 0.25rem 0.4rem 0.35rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.tool-block fieldset {
  margin: 0.75rem 0 0.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: var(--surface);
}

.tool-block legend {
  padding: 0 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.tool-block fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-right: 1rem;
  cursor: pointer;
}

.tool-block button {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.6rem 1.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.tool-block button:hover:not(:disabled) {
  opacity: 0.9;
}

.tool-block button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.tool-block .result,
.tool-block #result,
.tool-block #output {
  margin-top: 1.25rem;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tool-block .result:empty,
.tool-block #output:empty {
  display: none;
}

/* Article Footer Navigation */
.article-footer {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.back-link {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
}

.back-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
}

/* Index Page Article List */
.article-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.article-list__item a {
  display: block;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease;
}

.article-list__item a:hover {
  border-color: var(--accent);
  opacity: 1;
}

.article-list__title {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.article-list__meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 640px) {
  .article-card {
    padding: 1.35rem 1.1rem;
  }

  .article-title {
    font-size: 1.35rem;
  }

  .article-body h2 {
    font-size: 1.18rem;
  }

  .tool-block {
    padding: 1rem;
  }
}
