/* ==========================================================
   Phyllotaxis Lab — Liquid Glass theme (light)
   space_syntax / gibson の共有テーマを踏襲。
   植物学的な gold / green アクセントに調整。
   ========================================================== */

:root {
  --bg0: #edf2ec;
  --bg1: #f6faf4;
  --text: #1c211b;
  --text-dim: rgba(48, 62, 46, 0.68);
  --text-faint: rgba(48, 62, 46, 0.42);
  --stroke: rgba(24, 44, 24, 0.1);
  --stroke-bright: rgba(24, 44, 24, 0.18);
  --accent: #1e9d5a;   /* leaf green */
  --accent2: #c98a0b;  /* golden */
  --mint: #0d8f6a;
  --coral: #e8503f;
  --gold: #c98a0b;
  --radius: 24px;
  --radius-sm: 14px;
}

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

html {
  color-scheme: light;
}

body {
  min-height: 100vh;
  background: var(--bg0);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.75;
  overflow-x: hidden;
}

/* ---------- animated backdrop ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 75% -10%, #ffffff 0%, transparent 60%),
    linear-gradient(180deg, var(--bg1) 0%, var(--bg0) 70%);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(95px);
  opacity: 0.5;
  animation: drift 30s ease-in-out infinite alternate;
}

.blob.b1 {
  width: 620px;
  height: 620px;
  left: -160px;
  top: -180px;
  background: radial-gradient(circle at 35% 35%, #b5e8c2, transparent 70%);
}

.blob.b2 {
  width: 540px;
  height: 540px;
  right: -140px;
  top: -60px;
  background: radial-gradient(circle at 40% 40%, #f3e2ad, transparent 70%);
  animation-delay: -10s;
}

.blob.b3 {
  width: 600px;
  height: 600px;
  left: 30%;
  bottom: -280px;
  background: radial-gradient(circle at 50% 35%, #cfeab8, transparent 70%);
  animation-delay: -18s;
}

@keyframes drift {
  to {
    transform: translate(70px, 50px) scale(1.14);
  }
}

@media (prefers-reduced-motion: reduce) {
  .blob {
    animation: none;
  }
}

/* ---------- glass surface ---------- */

.glass {
  position: relative;
  background: linear-gradient(
    160deg,
    rgba(255, 255, 255, 0.78),
    rgba(255, 255, 255, 0.55) 45%,
    rgba(255, 255, 255, 0.68)
  );
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow:
    0 24px 60px rgba(40, 55, 90, 0.14),
    0 1px 2px rgba(40, 55, 90, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.55), transparent 30%);
  pointer-events: none;
}

/* ---------- page layout ---------- */

.page {
  max-width: 1500px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 14px clamp(14px, 2.4vw, 32px) 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s ease;
}
.back-link:hover { color: var(--accent); }

.app-header {
  padding: 2px 6px 0;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.app-header > div {
  min-width: 0;
}

.eyebrow,
.module-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.app-header h1 {
  font-size: clamp(20px, 2.2vw, 27px);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.3;
  background: linear-gradient(92deg, #1c211b 10%, #1e9d5a 55%, #c98a0b 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lead {
  flex: 1;
  min-width: 280px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}

@media (max-height: 820px) {
  .lead {
    display: none;
  }
}

/* ---------- module tabs ---------- */

.module-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(146px, 1fr));
  gap: 10px;
}

.tab-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 14px;
  padding: 7px 12px 6px;
  text-align: left;
  color: var(--text-dim);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.66), rgba(255, 255, 255, 0.42));
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
  box-shadow: 0 2px 10px rgba(40, 55, 90, 0.08);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.tab-button:hover {
  transform: translateY(-2px);
  color: var(--text);
  box-shadow: 0 8px 22px rgba(40, 55, 90, 0.14);
}

