@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700;800&family=Geist+Mono:wght@400;500;600;700;800&display=swap");

:root {
  color-scheme: light;
  --paper: #f7f8f5;
  --white: #ffffff;
  --ink: #172033;
  --muted: #788398;
  --line: #dfe4e8;
  --line-strong: #b9c2cc;
  --red: #e9564a;
  --blue: #2879d8;
  --violet: #8b5fc4;
  --green: #55a36c;
  --header-bg: rgba(247, 248, 245, 0.88);
  --header-border: rgba(201, 208, 215, 0.82);
  --button-bg: rgba(255, 255, 255, 0.75);
  --surface: rgba(255, 255, 255, 0.95);
  --surface-solid: #ffffff;
  --surface-subtle: #eef1f3;
  --surface-hover: #e9eceb;
  --text-secondary: #687386;
  --text-tertiary: #5e6879;
  --success-line: #bdd5c4;
  --success-text: #39794b;
  --success-bg: #edf7f0;
  --page-grid: rgba(218, 224, 228, 0.36);
  --shadow: rgba(38, 51, 70, 0.11);
  --progress-track: rgba(23, 32, 51, 0.06);
  --canvas-grid: #dde2e5;
  --canvas-grid-soft: #e5e8ea;
  --canvas-edge: #c8d0d6;
  --canvas-edge-soft: #d8dde1;
  --canvas-axis: #667286;
  --canvas-axis-label: #4b586e;
  --canvas-origin: #8993a3;
  --canvas-tick: #7f8999;
  --canvas-point-ring: #ffffff;
  --canvas-label-bg: rgba(255, 255, 255, 0.95);
  --canvas-label-border: #d5dade;
  --canvas-label-text: #344056;
  --canvas-output: #172033;
  --smooth: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0d1118;
  --white: #151c26;
  --ink: #f1f5f9;
  --muted: #98a4b7;
  --line: #273141;
  --line-strong: #445066;
  --red: #ff7166;
  --blue: #5aa2f2;
  --violet: #b18ae6;
  --green: #77c68f;
  --header-bg: rgba(13, 17, 24, 0.9);
  --header-border: rgba(68, 80, 102, 0.72);
  --button-bg: rgba(30, 39, 52, 0.82);
  --surface: rgba(21, 28, 38, 0.96);
  --surface-solid: #151c26;
  --surface-subtle: #202a38;
  --surface-hover: #202a38;
  --text-secondary: #a5b0c1;
  --text-tertiary: #aeb8c7;
  --success-line: #3c6749;
  --success-text: #92d4a5;
  --success-bg: #17271d;
  --page-grid: rgba(72, 84, 103, 0.25);
  --shadow: rgba(0, 0, 0, 0.3);
  --progress-track: rgba(241, 245, 249, 0.09);
  --canvas-grid: #283342;
  --canvas-grid-soft: #222c39;
  --canvas-edge: #46546a;
  --canvas-edge-soft: #354154;
  --canvas-axis: #8e9bb0;
  --canvas-axis-label: #bec8d7;
  --canvas-origin: #8997aa;
  --canvas-tick: #9aa7ba;
  --canvas-point-ring: #151c26;
  --canvas-label-bg: rgba(21, 28, 38, 0.96);
  --canvas-label-border: #48556a;
  --canvas-label-text: #e2e8f0;
  --canvas-output: #f1f5f9;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  color: var(--ink);
  background: var(--paper);
  font-family: "Geist", Inter, "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
}

a { color: inherit; }
button { font: inherit; }

