/* ==========================================================
   sim.css — โครงหน้า sim ที่ใช้ร่วมกันทั้ง 4 หน้า (โหลดหลัง site.css)
   หน้าแบ่ง 2 โซนเต็มจอ + scroll-snap:
     โซน A (.zone-experiment) — ทุ่งหญ้า/ท้องฟ้าเต็มโซน แผงปัจจัย+ตาราง เป็นการ์ดลอย
     โซน B (.zone-analysis)   — พื้นเรียบ แผงกราฟครอบด้วยเส้นกรอบเดียว ไม่ลอย
   ส่วนเฉพาะของแต่ละการทดลอง (ตัวจรวด/ร่ม/เครื่องยิง) อยู่ใน style.css ของโฟลเดอร์นั้น
   ========================================================== */
:root {
  /* สีฉากธรรมชาติ — แยกจากธีม UI */
  --sky-top: #9fd4f6;
  --sky-bottom: #e4f3fb;
  --ground: #7cc26b;
  --ground-dark: #5ea64f;
  --ground-deep: #4b8e3f;
  --trail: #f59e0b;
  --exhaust: #f97316;
  --exhaust-dark: #ea580c;

  --col-alt: #f1f5f9; /* คอลัมน์คู่ของตารางผล */
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.08);

  /* ชื่อเดิมที่โค้ด/สไตล์เดิมอ้างถึง */
  --accent: var(--blue);
  --accent-dark: var(--navy);

  --card-radius: 16px;
  --card-shadow: 0 18px 40px rgba(11, 28, 51, 0.18), 0 2px 6px rgba(11, 28, 51, 0.08);

  --horizon: 72%; /* app.js ตั้งค่าเป็น px ให้ตรงเส้นพื้นของฉากจริง */
}

html {
  scroll-snap-type: y mandatory;
  scroll-padding-top: var(--nav-h);
  scroll-behavior: smooth;
}

/* จอแคบ (มือถือ/แท็บเล็ต): ปิด CSS snap — เบราว์เซอร์มือถือดูดแรงและ re-snap ตอนโหลดหน้า (เปิดแล้วเด้ง)
   การดูดเข้าโซนกราฟบนจอแคบทำด้วย assets/zone-snap.js แทน (ดูดเฉพาะตอนผู้ใช้เลื่อนลงเอง) */
@media (max-width: 900px) {
  html {
    scroll-snap-type: none;
  }
}

main {
  display: block;
}

.zone {
  position: relative;
  scroll-snap-align: start;
  min-height: calc(100dvh - var(--nav-h));
}

/* ==========================================================
   โซน A — Experiment
   ========================================================== */
.zone-experiment {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--nav-h));
  padding: 18px clamp(16px, 2.2vw, 32px) 0;
  overflow: hidden;
  background: linear-gradient(
    to bottom,
    var(--sky-top) 0,
    var(--sky-bottom) var(--horizon),
    var(--ground) var(--horizon),
    var(--ground-dark) calc(var(--horizon) + 22px),
    var(--ground-deep) 100%
  );
}

/* ใบหญ้าเรียงตามเส้นขอบฟ้า + ลายสนามตัดหญ้าจางๆ ใต้เส้น */
.zone-experiment::before,
.zone-experiment::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.zone-experiment::before {
  top: var(--horizon);
  height: 10px;
  transform: translateY(-100%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='46' height='10'%3E%3Cpath d='M3 10 5 2l2 8M14 10l3-9 2 9M27 10l2-6 2 6M37 10l3-8 2 8' fill='%237cc26b'/%3E%3C/svg%3E") repeat-x bottom;
}

.zone-experiment::after {
  top: var(--horizon);
  bottom: 0;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 70px, transparent 70px 140px);
}

.workspace {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding-bottom: 58px; /* ที่ว่างให้ลูกศรบอกเลื่อนลง */
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 330px;
  gap: 20px;
}

/* ไม่ให้เนื้อหากว้าง (ตาราง) ดันคอลัมน์ grid จนหน้าเว็บกว้างเกินจอ */
.workspace > *,
.effects-grid > * {
  min-width: 0;
}

