:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #242424;
  --muted: #6b6860;
  --line: #e2dfd6;
  --blue: #185fa5;
  --blue-soft: #e6f1fb;
  --coral: #d85a30;
  --coral-soft: #fdf1ec;
  --green: #0f6e56;
  --green-soft: #eaf6f0;
  --red: #a32d2d;
  --red-soft: #fdecec;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  line-height: 1.55;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-soft);
}
.brand .tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.toplinks { display: flex; gap: 14px; font-size: 12.5px; }
.toplinks a { text-decoration: none; }
.toplinks a:hover { text-decoration: underline; }

main { max-width: 1180px; margin: 18px auto 40px; padding: 0 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.editor { padding: 14px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 14px; }
@media (max-width: 820px) {
  .editor-grid { grid-template-columns: 1fr; }
}

.label {
  display: block;
  font-size: 11px;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

textarea#code {
  width: 100%;
  height: 178px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfaf6;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 4;
}

textarea#code:focus,
input#call:focus,
input#prediction-value:focus,
input#example-link:focus,
.growth-form input:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }

.run-col { display: flex; flex-direction: column; gap: 10px; }
.run-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.run-actions .primary { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

input#call,
input#prediction-value,
input#example-link,
.growth-form input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--text);
  background: #fff;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 9px;
  padding: 7px 11px;
  transition: background .12s ease, border-color .12s ease;
}
button:hover { background: #f4f2ec; }
button:disabled { opacity: .45; cursor: default; }
button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 600;
  padding: 9px 12px;
}
button.primary:hover { background: #14508c; }

.prediction-dialog {
  width: min(430px, calc(100vw - 32px));
  color: var(--text);
  padding: 20px;
}
.prediction-dialog::backdrop { background: rgb(36 36 36 / .45); }
.prediction-dialog[open] + #results { visibility: hidden; }
.prediction-dialog code { overflow-wrap: anywhere; }
.prediction-dialog input { margin-top: 4px; width: 100%; }
.prediction-result { margin-bottom: 12px; padding: 14px 18px; scroll-margin-top: 70px; }
.prediction-result:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.prediction-dialog h2, .prediction-result h2 { font-size: 17px; margin: 0 0 6px; }
.prediction-dialog p, .prediction-result p { margin: 6px 0 12px; }
.prediction-result p:last-child { margin-bottom: 0; }

.status { font-size: 12px; color: var(--muted); min-height: 18px; }
.status.error { color: var(--red); }

.hint { font-size: 11px; color: var(--muted); min-height: 14px; }

select#example {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12.5px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
select#example:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
#example-note:empty { display: none; }
.example-share .run-actions { align-items: center; }
#example-link { width: 100%; margin-top: 6px; }

.metrics { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.metric {
  flex: 1 1 120px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
}
.metric .k { font-size: 10.5px; color: var(--muted); }
.metric .v { font-size: 19px; font-weight: 600; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 10px; }
.tabs button { font-size: 12.5px; color: var(--muted); }
.tabs button.active {
  color: var(--text);
  border-color: #cfccc3;
  background: #fff;
  font-weight: 600;
}

.panel { margin-top: 4px; }

.growth-card { padding: 16px; }
.growth-header { display: flex; align-items: center; justify-content: space-between; gap: 8px 18px; flex-wrap: wrap; }
.growth-header h2 { font-size: 18px; margin: 0; }
.growth-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) repeat(3, 76px) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}
.growth-form input { width: 100%; min-width: 0; }
@media (max-width: 760px) {
  .growth-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .growth-form .field:first-child, #growth-run { grid-column: 1 / -1; }
}
.growth-summary { font-size: 13px; color: var(--text); margin: 8px 0 12px; }
.growth-fit { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }
.growth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 6px;
}
.growth-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); }
.growth-legend span { display: inline-flex; align-items: center; gap: 7px; }
.growth-legend span::before { content: ""; width: 22px; border-top: 3px solid var(--coral); }
.growth-legend .growth-cached::before { border-top: 3px dashed var(--blue); }
#growth-chart {
  display: block;
  width: 100%;
  height: clamp(230px, 36vw, 330px);
  background: #fbfaf6;
  border: 1px solid #efede5;
  border-radius: 10px;
}
.growth-details { margin: 12px 0 0; font-size: 13px; }
.growth-details summary { color: var(--blue); cursor: pointer; }
.growth-table { border-collapse: collapse; width: 100%; margin-top: 6px; font-variant-numeric: tabular-nums; }
.growth-table th, .growth-table td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.growth-table th:first-child { text-align: left; }
.growth-table thead th { font-size: 12px; color: var(--muted); }
.growth-table tbody th { font-weight: normal; }

.player { display: flex; flex-direction: column; gap: 12px; }
.player-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.player-bar button { min-width: 38px; padding: 5px 8px; }
#play { min-width: 62px; }
input#slider { flex: 1 1 220px; accent-color: var(--coral); }
.stepinfo { font-size: 12px; color: var(--muted); min-width: 180px; }

.player-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
@media (max-width: 900px) { .player-grid { grid-template-columns: 1fr; } }

