:root {
  --bg: #ffffff;
  --surface: #f3f5f8;
  --text: #1b2330;
  --muted: #5a6577;
  --border: #d5dae3;
  --accent: #1f5fd1;
  --accent-text: #ffffff;
  --working: #b45309;
  --done: #15803d;
  --gutter: 16px;
  --radius: 8px;
  --touch: 44px;
  --max: 960px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --surface: #1b212b;
    --text: #e8ecf3;
    --muted: #a4aebf;
    --border: #2f3846;
    --accent: #7aa7ff;
    --accent-text: #0b1220;
    --working: #f5b45a;
    --done: #5fd08a;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

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

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-text);
  padding: 8px 12px;
  z-index: 10;
}
.skip-link:focus { left: 0; }

button, select, input[type="range"] { font: inherit; }

button {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
button[aria-pressed="true"], button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px var(--gutter);
  padding: 8px var(--gutter);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; min-height: var(--touch); font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); margin-right: auto; }
.menu { display: none; width: 100%; flex-direction: column; gap: 4px; }
.menu.open { display: flex; }
.menu a {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.menu a[aria-current="page"] { background: var(--surface); font-weight: 600; }
.language-switcher { display: flex; gap: 4px; }

.main { max-width: var(--max); margin: 0 auto; padding: var(--gutter); }
.main:focus { outline: none; }
.main h1 { font-size: 1.6rem; line-height: 1.25; }
.main pre { overflow-x: auto; background: var(--surface); padding: 12px; border-radius: var(--radius); }
.main code { background: var(--surface); padding: 1px 4px; border-radius: 4px; }
.main pre code { padding: 0; background: none; }

.site-footer {
  max-width: var(--max);
  margin: 24px auto 0;
  padding: var(--gutter);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}
.site-footer a { color: var(--muted); }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; margin: 8px 0; }

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--muted);
}

/* Replay player */
.replay { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--gutter); margin: 0 0 24px; }
.replay h2 { margin: 0 0 4px; font-size: 1.25rem; }
.replay .recorded { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }
.replay-error { border-color: var(--working); }

.graph { display: flex; flex-direction: column; gap: 20px; margin: 12px 0; }
.node {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.node + .node::before {
  content: "↓";
  position: absolute;
  left: 50%;
  top: -22px;
  transform: translateX(-50%);
  color: var(--muted);
}
.node-name { font-weight: 600; text-transform: capitalize; }
.node-status { font-size: 0.85rem; color: var(--muted); }
.node[data-status="working"] { border-color: var(--working); }
.node[data-status="working"] .node-status { color: var(--working); font-weight: 600; }
.node[data-status="done"] { border-color: var(--done); }
.node[data-status="done"] .node-status { color: var(--done); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.speed { display: flex; flex-wrap: wrap; gap: 4px; }
@media (min-width: 720px) { .speed { margin-left: auto; } }
.replay input[type="range"] { width: 100%; height: var(--touch); }
.replay .status { margin: 4px 0; font-size: 0.9rem; color: var(--muted); }
.replay .explanation:not(:empty) { margin: 8px 0; padding: 8px 12px; border-left: 4px solid var(--accent); background: var(--surface); }

.replay-columns { display: grid; gap: 12px; margin-top: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.timeline button { width: 100%; text-align: left; margin-bottom: 4px; }
.timeline button[aria-current="step"] { border-color: var(--accent); font-weight: 600; }
.message-panel h3 { margin: 0 0 8px; font-size: 1rem; }
.message { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 300px; overflow-y: auto; }
.message-panel .close { display: none; }

@media (max-width: 719px) {
  .message-panel { display: none; }
  .message-panel.open {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 60vh;
    overflow-y: auto;
    padding: var(--gutter);
    background: var(--bg);
    border-top: 2px solid var(--accent);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
    z-index: 5;
  }
  .message-panel.open .close { display: inline-block; }
}

@media (min-width: 720px) {
  .graph { flex-direction: row; align-items: stretch; gap: 28px; }
  .node { flex: 1; flex-direction: column; justify-content: center; text-align: center; }
  .node + .node::before { content: "→"; left: -22px; top: 50%; transform: translateY(-50%); }
  .replay-columns { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 720px) {
  .menu-toggle { display: none; }
  .menu { display: flex; flex-direction: row; width: auto; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