/* การ์ดลอย: ทึบ ขาว มุมมน มีเงา */
.card-float {
  min-height: 0;
  overflow: auto;
  background: var(--white);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
}

/* scrollbar บาง มุมมน ไม่มีปุ่มลูกศร และเว้นระยะจากขอบบน/ล่าง จะได้ไม่ทับมุมโค้งของการ์ด */
.card-float::-webkit-scrollbar,
.table-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.card-float::-webkit-scrollbar-track,
.table-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.card-float::-webkit-scrollbar-track {
  margin: 14px 0;
}

.card-float::-webkit-scrollbar-thumb,
.table-scroll::-webkit-scrollbar-thumb {
  border: 2px solid var(--white);
  border-radius: 999px;
  background: #cbd5e1;
}

.card-float::-webkit-scrollbar-thumb:hover,
.table-scroll::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.card-float::-webkit-scrollbar-button,
.table-scroll::-webkit-scrollbar-button,
.card-float::-webkit-scrollbar-corner,
.table-scroll::-webkit-scrollbar-corner {
  display: none;
  background: transparent;
}

@supports not selector(::-webkit-scrollbar) {
  .card-float,
  .table-scroll {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
  }
}

/* ---------------- แผงปัจจัย ---------------- */
.controls-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-heading h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.param-group label,
fieldset legend {
  display: block;
  margin-bottom: 6px;
  font-size: 0.86rem;
  font-weight: 600;
}

.range-hint {
  margin-left: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 400;
}

.param-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.param-row input[type='range'] {
  flex: 1;
  min-width: 0;
  accent-color: var(--blue);
}

.param-row input[type='number'] {
  width: 70px;
  padding: 5px 7px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.param-row input[type='number']:focus {
  border-color: var(--blue);
  outline: none;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset legend {
  padding: 0;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.segmented label {
  position: relative;
  display: block;
}

.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented label span {
  display: block;
  padding: 8px 6px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented input:checked + span {
  background: var(--navy);
  color: var(--white);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.warning-box {
  padding: 8px 10px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.82rem;
}

.constants-note {
  color: var(--muted);
  font-size: 0.8rem;
}

.constants-note summary {
  margin-bottom: 6px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
}

.constants-note ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.5;
}

/* ---------------- พื้นที่จำลอง (โปร่ง วาดบนพื้นหลังโซนตรงๆ) ---------------- */
.simulation-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scene {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
}

.scene-sun {
  position: absolute;
  top: 36px;
  left: 50%;
  width: 58px;
  height: 58px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6d8, #ffd166 60%, #ffb703 100%);
  box-shadow: 0 0 26px 8px rgba(255, 183, 3, 0.3);
}

.scene-cloud {
  position: absolute;
  width: 58px;
  height: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
}

.scene-cloud::before,
.scene-cloud::after {
  content: '';
  position: absolute;
  bottom: 0;
  border-radius: 50%;
  background: inherit;
}

.scene-cloud::before {
  left: 10px;
  width: 24px;
  height: 24px;
}

.scene-cloud::after {
  right: 8px;
  width: 32px;
  height: 32px;
}

.scene-cloud-a {
  top: 44px;
  left: 10%;
  transform: scale(1.3);
}

.scene-cloud-b {
  top: 78px;
  right: 12%;
  opacity: 0.85;
  transform: scale(1.6);
}

/* แถบพื้นในฉากเดิม — เหลือไว้แค่ความสูง (บางการทดลองใช้คำนวณเส้นพื้น) หญ้าจริงมาจากพื้นหลังโซน */
.scene-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  background: none;
}

.scene-ground span {
  display: none;
}

#trailCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.axis-y {
  position: absolute;
  top: 14px;
  bottom: 44px;
  left: 10px;
  display: flex;
  flex-direction: column-reverse;
  justify-content: space-between;
  padding-left: 6px;
  border-left: 1px dashed rgba(11, 28, 51, 0.4);
  color: var(--navy);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.axis-x {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  display: flex;
  justify-content: space-between;
  color: var(--white);
  font-size: 0.68rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(11, 28, 51, 0.45);
  pointer-events: none;
}

.axis-label {
  position: absolute;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--navy);
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  pointer-events: none;
}

.axis-label.y-label {
  top: 8px;
  left: 10px;
}

.axis-label.x-label {
  right: 10px;
  bottom: 26px;
}

/* แถบผลลัพธ์รอบปัจจุบัน — pill ลอย เข้าชุดกับการ์ด */
.live-stats {
  align-self: center;
  max-width: 100%;
  margin-top: 12px;
  padding: 9px 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
  border-radius: 999px;
  background: var(--white);
  box-shadow: var(--card-shadow);
}

.live-stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 0.82rem;
}

.live-stat-label {
  color: var(--muted);
}

.live-stat-value {
  color: var(--navy);
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ลูกศรบอกให้เลื่อนลงไปดูกราฟ */
.scroll-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 2;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(11, 28, 51, 0.72);
  color: var(--white);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  transition: background 0.15s ease;
}

.scroll-hint:hover {
  background: var(--navy);
}

.scroll-hint:hover .icon {
  animation: hint-nudge 0.6s ease;
}

@keyframes hint-nudge {
  50% {
    transform: translateY(3px);
  }
}

/* ---------------- ตารางผล ---------------- */
.results-sidebar {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.table-toolbar h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

/* หัวข้อ + ปุ่มเฟืองตั้งค่าคอลัมน์ (ตั้งค่าได้เฉพาะตารางย่อ จึงซ่อนตอนขยาย) */
.table-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#tableSettingsBtn {
  width: 32px;
  height: 32px;
  padding: 0;
  flex: none;
}

.results-sidebar.expanded #tableSettingsBtn {
  display: none;
}

