/* ============================================================
   Concept Sandbox
   目的: 採点ではなく、セル・参照・関数の挙動を観察する作業台
   ============================================================ */

.lab-page {
  max-width: 1720px;
  margin: 0 auto;
  padding: 0.35rem clamp(0.75rem, 1.6vw, 1.75rem) 3rem;
}

.practice-body .nav {
  max-width: 1720px;
  padding-inline: clamp(1rem, 1.8vw, 1.75rem);
}

.lab-hero {
  align-items: end;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 300px);
  margin: 0.1rem 0 0.7rem;
}
.lab-hero .eyebrow {
  margin-bottom: 0.3rem;
}
.lab-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.32rem, 2.2vw, 1.95rem);
  font-weight: 900;
  line-height: 1.2;
  margin: 0.05rem 0 0.25rem;
  max-width: none;
}
.lab-hero .accent {
  color: var(--green);
}
.lab-lede {
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.52;
  margin: 0;
  max-width: 74ch;
}
.lab-hero-panel {
  background: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #fff;
  display: grid;
  gap: 0.35rem;
  padding: 0.8rem;
}
.panel-kicker {
  color: rgba(255, 255, 255, 0.68);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lab-hero-panel strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  line-height: 1.3;
}
.lab-hero-panel span:last-child {
  color: var(--green-tint);
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.lab-layout {
  align-items: start;
  display: grid;
  gap: 0.75rem;
  grid-template-areas: "rail workbench inspector";
  grid-template-columns: clamp(210px, 16vw, 270px) minmax(380px, 1fr) clamp(250px, 22vw, 370px);
}
.lab-rail,
.workbench,
.lab-inspector {
  min-width: 0;
}
.lab-rail { grid-area: rail; }
.workbench { grid-area: workbench; }
.lab-inspector { grid-area: inspector; }
.lab-rail,
.workbench,
.inspector-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.lab-rail {
  align-content: start;
  display: grid;
  gap: 0.72rem;
  grid-template-areas:
    "head"
    "search"
    "list"
    "tools";
  grid-template-columns: 1fr;
  max-height: calc(100vh - 5.9rem);
  overflow: auto;
  padding: 0.72rem;
  position: sticky;
  scrollbar-gutter: stable;
  top: 5rem;
  z-index: 8;
}
.lab-rail > .rail-head { grid-area: head; }
.rail-head {
  display: grid;
  gap: 0.12rem;
  align-content: center;
}
.rail-head.compact strong {
  font-size: 1rem;
}
.rail-kicker {
  color: var(--live);
  font-family: var(--font-mono);
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.rail-head strong {
  font-family: var(--font-display);
  font-size: 1.04rem;
  line-height: 1.25;
}

.catalog-controls {
  display: grid;
  gap: 0.55rem;
  grid-area: search;
  align-self: center;
}
#catalogSearch {
  background: #fff;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.92rem;
  min-height: 42px;
  outline: none;
  padding: 0 0.75rem;
  width: 100%;
}
#catalogSearch:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 131, 76, 0.14);
}
.scenario-list,
.formula-tools,
.formula-map,
.reference-flow {
  display: grid;
  gap: 0.5rem;
}
.scenario-list {
  grid-area: list;
  grid-auto-flow: row;
  grid-template-columns: 1fr;
  max-height: calc(100vh - 20.6rem);
  min-height: 300px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.08rem 0.16rem 0.16rem 0;
  scroll-padding-block: 0.5rem;
}
.scenario-btn {
  align-items: start;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: 30px minmax(0, 1fr);
  min-height: 64px;
  overflow: hidden;
  padding: 0.58rem 0.62rem;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  width: 100%;
}
.scenario-btn:hover {
  border-color: var(--green);
  transform: translateY(-1px);
}
.scenario-btn.active {
  background: var(--green-tint);
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(22, 131, 76, 0.2);
}
.scenario-btn.function .scenario-no {
  background: var(--green-tint);
  color: var(--green-deep);
}
.scenario-btn.concept .scenario-no {
  background: var(--blue-tint);
  color: var(--blue);
}
.scenario-no {
  align-items: center;
  background: var(--paper-2);
  border-radius: 999px;
  color: var(--ink-soft);
  display: inline-flex;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  height: 28px;
  justify-content: center;
  margin-top: 0.05rem;
  min-width: 28px;
  width: 28px;
}
.scenario-btn > span:last-child {
  min-width: 0;
  overflow: hidden;
}
.scenario-btn b {
  display: block;
  font-size: 0.84rem;
  line-height: 1.28;
  overflow-wrap: anywhere;
}
.scenario-btn small {
  color: var(--ink-faint);
  display: block;
  font-size: 0.77rem;
  line-height: 1.3;
  margin-top: 0.12rem;
  overflow-wrap: anywhere;
}
.catalog-empty {
  background: var(--paper);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 0;
  padding: 0.75rem;
}
.toolbox {
  border-top: 1px solid var(--line);
  grid-area: tools;
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  padding-top: 0.72rem;
}
.formula-tools {
  display: grid;
  gap: 0.4rem;
  grid-template-columns: 1fr;
}
.formula-chip {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  min-height: 38px;
  overflow: hidden;
  padding: 0.36rem 0.52rem;
  text-overflow: clip;
  white-space: normal;
  word-break: break-word;
}
.formula-chip:hover {
  border-color: var(--green);
  color: var(--green-deep);
}

