:root {
  --bg: #f2efe9;
  --ink: #1d2a3a;
  --accent: #b34a2c;
  --panel: #fff9f0;
  --line: #d7c9b8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  background: radial-gradient(circle at top right, #f6d6a5, var(--bg) 40%);
  color: var(--ink);
}

.page {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  box-sizing: border-box;
}

.hero h1 {
  margin-bottom: 0.25rem;
  letter-spacing: 0.03em;
}

.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.hero-row h1 {
  margin: 0;
}

.help-btn {
  background: #2f5e84;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  font-size: 0.88rem;
}

.help-btn:hover:enabled {
  background: #244969;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.global-notice {
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.9rem;
  border: 1px solid #d5c7b2;
  background: #fff7ea;
  color: #553f28;
  font-size: 0.92rem;
  line-height: 1.35;
}

.global-notice.is-error {
  border-color: #d6b3a8;
  background: #fff2ef;
  color: #7a3020;
}

.global-notice.is-info {
  border-color: #b8ccdc;
  background: #eff7ff;
  color: #254f71;
}

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(25, 30, 38, 0.44);
  z-index: 80;
}

.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(460px, 92vw);
  height: 100vh;
  background: #fff9f1;
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 28px rgba(30, 34, 40, 0.22);
  transform: translateX(102%);
  transition: transform 220ms ease;
  z-index: 90;
  display: grid;
  grid-template-rows: auto 1fr;
}

.help-drawer.is-open {
  transform: translateX(0);
}

.help-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f8efe2);
}

.help-drawer__header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.help-close-btn {
  background: #6d7782;
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
}

.help-close-btn:hover:enabled {
  background: #56606a;
}

.help-drawer__content {
  overflow-y: auto;
  padding: 0.9rem 1rem 1.2rem;
  display: grid;
  gap: 0.75rem;
}

.help-section {
  border: 1px solid #dfd1bf;
  border-radius: 9px;
  background: #fffdf9;
  padding: 0.7rem 0.8rem;
}

.help-section h3 {
  margin: 0 0 0.45rem;
  color: #9f4025;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.help-section p {
  margin: 0.15rem 0 0.45rem;
  font-size: 0.92rem;
}

.help-section ul,
.help-section ol {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  line-height: 1.35;
}

.section-helper,
.local-help {
  font-size: 0.82rem;
  color: #665d54;
  background: #fffdf8;
  border: 1px dashed #dbc9b5;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  line-height: 1.35;
}

.section-helper {
  margin-bottom: 0.6rem;
}

.local-help {
  margin-bottom: 0.35rem;
}

.controls {
  display: grid;
  gap: 0.75rem;
}

.field-row {
  display: grid;
  gap: 0.3rem;
}

label {
  font-weight: 600;
}

.help-inline-btn {
  border: 1px solid #bfae9a;
  border-radius: 999px;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  margin-left: 0.25rem;
  background: #f3ebe0;
  color: #4a5966;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}

h2 .help-inline-btn,
h3 .help-inline-btn,
.section-helper .help-inline-btn,
.local-help .help-inline-btn,
label .help-inline-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.help-inline-btn:hover:enabled {
  background: #e8d9c8;
  color: #2a3a48;
}

input {
  padding: 0.6rem 0.7rem;
  border: 1px solid #b8ad9f;
  border-radius: 8px;
  font-size: 1rem;
}

.actions {
  margin-top: 0.25rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.output-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.output-grid > div {
  min-width: 0;
  width: 100%;
}

.scrollbox {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  height: clamp(80px, 12vh, 160px);
  overflow-y: auto;
  padding: 0.7rem;
  font-family: "Consolas", "Liberation Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.table-scroll {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  height: clamp(200px, 45vh, 520px);
  overflow: auto;
  width: 100%;
  min-width: 0;
}

.obs-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
  font-family: "Consolas", "Liberation Mono", monospace;
  font-size: 0.82rem;
}

.obs-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7eee3;
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.45rem 0.5rem;
}

.obs-table td {
  border-bottom: 1px solid #eee3d5;
  vertical-align: top;
  padding: 0.4rem 0.5rem;
}

.obs-table tbody tr:nth-child(odd) {
  background: #fffdf9;
}

.table-empty {
  padding: 0.7rem;
  color: #6d655c;
  font-family: "Consolas", "Liberation Mono", monospace;
  font-size: 0.9rem;
}

.selected-panel {
  display: grid;
  gap: 0.4rem;
}

.selected-id-row {
  display: flex;
  gap: 0.5rem;
}

.selected-id-row input[type="text"] {
  flex: 1;
  font-family: "Consolas", "Liberation Mono", monospace;
  font-size: 0.95rem;
  background: #fffdf9;
  color: var(--ink);
  cursor: default;
}

.obs-table tbody tr {
  cursor: pointer;
}

.obs-table tbody tr:hover {
  background: #fde8d8 !important;
}

.obs-table tbody tr.row-selected {
  background: #f5c9a8 !important;
  outline: 2px solid var(--accent);
}

.lrr-panel h2 {
  margin-top: 0;
}

.lrr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.lrr-group {
  background: #fdf6ec;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  display: grid;
  gap: 0.35rem;
  align-content: start;
  min-width: 0;
}