/* ---------------- หน้าตั้งค่าคอลัมน์: การ์ดลอยกลางจอ หลังเป็นฝ้าแบบตารางขยาย ---------------- */
.ts-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(11, 28, 51, 0.5);
  backdrop-filter: blur(6px);
}

.ts-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 81;
  width: min(92vw, 380px);
  max-height: 85vh;
  overflow: auto;
  padding: 20px;
  transform: translate(-50%, -50%);
  background: var(--white);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
}

.ts-backdrop[hidden],
.ts-dialog[hidden] {
  display: none;
}

body.ts-open {
  overflow: hidden;
}

.ts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ts-head h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.ts-close {
  width: 32px;
  height: 32px;
  padding: 0;
  flex: none;
}

.ts-intro {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.8rem;
}

.ts-group {
  margin: 0 0 12px;
  padding: 0;
  border: 0;
}

.ts-group legend {
  margin-bottom: 4px;
  padding: 0;
  color: var(--blue);
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ts-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.ts-option:hover {
  background: var(--blue-50);
}

.ts-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--blue);
  cursor: pointer;
}

.ts-option input:disabled,
.ts-option input:disabled + span {
  cursor: not-allowed;
  opacity: 0.6;
}

.ts-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.ts-actions .primary-button {
  width: auto;
  padding: 8px 18px;
  font-size: 0.9rem;
}

.ts-actions .secondary-button {
  padding: 8px 14px;
  font-size: 0.85rem;
}

/* การ์ดตารางย่อ: ปุ่มขยายเหลือแค่ไอคอน (ใน modal โชว์ข้อความ "ปิด" เต็ม) */
.results-sidebar:not(.expanded) #expandTableBtn {
  width: 36px;
  height: 36px;
  padding: 0;
}

.results-sidebar:not(.expanded) #expandTableBtn .btn-label {
  display: none;
}

.table-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  position: sticky;
  top: 0;
  padding: 7px 6px;
  border-bottom: 2px solid var(--navy);
  background: var(--white);
  color: var(--navy);
  font-family: var(--font-display);
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

tbody td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  white-space: nowrap;
}