.workbench {
  overflow: hidden;
  padding: 1rem;
}
.workbench-head {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
}
.scenario-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.grade-badge,
.concept-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  min-height: 28px;
  padding: 0.36rem 0.62rem;
}
.grade-badge {
  background: var(--green);
  color: #fff;
}
.concept-badge {
  background: var(--paper-2);
  color: var(--ink-soft);
}
.workbench h2 {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.4vw, 1.65rem);
  line-height: 1.28;
  margin: 0.28rem 0 0.25rem;
}
.workbench p {
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0;
}
.workbench-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}
.soft-btn {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 800;
  min-height: 38px;
  padding: 0.35rem 0.75rem;
  white-space: nowrap;
}
.soft-btn:hover,
.soft-btn[aria-pressed="true"] {
  border-color: var(--green);
  color: var(--green-deep);
}

.lab-formula-bar {
  align-items: center;
  background: var(--paper);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
  min-width: 0;
  padding: 0.35rem 0.5rem;
}
.lab-formula-bar:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 131, 76, 0.14);
}
.flow-summary {
  align-items: stretch;
  background: linear-gradient(90deg, #fff, var(--paper));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0.45rem;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.15fr) auto minmax(0, 0.85fr);
  margin: -0.25rem 0 0.75rem;
  padding: 0.5rem;
}
.summary-step {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(214, 225, 217, 0.8);
  border-radius: 7px;
  display: grid;
  gap: 0.16rem;
  min-width: 0;
  padding: 0.45rem 0.55rem;
}
.summary-label {
  color: var(--ink-faint);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}
.summary-value {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: anywhere;
}
.summary-arrow {
  align-self: center;
  color: var(--live);
  font-weight: 900;
  line-height: 1;
}
.active-cell {
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-weight: 700;
  min-width: 3em;
  text-align: center;
}
#labFormula {
  background: transparent;
  border: none;
  color: var(--ink);
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.96rem;
  min-height: 36px;
  min-width: 0;
  outline: none;
}