.graph-page {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.graph-experience {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 600px;
  overflow: hidden;
  background:
    radial-gradient(circle at 24% 53%, color-mix(in srgb, var(--blue) 4%, transparent), transparent 24%),
    radial-gradient(circle at 75% 53%, color-mix(in srgb, var(--green) 4%, transparent), transparent 24%),
    var(--paper);
}

#graph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.graph-header {
  position: absolute;
  z-index: 10;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 76px;
  padding: 0 32px;
  border-bottom: 2px solid var(--header-border);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.wordmark {
  display: flex;
  min-width: 0;
  align-items: center;
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.035em;
  line-height: 1.15;
  text-decoration: none;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.graph-header .wordmark,
.explain-header .wordmark {
  flex: 1;
  margin-right: 12px;
}

.explain-link,
.fullscreen-toggle,
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px 9px 15px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink);
  background: var(--button-bg);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  transition: color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.fullscreen-toggle {
  cursor: pointer;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.explain-link:hover,
.fullscreen-toggle:hover,
.theme-toggle:hover {
  color: var(--paper);
  background: var(--ink);
  transform: translateY(-1px);
}

.explain-link:focus-visible,
.fullscreen-toggle:focus-visible,
.theme-toggle:focus-visible,
#replay:focus-visible,
.back-link:focus-visible {
  outline: 3px solid rgba(40,121,216,.23);
  outline-offset: 3px;
}

.explain-link svg,
.fullscreen-toggle svg,
.theme-toggle svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.fullscreen-toggle .exit-fullscreen-icon,
.fullscreen-toggle.is-fullscreen .enter-fullscreen-icon { display: none; }
.fullscreen-toggle.is-fullscreen .exit-fullscreen-icon { display: block; }

.theme-toggle .sun-icon,
:root[data-theme="dark"] .theme-toggle .moon-icon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun-icon { display: block; }

.graph-title {
  position: absolute;
  z-index: 5;
  top: 105px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 240px;
  opacity: 0;
  transform: translateY(10px);
}

.input-title { left: calc(25% - 120px); }
.output-title { left: calc(75% - 120px); }

.graph-title > span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  font-weight: 750;
}

.graph-title div {
  display: flex;
  flex-direction: column;
}

.graph-title strong {
  font-size: 13px;
  letter-spacing: 0.12em;
}

.graph-title small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.map-badge {
  position: absolute;
  z-index: 7;
  top: 49%;
  left: 50%;
  display: flex;
  width: 104px;
  height: 104px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 12px 35px var(--shadow);
  transform: translate(-50%, -50%) scale(.72);
  opacity: 0;
}

.map-badge::before,
.map-badge::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 42px;
  height: 2px;
  background: var(--line-strong);
}

.map-badge::before { right: 100%; }
.map-badge::after { left: 100%; }

.map-badge small {
  color: var(--muted);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: .1em;
}

.map-badge > strong {
  margin: 2px 0 0;
  font-family: "Geist", Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 38px;
  font-style: italic;
  font-weight: 400;
  line-height: 1;
}

.map-badge span {
  position: absolute;
  top: calc(100% + 10px);
  padding: 5px 8px;
  border: 1.5px solid var(--success-line);
  border-radius: 5px;
  color: var(--success-text);
  background: var(--success-bg);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  font-weight: 750;
  white-space: nowrap;
}

.map-badge sub { font-size: 6px; }

.result-card {
  position: absolute;
  z-index: 12;
  bottom: 73px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 430px;
  padding: 11px 13px;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 16px 38px var(--shadow);
  transform: translate(-50%, 18px) scale(.97);
  opacity: 0;
}

.result-icons {
  position: relative;
  width: 72px;
  height: 28px;
}