/* สีสลับคอลัมน์ให้อ่านง่าย: คอลัมน์คี่ขาว คอลัมน์คู่เทาอ่อน
   ตารางขยายแสดงครบทุกคอลัมน์จึงใช้ :nth-child ได้ตรงๆ — ตารางย่อนับเฉพาะคอลัมน์ที่แสดง (table-settings.js) */
#resultsSidebar.expanded #resultsTable tr > :nth-child(even) {
  background: var(--col-alt);
}

/* แถวที่ชี้อยู่ทับสีสลับคอลัมน์ (selector ต้องแรงกว่ากฎสีคอลัมน์) */
#resultsSidebar #resultsTable tbody tr:hover > td:nth-child(n) {
  background: var(--blue-50);
}

.empty-row td {
  color: var(--muted);
  text-align: center;
  white-space: normal;
}

.col-extra {
  display: none;
}

.results-sidebar.expanded .col-extra {
  display: table-cell;
}

.note {
  margin: 2px 2px 0;
  color: var(--muted);
  font-size: 0.74rem;
}

/* ตารางขยาย — modal กลางจอ (ยังเป็นการ์ดลอย) */
#tableBackdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(11, 28, 51, 0.5);
  backdrop-filter: blur(6px);
}

#tableBackdrop.visible {
  display: block;
}

.results-sidebar.expanded {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 51;
  width: min(92vw, 820px);
  max-height: 85vh;
  transform: translate(-50%, -50%);
}

body.table-modal-open {
  overflow: hidden;
}

body.table-modal-open .workspace {
  z-index: 60;
}

/* ==========================================================
   โซน B — Analysis (ไม่ลอย ใช้เส้นกรอบเดียว)
   ========================================================== */
.zone-analysis {
  display: flex;
  flex-direction: column;
  padding: 32px clamp(16px, 2.2vw, 32px) 40px;
  background: var(--bg);
}

.zone-analysis > * {
  width: 100%;
  max-width: 1480px;
  margin-left: auto;
  margin-right: auto;
}

.zone-analysis .panel-heading h2 {
  font-size: clamp(1.35rem, 2.4vw, 1.9rem);
  font-weight: 700;
}