.sheet-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: calc(100vh - 23rem);
  min-height: 300px;
  overflow: auto;
  position: relative;
}
.lab-sheet {
  display: grid;
  font-family: var(--font-mono);
  min-width: max-content;
  position: relative;
  width: 100%;
  z-index: 1;
}
.link-layer {
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  position: absolute;
  z-index: 4;
}
.link-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.78);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}
.link-path {
  fill: none;
  marker-end: url(#labArrow);
  opacity: 0.68;
  stroke: var(--live);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}
.link-path.dependent {
  stroke: var(--blue);
}
#labArrow path {
  fill: var(--live);
  stroke: #fff;
  stroke-linejoin: round;
  stroke-width: 0.8;
}
.sheet-head,
.lab-cell {
  align-items: center;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  display: flex;
  min-height: 46px;
  padding: 0 0.68rem;
}
.sheet-head {
  background: var(--paper-2);
  color: var(--ink-faint);
  font-size: 0.78rem;
  font-weight: 700;
  justify-content: center;
  position: relative;
  z-index: 2;
}
.lab-cell {
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.94rem;
  justify-content: flex-start;
  min-width: 0;
  position: relative;
  text-align: left;
  transition: background 0.14s, box-shadow 0.14s, color 0.14s;
  white-space: nowrap;
}
.lab-cell:hover {
  background: var(--green-tint);
}
.lab-cell.num {
  justify-content: flex-end;
}
.lab-cell.formula {
  color: var(--green-deep);
}
.lab-cell.selected {
  background: #fff;
  box-shadow: inset 0 0 0 2.5px var(--green);
  color: var(--ink);
  z-index: 6;
}
.lab-cell.precedent {
  background: var(--amber-tint);
  box-shadow: inset 0 0 0 2px rgba(217, 140, 0, 0.55);
  z-index: 5;
}
.lab-cell.dependent {
  background: var(--blue-tint);
  box-shadow: inset 0 0 0 2px rgba(47, 111, 190, 0.42);
  z-index: 5;
}
.lab-cell.error {
  background: var(--live-tint);
  color: var(--live);
  font-weight: 700;
}
.cell-value {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-fx {
  background: var(--green-tint);
  border-radius: 999px;
  bottom: 3px;
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0 0.25rem;
  position: absolute;
  right: 4px;
}
.cell-editor {
  background: #fff;
  border: none;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  height: 100%;
  min-height: 40px;
  outline: none;
  width: 100%;
}

.lab-inspector {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: 1fr;
  position: sticky;
  top: 5rem;
  max-height: calc(100vh - 5.8rem);
  overflow: auto;
  padding-right: 0.1rem;
  scrollbar-gutter: stable;
}
.function-guide-card { order: 1; }
.selected-card { order: 2; }
.reference-card { order: 3; }
.calculation-card { order: 4; }
.map-card { order: 5; }
.inspector-card {
  overflow: hidden;
  padding: 0.78rem;
}
.inspector-card h3 {
  font-family: var(--font-display);
  font-size: 1.08rem;
  margin: 0.15rem 0 0.65rem;
}
.function-guide-card {
  border-color: rgba(22, 131, 76, 0.28);
}
.function-guide-card h3 {
  color: var(--green-deep);
  font-size: 1.22rem;
}
.function-guide-card p {
  color: var(--ink-soft);
  line-height: 1.6;
  margin: 0 0 0.65rem;
}
.syntax-line {
  background: var(--ink);
  border-radius: var(--radius-sm);
  color: var(--green-tint);
  display: block;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.45;
  margin-bottom: 0.65rem;
  overflow-wrap: anywhere;
  padding: 0.58rem 0.62rem;
}
.guide-rulebox {
  background: var(--green-tint);
  border: 1px solid rgba(22, 131, 76, 0.24);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0.42rem;
  margin: 0 0 0.65rem;
  padding: 0.58rem 0.62rem;
}
.guide-rulebox[hidden] {
  display: none;
}
.guide-rulebox strong {
  color: var(--green-deep);
  font-size: 0.78rem;
  font-weight: 900;
}
.guide-rulebox ul {
  display: grid;
  gap: 0.32rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.guide-rulebox li {
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.5;
  padding-left: 1rem;
  position: relative;
}
.guide-rulebox li::before {
  color: var(--green-deep);
  content: "・";
  font-weight: 900;
  left: 0;
  position: absolute;
}
.guide-points {
  display: grid;
  gap: 0.38rem;
  list-style: none;
  margin: 0 0 0.55rem;
  padding: 0;
}
.guide-points li {
  background: var(--paper);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.45;
  padding: 0.46rem 0.55rem 0.46rem 1.65rem;
  position: relative;
}
.guide-points li::before {
  background: var(--green);
  border-radius: 999px;
  content: "";
  height: 0.45rem;
  left: 0.72rem;
  position: absolute;
  top: 0.93rem;
  width: 0.45rem;
}
.guide-details {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.42rem;
  margin: 0.55rem 0 0;
  padding-top: 0.55rem;
}
.guide-details[hidden] {
  display: none;
}
.guide-details div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0.16rem;
  padding: 0.5rem 0.58rem;
}
.guide-details dt {
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 800;
}
.guide-details dd {
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.52;
  margin: 0;
}
.selected-title {
  align-items: center;
  display: flex;
  gap: 0.55rem;
  justify-content: space-between;
  margin-top: 0.2rem;
}
.selected-title strong {
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-size: 2rem;
  line-height: 1;
}
.selected-title span {
  background: var(--paper-2);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.28rem 0.55rem;
}
.cell-facts {
  display: grid;
  gap: 0.45rem;
  margin: 0.85rem 0;
}
.cell-facts div {
  background: var(--paper);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0.1rem;
  padding: 0.5rem 0.6rem;
}
.cell-facts dt {
  color: var(--ink-faint);
  font-size: 0.72rem;
  font-weight: 800;
}
.cell-facts dd {
  color: var(--ink);
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
.cell-facts code {
  color: var(--green-deep);
  font-family: var(--font-mono);
}
.cell-message {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0;
}
.flow-block {
  background: var(--paper);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0.45rem;
  padding: 0.6rem;
}
.flow-block span {
  color: var(--ink-faint);
  font-size: 0.74rem;
  font-weight: 800;
}
.ref-chip,
.ref-pill {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 800;
  display: inline-flex;
  margin: 0.12rem 0.18rem 0.12rem 0;
  padding: 0.2rem 0.46rem;
}
.ref-chip {
  cursor: pointer;
}
.ref-chip:hover {
  border-color: var(--green);
}
.empty-note,
.no-ref {
  color: var(--ink-faint);
  font-size: 0.88rem;
}
.step-list {
  display: grid;
  gap: 0.45rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.step-list li {
  background: var(--paper);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0.15rem 0.5rem;
  grid-template-columns: auto 1fr;
  padding: 0.55rem;
}
.step-list span {
  align-items: center;
  background: #fff;
  border-radius: 999px;
  color: var(--green-deep);
  display: inline-flex;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 800;
  height: 24px;
  justify-content: center;
  min-width: 24px;
  padding: 0 0.2rem;
}
.step-list b {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}
.step-list small {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  grid-column: 2;
}
.map-row {
  background: var(--paper);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 0.28rem;
  padding: 0.55rem;
  text-align: left;
}
.map-row:hover,
.map-row.active {
  border-color: var(--green);
}
.map-cell {
  color: var(--green-deep);
  font-family: var(--font-mono);
  font-weight: 800;
}
.map-row code {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}
.map-row strong {
  color: var(--ink);
  font-family: var(--font-mono);
}
.map-row small {
  display: block;
}

@media (max-width: 900px) {
  .lab-layout {
    grid-template-areas:
      "rail"
      "workbench"
      "inspector";
    grid-template-columns: 1fr;
  }
  .lab-rail {
    grid-template-areas:
      "head search"
      "list list"
      "tools tools";
    grid-template-columns: 160px minmax(0, 1fr);
    max-height: none;
    overflow: visible;
    position: static;
  }
  .scenario-list {
    grid-auto-columns: minmax(178px, 235px);
    grid-auto-flow: column;
    grid-template-columns: none;
    max-height: none;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0.2rem;
  }
  .toolbox {
    border-left: none;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 0.65rem;
  }
  .formula-tools {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.12rem;
  }
  .sheet-shell {
    max-height: none;
  }
}

@media (max-width: 840px) {
  .lab-hero,
  .lab-layout {
    grid-template-columns: 1fr;
  }
  .lab-layout {
    grid-template-areas:
      "rail"
      "workbench"
      "inspector";
  }
  .lab-inspector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
    position: static;
  }
  .workbench-head {
    align-items: stretch;
    flex-direction: column;
  }
  .workbench-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .lab-page {
    padding: 1rem 1rem 3rem;
  }
  .lab-hero {
    gap: 0.45rem;
    margin-top: 0.2rem;
    margin-bottom: 0.45rem;
  }
  .lab-hero .eyebrow,
  .lab-lede {
    display: none;
  }
  .lab-hero h1 {
    font-size: 1.36rem;
    max-width: none;
  }
  .lab-hero-panel {
    display: none;
  }
  .lab-rail {
    grid-template-areas:
      "search"
      "list";
    grid-template-columns: 1fr;
    gap: 0.5rem;
    padding: 0.62rem;
  }
  .lab-rail > .rail-head,
  .toolbox {
    display: none;
  }
  .scenario-list {
    grid-auto-columns: minmax(170px, 82vw);
    max-height: none;
    overflow-x: auto;
  }
  .formula-tools {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding-bottom: 0.1rem;
  }
  .formula-chip {
    flex: 0 0 auto;
    min-width: 88px;
    padding: 0 0.7rem;
  }
  .lab-inspector {
    grid-template-columns: 1fr;
  }
  .lab-formula-bar {
    flex-wrap: wrap;
  }
  .flow-summary {
    gap: 0.35rem;
    grid-template-columns: 1fr;
    padding: 0.42rem;
  }
  .summary-arrow {
    display: none;
  }
  #labFormula {
    flex-basis: 100%;
  }
  .sheet-head,
  .lab-cell {
    min-height: 40px;
    padding: 0 0.45rem;
  }
}
