@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&family=Fira+Code:wght@400;700&display=swap");

:root {
  --bg: #003333;
  --text: #ffffff;
  --text-muted: #aaccbb;
  --accent: #eeffee;
  --accent-visited: #dddddd;
  --card-bg: #004040;
  --card-border: #006060;
  --code-bg: #005050;
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #002828;
  --text: #ffffff;
  --text-muted: #99bbaa;
  --accent: #eeffee;
  --accent-visited: #dddddd;
  --card-bg: #003838;
  --card-border: #005555;
  --code-bg: #004545;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  transition: background 0.3s, color 0.3s;
}

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

a:visited {
  color: var(--accent-visited);
}

a:hover {
  text-decoration: none;
  background: var(--code-bg);
}

a:active {
  color: #ff0000;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 3rem;
}

.site-logo {
  max-width: 100%;
  height: auto;
  margin: 0 auto 1rem;
  display: block;
}

.header h1 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

.header p {
  color: var(--text-muted);
}

.social-icons {
  display: flex;
  gap: 2rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.social-icons a {
  color: var(--text-muted);
  transition: color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  text-decoration: none;
}

.social-icons a:hover {
  color: var(--accent);
  background: var(--code-bg);
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}

/* Back to top link */
.back-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
  color: var(--text-muted);
  text-decoration: none;
  font-family: 'Fira Code', monospace;
  z-index: 100;
}
.back-link:hover {
  color: var(--accent);
  background: var(--code-bg);
}
.back-link:visited {
  color: var(--text-muted);
}

/* Section */
section {
  margin-bottom: 3rem;
}

section h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--card-border);
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
  margin-bottom: 1rem;
  transition: background 0.3s;
}

.card h3 {
  font-size: 1.1rem;
  margin-bottom: 0.3rem;
}

.card .date {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.card .description {
  margin-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Post content */
.post-content {
  line-height: 1.9;
  font-size: 1rem;
}

.post-content h1 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  border-bottom: none;
}

.post-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.post-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reading-time {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.copy-page-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  transition: color 0.2s;
  vertical-align: middle;
}
.copy-page-btn:hover {
  color: var(--text);
}
.copy-page-btn.copied {
  color: var(--accent, #4ecdc4);
}

.tag {
  background: var(--code-bg);
  color: var(--text-muted);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

/* Article Layout */
body:has(.article-layout) {
  max-width: 1160px;
}

.article-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 2rem;
}

.article-layout main {
  min-width: 0;
}

.toc-sidebar {
  position: relative;
}

.toc-sidebar .toc {
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
}

@media (max-width: 860px) {
  .article-layout {
    grid-template-columns: 1fr;
  }
  .toc-sidebar {
    display: none;
  }
}

/* Table of Contents */
.toc {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
}

.toc strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.toc ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
  border-left: 2px solid var(--card-border);
}

.toc li {
  margin: 0;
  font-size: 0.9rem;
  padding: 0.25rem 0 0.25rem 0.8rem;
  margin-left: -2px;
  border-left: 2px solid transparent;
}

.toc li:has(.active) {
  border-left-color: var(--accent);
}

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

.toc a:hover {
  background: var(--code-bg);
}

.toc a.active {
  color: var(--accent);
}

/* Footnotes */
.footnotes {
  margin-top: 2rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.footnotes p {
  margin: 0.5rem 0;
}

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

.post-content p {
  margin: 1rem 0;
}

.post-content h2 {
  font-size: 1.4rem;
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--card-border);
}

.post-content h3 {
  font-size: 1.15rem;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
}

.post-content h4 {
  font-size: 1.05rem;
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
}

.post-content blockquote {
  background: var(--code-bg);
  border-left: 4px solid var(--accent);
  margin: 1rem 0;
  padding: 0.8rem 1.2rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
}

.post-content blockquote p {
  margin: 0.3rem 0;
}

.post-content ul,
.post-content ol {
  margin: 1rem 0;
  padding-left: 1.8rem;
}

.post-content li {
  margin: 0.3rem 0;
}

.post-content hr {
  border: none;
  border-top: 1px solid var(--card-border);
  margin: 2.5rem 0;
}

.post-content strong {
  font-weight: 700;
}

.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto 0.3rem;
  border-radius: var(--radius);
}

.post-content p > img + em,
.post-content img + em {
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: normal;
  margin-bottom: 1.5rem;
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

.post-content thead th {
  background: var(--code-bg);
  font-weight: 700;
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 2px solid var(--card-border);
}

.post-content td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--card-border);
}

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

.post-content tbody tr:hover {
  background: var(--code-bg);
}

.post-content h2 {
  margin-top: 2rem;
}

.post-content code {
  font-family: 'Fira Code', monospace;
  background: var(--code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.post-content pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1rem 0;
}

.post-content pre code {
  background: none;
  padding: 0;
}

/* Alerts / Callouts */
.alert {
  border-left: 4px solid var(--accent);
  background: var(--code-bg);
  padding: 1rem 1.2rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  line-height: 1.7;
}

.alert strong:first-child {
  display: block;
  margin-bottom: 0.3rem;
}

.alert-warning {
  border-left-color: #e6a700;
}

[data-theme="dark"] .alert-warning {
  border-left-color: #ffc107;
}

/* Action Sidebar (JS-injected, fixed position) */
.action-sidebar {
  position: fixed;
  top: 50%;
  left: max(1rem, calc((100vw - 1160px) / 2 - 70px));
  transform: translateY(-50%);
  z-index: 10;
}

.action-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 44px;
  height: 44px;
  border: 1px solid var(--card-border);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
  text-decoration: none;
  font-size: 0;
}

.action-btn:hover {
  color: var(--accent);
  background: var(--code-bg);
  border-color: var(--accent);
}

.action-btn:visited {
  color: var(--text-muted);
}

.action-btn:visited:hover {
  color: var(--accent);
}

.x-btn {
  opacity: 1;
}

.action-count {
  font-size: 0.7rem;
  line-height: 1;
  margin-top: 2px;
  color: var(--text-muted);
}

.like-btn {
  height: auto;
  padding: 8px 0 4px;
  border-radius: 22px;
}

/* Drop cap */
.drop-cap::first-letter {
  float: left;
  font-size: 3em;
  line-height: 0.8;
  padding-right: 0.08em;
  margin-top: 0.05em;
  font-weight: 700;
  color: var(--accent, var(--text));
}

/* Language switch */
.lang-switch a,
.lang-switch .hex-toggle,
.lang-switch .bin-toggle,
.lang-switch .dump-toggle {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
  border: 1px solid var(--card-border);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  font-family: 'Fira Code', monospace;
  vertical-align: middle;
}
.lang-switch a:hover,
.lang-switch .hex-toggle:hover,
.lang-switch .bin-toggle:hover,
.lang-switch .dump-toggle:hover {
  color: var(--text);
}
.lang-switch .hex-toggle.active,
.lang-switch .bin-toggle.active,
.lang-switch .dump-toggle.active {
  background: var(--code-bg);
  color: var(--accent);
  border-color: var(--accent);
}

/* Dump overlay */
.dump-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  color: #00ff00;
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  padding: 1.5rem;
  overflow-y: auto;
  z-index: 9999;
  white-space: pre;
}

/* Footer */
footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--card-border);
}