.zone-analysis .subtitle {
  margin: 6px auto 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.effects-grid {
  flex: 1;
  margin-top: 20px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

.box-line {
  border: 1.5px solid var(--navy);
  background: var(--white);
}

.effects-controls {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.effects-controls select {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font-size: 0.88rem;
  cursor: pointer;
}

.effects-controls select:focus {
  border-color: var(--blue);
  outline: none;
}

.chart-card {
  position: relative;
  min-width: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.chart-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.chart-title h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.chart-title span {
  color: var(--muted);
  font-size: 0.76rem;
}

.effects-chart-card canvas {
  display: block;
  width: 100%;
  flex: 1;
  height: clamp(260px, 48dvh, 480px);
  margin-top: 12px;
}

.chart-empty {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 50%;
  margin: 0;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

.effects-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

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

.effects-legend-swatch {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
}

/* คำอธิบาย error bar ใต้กราฟ */
.effects-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

/* ปุ่มดาวน์โหลด PNG อยู่ล่างสุดของกล่องตัวเลือกกราฟ */
.effects-png {
  margin-top: auto;
  align-self: flex-start;
}

.effects-png:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.effects-png:disabled:hover {
  border-color: var(--line);
  color: var(--ink);
}

/* กล่องบอกค่าตอนชี้/แตะจุดในกราฟ */
.effects-chart-card canvas {
  touch-action: pan-y;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  max-width: 240px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--navy);
  color: var(--white);
  font-size: 0.76rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(11, 28, 51, 0.22);
}

.chart-tooltip strong {
  font-weight: 600;
}

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 290px minmax(0, 1fr) 300px;
    gap: 16px;
  }
}

/* tablet/มือถือ: โซน A สูงตามเนื้อหา — ฉากขึ้นก่อน ตามด้วยแผงปัจจัย แล้วตาราง */
@media (max-width: 900px) {
  .zone-experiment {
    height: auto;
    overflow: visible;
    padding-bottom: 18px;
    scroll-snap-align: none;
  }
  .workspace {
    grid-template-columns: 1fr;
    padding-bottom: 0;
  }
  .simulation-panel {
    order: -1;
  }
  .scene {
    flex: none;
    height: 360px;
  }
  .card-float {
    overflow: visible;
  }
  .controls-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
  }
  .controls-panel .panel-heading,
  .controls-panel fieldset,
  .controls-panel .primary-button,
  .controls-panel .warning-box,
  .controls-panel .constants-note {
    grid-column: 1 / -1;
  }
  .results-sidebar:not(.expanded) .table-scroll {
    max-height: 360px;
  }
  .scroll-hint {
    position: static;
    align-self: center;
    margin-top: 16px;
    transform: none;
  }
  .effects-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .zone-experiment {
    padding-top: 8px;
  }
  .workspace {
    gap: 10px;
  }
  .controls-panel {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
  }
  .panel-heading h2 {
    font-size: 0.98rem;
  }
  .param-group label,
  fieldset legend {
    margin-bottom: 2px;
    font-size: 0.82rem;
  }
  .range-hint {
    font-size: 0.7rem;
  }
  .param-row input[type='number'] {
    height: 28px;
    padding: 2px 6px;
  }
  .segmented {
    padding: 3px;
  }
  .segmented label span {
    padding: 5px 4px;
    font-size: 0.78rem;
  }
  .controls-panel .hint {
    display: none;
  }
  .primary-button {
    padding: 10px 14px;
    font-size: 0.95rem;
  }
  .scene {
    height: 150px;
    min-height: 0;
  }
  .scene-sun {
    top: 10px;
    width: 30px;
    height: 30px;
    box-shadow: 0 0 12px 3px rgba(255, 183, 3, 0.3);
  }
  .scene-cloud-a {
    top: 12px;
    transform: scale(0.6);
  }
  .scene-cloud-b {
    top: 30px;
    transform: scale(0.75);
  }
  .axis-label,
  .axis-y,
  .axis-x {
    font-size: 0.6rem;
  }
  .live-stats {
    margin-top: 6px;
    padding: 5px 12px;
    gap: 2px 12px;
    border-radius: 14px;
  }
  .live-stat {
    font-size: 0.74rem;
  }
  table {
    min-width: 520px;
  }
  .results-sidebar.expanded {
    width: 96vw;
    max-height: 92vh;
  }
}

/* ===================== ประวัติการทดลอง (history.js) ===================== */
.history-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--blue-50);
}
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.history-account {
  display: inline-flex;
  align-items: center;
}
.history-bar [hidden],
.history-note[hidden] {
  display: none !important;
}
.history-status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.history-continue {
  align-self: flex-start;
  padding: 4px 10px;
  border: 1px dashed var(--blue);
  border-radius: 999px;
  background: var(--white);
  color: var(--blue-600);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.history-continue[hidden] {
  display: none;
}
.hs-dialog {
  width: min(94vw, 520px);
  max-height: min(84vh, 640px);
  display: flex;
  flex-direction: column;
}
.hs-note {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
}
.hs-new {
  align-self: flex-start;
}
.hs-status {
  min-height: 1.2em;
  margin: 10px 0 6px;
  font-size: 0.88rem;
  color: var(--muted);
}
.hs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: grid;
  gap: 8px;
}
.hs-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
}
.hs-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 200px;
}
.hs-name {
  overflow-wrap: anywhere;
}
.hs-meta {
  font-size: 0.8rem;
  color: var(--muted);
}
.hs-badge {
  align-self: flex-start;
  margin-top: 2px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--blue-100);
  color: var(--blue-600);
  font-size: 0.75rem;
  font-weight: 600;
}
.hs-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.hs-actions .secondary-button,
.hs-actions .primary-button {
  padding: 6px 10px;
  font-size: 0.82rem;
}
.hs-danger {
  color: #b91c1c;
}
.hs-confirm {
  font-size: 0.85rem;
  font-weight: 600;
}
.hs-rename {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