.result-icons i,
.result-icons b {
  position: absolute;
  top: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.result-icons i:nth-child(1) { left: 0; background: var(--red); }
.result-icons i:nth-child(2) { left: 15px; background: var(--blue); }
.result-icons i:nth-child(3) { left: 30px; background: var(--violet); }
.result-icons b { right: 0; background: var(--ink); }
.result-icons::after {
  content: "→";
  position: absolute;
  top: 5px;
  left: 44px;
  color: var(--muted);
  font-size: 15px;
}

.result-card p {
  margin: 0;
  color: var(--text-tertiary);
  font-size: 13px;
}

.result-card p strong { color: var(--ink); }

.result-card code {
  margin-left: auto;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-subtle);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.graph-footer {
  position: absolute;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 54px;
  padding: 0 32px;
  border-top: 2px solid var(--header-border);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.legend {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 650;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.red { background: var(--red); }
.blue { background: var(--blue); }
.violet { background: var(--violet); }
.black { background: var(--ink); }

#replay {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}

#replay:hover { background: var(--surface-hover); }

#replay svg {
  width: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.progress {
  position: absolute;
  z-index: 15;
  right: 0;
  bottom: 52px;
  left: 0;
  height: 3px;
  background: var(--progress-track);
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ink);
}

.is-running .graph-title { animation: rise-in 500ms var(--smooth) forwards; }
.is-running .output-title { animation-delay: 200ms; }
.is-running .map-badge { animation: badge-in 550ms var(--smooth) 1.5s forwards; }
.is-running .result-card { animation: result-in 500ms var(--smooth) 5.5s forwards; }
.is-running #progress-fill { animation: progress 8s linear forwards; }

@keyframes rise-in { to { opacity: 1; transform: translateY(0); } }
@keyframes badge-in { to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes result-in { to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
@keyframes progress { to { width: 100%; } }

/* Explanation route */
.explain-page {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(var(--page-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--page-grid) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

.explain-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 76px;
  padding: 0 max(24px, calc((100vw - 980px) / 2));
  border-bottom: 2px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.back-link {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
}

.back-link svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.explain-shell {
  display: grid;
  width: min(1180px, calc(100% - 40px));
  height: calc(100vh - 76px);
  margin: 0 auto;
  padding: 30px 0 28px;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 20px;
}

.simple-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  height: min(56vh, 480px);
  margin: auto 0;
}

.simple-step {
  display: flex;
  min-width: 0;
  min-height: 0;
  padding: clamp(20px, 2.2vw, 30px);
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  flex-direction: column;
  background: var(--surface);
  box-shadow: 0 16px 36px var(--shadow);
}

.simple-step > span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 750;
}

.simple-step h2 {
  margin: auto 0 12px;
  font-family: "Geist", Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(21px, 2.15vw, 29px);
  font-weight: 650;
  letter-spacing: -.025em;
}

.simple-step p {
  margin: 0;
  color: var(--text-secondary);
  font-size: clamp(12px, 1.05vw, 14px);
  line-height: 1.55;
}

.simple-step code {
  display: inline-block;
  margin-top: 17px;
  padding: 7px 9px;
  border-radius: 5px;
  color: var(--success-text);
  background: var(--success-bg);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 750;
}

.bottom-line {
  margin: 0;
  padding: 14px 0 14px 20px;
  border-left: 3px solid var(--red);
  color: var(--ink);
  font-family: "Geist", Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(22px, 2.7vw, 38px);
  font-weight: 600;
  line-height: 1.2;
}

@media (max-width: 760px) {
  .graph-experience { min-height: 680px; }
  .graph-header { height: 66px; padding: 0 18px; }
  .wordmark {
    font-size: 12px;
    letter-spacing: .035em;
    line-height: 1.15;
  }
  .explain-link span, .fullscreen-toggle span { display: none; }
  .explain-link, .fullscreen-toggle { width: 38px; height: 38px; justify-content: center; padding: 0; }
  .graph-title { top: 82px; }
  .input-title { left: 18px; width: 230px; }
  .output-title { top: 53%; left: 18px; }
  .map-badge { top: 50%; left: auto; right: 18px; width: 76px; height: 76px; transform: translateY(-50%) scale(.72); }
  .map-badge::before, .map-badge::after { display: none; }
  .map-badge > strong { font-size: 29px; }
  .map-badge small { font-size: 5px; }
  .is-running .map-badge { animation-name: badge-in-mobile; }
  .result-card { bottom: 72px; min-width: 0; width: calc(100% - 28px); gap: 10px; }
  .result-icons { display: none; }
  .result-card p { font-size: 11px; }
  .graph-footer { height: 54px; padding: 0 18px; }
  .legend span { display: none; }
  .legend span:last-child { display: flex; }
  .progress { bottom: 52px; }
  .explain-header { height: 66px; padding: 0 18px; }
  .explain-shell {
    width: calc(100% - 24px);
    height: calc(100vh - 66px);
    padding: 12px 0;
    gap: 10px;
  }
  .simple-steps {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 8px;
    height: 100%;
  }
  .simple-step {
    display: grid;
    padding: 12px;
    grid-template-columns: 34px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 10px;
  }
  .simple-step > span {
    width: 28px;
    height: 28px;
    grid-row: 1 / 3;
  }
  .simple-step h2 {
    margin: 0 0 4px;
    font-size: clamp(14px, 4.2vw, 18px);
  }
  .simple-step p {
    font-size: clamp(10px, 2.9vw, 12px);
    line-height: 1.35;
  }
  .simple-step code {
    margin-top: 6px;
    padding: 4px 6px;
    grid-column: 2;
    font-size: 10px;
  }
  .bottom-line {
    padding: 8px 0 8px 12px;
    font-size: clamp(16px, 4.8vw, 23px);
  }
}

@keyframes badge-in-mobile {
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}

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