.lrr-group h3 {
  margin: 0 0 0.25rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.lrr-group--full {
  grid-column: 1 / -1;
}

.lrr-geometry-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
}

.lrr-viz-panel {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  background: #fffdf9;
  display: grid;
  gap: 0.45rem;
  align-content: start;
}

.lrr-sim-panel {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  background: #fffaf3;
  display: grid;
  gap: 0.45rem;
  align-content: start;
}

.lrr-viz-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

#lrrAxisPreview {
  width: 100%;
  height: auto;
  border: 1px solid #cabba8;
  border-radius: 6px;
  background: radial-gradient(circle at 25% 15%, #fff, #f2ebdf 70%);
  cursor: grab;
}

#lrrSimPreview {
  width: 100%;
  height: auto;
  border: 1px solid #cabba8;
  border-radius: 6px;
  background: radial-gradient(circle at 20% 20%, #fff, #eee4d7 72%);
}

#lrrAxisPreview:active {
  cursor: grabbing;
}

.lrr-viz-controls {
  display: grid;
  gap: 0.25rem;
}

.lrr-viz-controls input[type="range"] {
  width: 100%;
}

.lrr-sim-controls {
  display: grid;
  grid-template-columns: auto auto auto 84px auto 78px auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

#lrrSimResolutionS,
#lrrSimPeriods {
  min-width: 0;
}

.sim-btn {
  background: #2f5e84;
  padding: 0.42rem 0.8rem;
  font-size: 0.82rem;
  border-radius: 7px;
}

.sim-btn:hover:enabled {
  background: #244969;
}

.sim-btn--record {
  background: #8f3a2d;
}

.sim-btn--record:hover:enabled {
  background: #712e24;
}

.lrr-viz-hint {
  font-size: 0.73rem;
}

#lrrRbCount,
#lrrNormBCount {
  font-weight: 400;
  font-size: 0.75rem;
  color: #7a6d62;
  transition: color 0.2s;
}

.error-hint {
  font-weight: 600;
  font-size: 0.7rem;
  color: #c45a4a;
  margin-left: 0.4rem;
  display: none;
}

.error-hint.show {
  display: inline;
}

#lrrRbCount.mismatch,
#lrrNormBCount.mismatch {
  color: #c45a4a;
  font-weight: 600;
}

#lrrRb.geo-invalid,
#lrrNormB.geo-invalid {
  border-color: #c45a4a !important;
  background: #fdf3f1;
}

.vec3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
}

.vec3 input {
  min-width: 0;
  text-align: center;
}

.hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: #7a6d62;
}

.lrr-group input,
.lrr-group select {
  padding: 0.35rem 0.5rem;
  border: 1px solid #b8ad9f;
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
  width: 100%;
  box-sizing: border-box;
}

.lrr-group textarea {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid #b8ad9f;
  border-radius: 6px;
  font-family: "Consolas", "Liberation Mono", monospace;
  font-size: 0.8rem;
  resize: vertical;
  box-sizing: border-box;
  min-width: 0;
}

.lrr-actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.lrr-calc-progress {
  margin-bottom: 1rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbf5ec;
  display: grid;
  gap: 0.35rem;
}

.lrr-calc-progress__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 0.88rem;
}

.lrr-calc-progress__track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #e8d7c2;
}

.lrr-calc-progress__bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #b34a2c, #d97a45);
  transition: width 0.25s ease;
}

.lrr-calc-progress.is-busy .lrr-calc-progress__bar {
  background: linear-gradient(90deg, #b34a2c, #e3a15c, #b34a2c);
  background-size: 200% 100%;
  animation: lrr-progress-shimmer 1.4s linear infinite;
}

@keyframes lrr-progress-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: 0 0;
  }
}

.calc-btn {
  padding: 0.8rem 1.5rem;
  font-size: 1.05rem;
  background: linear-gradient(135deg, var(--accent), #d45e3a);
  font-weight: 700;
}

.calc-btn:disabled::after {
  content: " ⏳";
}

.lrr-metrics {
  background: #f9f4ef;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  font-size: 0.9rem;
}

.metric-item {
  display: grid;
  gap: 0.15rem;
}

.metric-label {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.metric-value {
  font-family: "Consolas", "Liberation Mono", monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: #1d2a3a;
}

.image-gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  max-width: 980px;
  margin: 0 auto;
}

.gallery-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s, box-shadow 0.2s;
}

.gallery-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.gallery-image {
  width: 100%;
  height: auto;
  display: block;
  background: #f5f0ea;
}

.gallery-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
}

.lrr-results-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
}

.download-btn {
  background: #2e6f5f;
  padding: 0.75rem 1.2rem;
  font-size: 0.95rem;
}

.download-btn:hover:enabled {
  background: #24594c;
}

@media (max-width: 800px) {
  .hero-row {
    align-items: flex-start;
  }

  .output-grid {
    grid-template-columns: 1fr;
  }

  .scrollbox {
    height: clamp(60px, 10vh, 120px);
  }

  .table-scroll {
    height: clamp(160px, 38vh, 360px);
  }

  .lrr-geometry-cols {
    grid-template-columns: 1fr;
  }

  .lrr-sim-controls {
    grid-template-columns: 1fr 1fr;
  }

  .help-drawer {
    width: 100vw;
  }
}