.tab-button span {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tab-button small {
  display: block;
  margin-top: 1px;
  font-size: 9.5px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.tab-button[aria-selected="true"] {
  color: #ffffff;
  background: linear-gradient(135deg, #1e9d5a, #c98a0b);
  border-color: transparent;
  box-shadow:
    0 10px 26px rgba(40, 130, 70, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.tab-button[aria-selected="true"] small {
  color: rgba(255, 255, 255, 0.74);
}

/* ---------- main lab layout ---------- */

.lab-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(310px, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "canvas info"
    "controls info";
  gap: 14px;
  align-items: stretch;
}

.canvas-panel {
  grid-area: canvas;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.canvas-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-stage {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(20, 30, 50, 0.08),
    0 10px 32px rgba(40, 55, 90, 0.16);
}

#labCanvas {
  position: relative;
  z-index: 2;
  display: block;
  max-width: 100%;
  background: #12160f;
  touch-action: none;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 16px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(40, 55, 90, 0.14);
  -webkit-backdrop-filter: blur(14px) saturate(170%);
  backdrop-filter: blur(14px) saturate(170%);
  pointer-events: none;
}

.canvas-note {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-faint);
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- info panel ---------- */

.info-panel {
  grid-area: info;
  min-height: 0;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.info-panel h2 {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.3;
}

.module-subtitle {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: -8px;
}

.info-panel > p {
  color: var(--text-dim);
  font-size: 13.5px;
}

.info-panel section {
  border-top: 1px solid rgba(20, 30, 50, 0.09);
  padding-top: 12px;
}

.info-panel h3 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mint);
  margin-bottom: 6px;
}

.info-panel section p,
.info-panel li {
  font-size: 13.5px;
  color: var(--text-dim);
}

.info-panel ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-panel li::marker {
  color: var(--accent);
}

/* ---------- calc card (計算過程ライブ領域) ---------- */

.calc-section h3 {
  color: var(--accent2);
}

.calc-card {
  border-radius: var(--radius-sm);
  border: 1px solid rgba(79, 70, 229, 0.18);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.92), rgba(238, 240, 255, 0.7));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  padding: 12px 14px;
  font-size: 13px;
}

.calc-empty {
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.5;
}

.calc-card .calc-title {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.calc-card .calc-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 9px;
  border-radius: 999px;
  color: #fff;
  background: var(--accent2);
}

.calc-card .calc-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.calc-card ol.calc-steps {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  counter-reset: step;
}

.calc-card ol.calc-steps > li {
  position: relative;
  padding-left: 26px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.calc-card ol.calc-steps > li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(79, 70, 229, 0.14);
  color: var(--accent2);
  font-size: 10.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calc-card .calc-step-label {
  display: block;
  font-weight: 700;
  color: var(--text);
  font-size: 12px;
}

.calc-card .eq {
  font-family: "SFMono-Regular", "DejaVu Sans Mono", ui-monospace, "Menlo", monospace;
  font-size: 12px;
  color: var(--text);
  background: rgba(13, 143, 147, 0.08);
  border-radius: 7px;
  padding: 2px 7px;
  display: inline-block;
  margin-top: 2px;
  line-height: 1.7;
}

.calc-card .calc-result {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed rgba(79, 70, 229, 0.25);
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.calc-card .calc-result b {
  color: var(--accent2);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.calc-card .calc-note {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

.calc-card em {
  color: var(--accent);
  font-style: normal;
  font-weight: 700;
}

/* hover tooltip for jargon (e.g. 次数) */
.calc-card .tip {
  border-bottom: 1px dotted var(--accent2);
  cursor: help;
  position: relative;
}

.calc-card .tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: 145%;
  z-index: 20;
  width: max-content;
  max-width: 210px;
  white-space: normal;
  background: #1b1d22;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  padding: 6px 9px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

/* ---------- controls ---------- */

.controls-panel {
  grid-area: controls;
  padding: 12px 18px 14px;
}

.controls-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.controls-heading h2 {
  font-size: 14px;
  font-weight: 800;
}

.reset-button {
  appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid rgba(20, 30, 50, 0.12);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.7));
  box-shadow: 0 2px 8px rgba(40, 55, 90, 0.08);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.reset-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(13, 143, 147, 0.2);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px 18px;
  align-items: center;
}

.control label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.control output {
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

/* range slider */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(13, 143, 147, 0.6), rgba(79, 70, 229, 0.45));
  box-shadow: inset 0 1px 2px rgba(40, 55, 90, 0.18);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  border: 0.5px solid rgba(20, 30, 50, 0.12);
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(40, 55, 90, 0.3), 0 0 0 4px rgba(13, 143, 147, 0.08);
  transition: box-shadow 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 3px 8px rgba(40, 55, 90, 0.3), 0 0 0 7px rgba(13, 143, 147, 0.14);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(13, 143, 147, 0.6), rgba(79, 70, 229, 0.45));
}

input[type="range"]::-moz-range-thumb {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 0.5px solid rgba(20, 30, 50, 0.12);
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(40, 55, 90, 0.3);
}

/* toggle (checkbox) — iOS スイッチ風 */

.checkbox-control {
  display: flex !important;
  flex-direction: row;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 12px !important;
  cursor: pointer;
}

.checkbox-control input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: rgba(120, 120, 128, 0.22);
  border: none;
  position: relative;
  cursor: pointer;
  transition: background 0.22s ease;
}

.checkbox-control input::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  translate: 0 -50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22), 0 0 1px rgba(0, 0, 0, 0.12);
  transition: left 0.22s ease;
}