.inner { padding: 12px; }

.stepcode {
  margin: 0;
  background: #fbfaf6;
  border: 1px solid #efede5;
  border-radius: 10px;
  padding: 8px 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  overflow: auto;
  max-height: 340px;
}
.stepcode .ln { display: flex; gap: 10px; padding: 0 8px; border-radius: 6px; }
.stepcode .ln.cur { background: var(--coral-soft); box-shadow: inset 3px 0 0 var(--coral); }
.stepcode .n { color: #b3b0a6; min-width: 22px; text-align: right; user-select: none; }
.stepcode .t { white-space: pre; }

.legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.sw { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-left: 6px; }
.sw:first-child { margin-left: 0; }
.sw.coral { background: var(--coral-soft); border: 1px solid var(--coral); }
.sw.blue { background: #fff; border: 1px solid #c3d4e6; }
.sw.green { background: var(--green-soft); border: 1px solid #a9cdbf; }
.sw.red { background: var(--red-soft); border: 1px solid #e3a6a6; }

.steptree {
  background: #fbfaf6;
  border: 1px solid #efede5;
  border-radius: 10px;
  padding: 6px;
  max-height: 360px;
  overflow: auto;
}
.steptree svg { display: block; max-width: 100%; height: auto; }

.stepframe {
  margin-top: 8px;
  border: 1px solid var(--coral);
  background: #fffaf7;
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 12px;
  max-width: 420px;
}
.stepframe .head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.stepframe .head span { font-weight: 400; color: #8a877d; }
.stepframe .vars {
  margin-top: 6px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.stepframe .vars .k { color: var(--blue); }
.stepframe .vars .v { color: #3d3b35; word-break: break-all; }

.stepout {
  margin: 0;
  background: #f4f2ec;
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  color: #3d3b35;
}

.panel .rl-wrap { margin: 0; }
.view-layout {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.view-panels { flex: 1; min-width: 0; }
.trace-inspector {
  flex: none;
  width: 268px;
  max-width: 100%;
  margin-top: 4px;
  padding: 14px;
}
.trace-inspector h2, .doctor h2 { font-size: 17px; margin: 0 0 8px; }
.trace-inspector h3, .doctor h3 { font-size: 13px; margin: 12px 0 4px; }
.trace-inspector code { overflow-wrap: anywhere; }
.trace-note { color: var(--muted); font-size: 12px; margin: 5px 0 10px; }
.trace-note.trace-error { color: var(--red); overflow-wrap: anywhere; }
.trace-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.trace-action { color: var(--blue); font-size: 12px; line-height: 1.4; padding: 5px 8px; }
.trace-action:hover { background: var(--blue-soft); border-color: var(--blue); }
.trace-action:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.inspect-call { margin-left: 8px; padding: 2px 5px; vertical-align: middle; }
.call-path, .occurrence-list {
  display: grid;
  gap: 4px;
  margin: 6px 0 10px;
  padding: 3px 3px 3px 16px;
  max-height: 250px;
  overflow: auto;
  list-style: none;
}
.call-path { border-left: 2px solid #a8c4dd; padding-left: 8px; }
.call-path button { text-align: left; overflow-wrap: anywhere; }
.occurrence-list { padding-left: 3px; }
.call-path [aria-current] { color: var(--blue); font-size: 12px; font-weight: 700; }
.doctor { padding: 18px; }
.doctor-finding { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 2px; }
.doctor-finding h3 { font-size: 14px; }
.doctor-finding p { margin: 4px 0; font-size: 13px; overflow-wrap: anywhere; }
.panel .rl-tree summary.subproblem-match { background: var(--coral-soft); }
.panel .rl-tree summary.call-on-path { box-shadow: inset 3px 0 var(--blue); }
.panel .rl-tree summary.call-selected { background: var(--blue-soft); }
g[role="button"][data-subproblem-id] { cursor: pointer; }
g[role="button"][data-subproblem-id]:focus-visible { outline: none; }
g[role="button"][data-subproblem-id]:focus-visible > rect,
g[role="button"][data-subproblem-id]:hover > rect {
  stroke: var(--blue);
  stroke-width: 2;
}
g.subproblem-match > rect { stroke: var(--coral); stroke-width: 2; }
g.call-on-path > rect, path.call-on-path { stroke: var(--blue); stroke-width: 2; }
g.call-selected > rect { fill: var(--blue-soft); stroke-width: 3; }
#panel-dag g.subproblem-match > rect { stroke: var(--blue); stroke-width: 3; }
@media (max-width: 900px) {
  .view-layout { flex-direction: column; align-items: stretch; }
  .trace-inspector { width: 100%; order: -1; margin-top: 0; }
}
#download-json { margin-bottom: 8px; }
.jsonout {
  margin: 0;
  max-height: 560px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: #3d3b35;
}

footer {
  max-width: 1180px;
  margin: 0 auto 30px;
  padding: 0 22px;
  font-size: 11.5px;
  color: var(--muted);
}

.notice {
  background: var(--coral-soft);
  border: 1px solid #e4b3a2;
  color: #8f3a1d;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
}