.checkbox-control input:checked {
  background: #34c759;
}

.checkbox-control input:checked::before {
  left: 19px;
}

/* segmented control — iOS セグメント風(白ピル) */

.segmented-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: rgba(120, 120, 128, 0.14);
}

.segmented button {
  flex: 1;
  min-width: 0;
  padding: 6px 5px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  overflow-wrap: break-word;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button[aria-pressed="true"] {
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14), 0 3px 8px rgba(0, 0, 0, 0.06);
}

/* plain glass button */

.plain-button {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  width: 100%;
  color: var(--accent);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(20, 30, 50, 0.12);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.7));
  box-shadow: 0 2px 8px rgba(40, 55, 90, 0.08);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.plain-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(13, 143, 147, 0.18);
}

select {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .page {
    height: auto;
    overflow: visible;
  }

  .lab-layout {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-template-areas:
      "canvas"
      "controls"
      "info";
  }

  .canvas-frame {
    min-height: 320px;
  }

  .module-tabs {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}

/* ==========================================================
   Phyllotaxis-specific additions
   ========================================================== */

/* big live readout for the divergence angle / key value */
.readout {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(201, 138, 11, 0.22);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.92), rgba(250, 243, 224, 0.7));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.readout .readout-value {
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent2);
}

.readout .readout-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.readout .readout-sub {
  flex-basis: 100%;
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* packing-quality meter */
.meter {
  margin-top: 4px;
}

.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.meter-head span:first-child {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.meter-head .meter-val {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.meter-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(120, 128, 110, 0.2);
  overflow: hidden;
}

.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #e8503f 0%, #e0a90b 45%, #1e9d5a 100%);
  transition: width 0.25s ease;
}

.meter-caption {
  margin-top: 5px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-faint);
}

/* continued-fraction / convergent chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chips .chip {
  font-family: "SFMono-Regular", "DejaVu Sans Mono", ui-monospace, "Menlo", monospace;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(30, 157, 90, 0.1);
  border: 1px solid rgba(30, 157, 90, 0.2);
}

.chips .chip.is-gold {
  color: #7a5308;
  background: rgba(201, 138, 11, 0.14);
  border-color: rgba(201, 138, 11, 0.32);
}

/* arm-family legend row */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 6px;
}

.legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.legend .legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

/* fibonacci highlight inline */
.fib {
  color: var(--accent2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
