:root {
  --bg: #edeae4;
  --surface: #fafaf7;
  --card: #ffffff;
  --border: #e8e4de;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --faint: #9a948c;
  --accent: #ff6b1a;
  --accent-soft: #f1ece4;
  --accent-tint: #fff1e6;
  --accent-tint-border: #fad9bf;
  --green: #1f8a5b;
  --amber: #b26b00;
  --red: #c0392b;
  --danger-border: #e7c6be;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 16px;
}

.ms {
  font-family: 'Material Symbols Outlined' !important;
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-feature-settings: 'liga';
  vertical-align: middle;
}

input[type='range'] {
  accent-color: var(--accent);
  height: 4px;
  width: 100%;
}

/* ---- app shell ---- */

.app {
  max-width: 440px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.06);
}

.app-header {
  padding: 18px 20px 12px;
  flex: none;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.app-header .sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---- tabs (segmented) ---- */

.tab-bar {
  margin: 0 16px 12px;
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 4px;
  display: flex;
  gap: 4px;
  flex: none;
}

.tab-btn {
  flex: 1;
  border: none;
  cursor: pointer;
  padding: 10px 0;
  border-radius: 11px;
  font: 600 13px 'DM Sans', system-ui;
  color: var(--muted);
  background: transparent;
  transition: all 0.18s ease;
}

.tab-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.09);
}

.tab-panel {
  flex: 1;
  overflow: auto;
  padding: 0 16px 28px;
}

.tab-content {
  display: none;
  flex-direction: column;
}

.tab-content.active {
  display: flex;
}

/* ---- shared cards / fields ---- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-top: 12px;
}

.card-k {
  font: 600 10.5px 'DM Sans';
  color: var(--faint);
  letter-spacing: 0.09em;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font: 500 12px 'DM Sans';
  color: var(--muted);
  margin-bottom: 11px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-row {
  display: flex;
  gap: 9px;
  align-items: flex-end;
  margin-bottom: 11px;
}

.swap-btn {
  flex: none;
  width: 42px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
}

.swap-btn .ms {
  font-size: 20px;
}

.swap-btn:active {
  background: var(--accent-soft);
  color: var(--accent);
}

.field-row .field {
  flex: 1;
  margin-bottom: 0;
}

.field input[type='number'],
.field input[type='text'],
.field select {
  font: 500 14px 'DM Sans';
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  min-height: 44px;
  width: 100%;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239A948C' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 38px;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
}

.aspect {
  font: 500 11.5px 'DM Sans';
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  margin: -4px 0 11px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font: 500 13px 'DM Sans';
  color: var(--ink);
  margin-bottom: 11px;
  cursor: pointer;
}

.check-row input[type='checkbox'] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
  cursor: pointer;
}

.json-preview {
  background: #faf7f2;
  border-radius: 10px;
  padding: 9px 11px;
  font: 400 10.5px/1.5 ui-monospace, Menlo, monospace;
  color: #8a8278;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- buttons ---- */

.btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 13px 0;
  font: 600 15px 'DM Sans';
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 20px rgba(255, 107, 26, 0.28);
}

.btn-accent:disabled {
  box-shadow: none;
}

.btn-soft {
  background: var(--accent-soft);
  color: var(--ink);
  width: auto;
  padding: 11px 18px;
  font-size: 14px;
  min-height: 42px;
}

.btn-outline-danger {
  background: #fff;
  border: 1px solid var(--danger-border);
  color: var(--red);
  font-size: 14px;
  margin-top: 14px;
}

.btn .ms {
  font-size: 19px;
}

/* ---- preview ---- */

.preview-wrap {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  background: linear-gradient(155deg, #4a4640 0%, #17140f 100%);
  margin-top: 4px;
}

video.preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.preview-badges {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.badge {
  color: #fff;
  font: 600 11px 'DM Sans';
  padding: 5px 10px;
  border-radius: 999px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.badge-res {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.badge-res .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3fbf7f;
}

.badge-rec {
  background: rgba(192, 57, 43, 0.94);
  animation: recpulse 1.3s ease-in-out infinite;
}

.badge-rec .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
}

@keyframes recpulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.preview-controls {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 34px;
}

.shutter {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255, 255, 255, 0.55);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.shutter .ms {
  font-size: 24px;
  color: var(--ink);
}

.recbtn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 2px solid rgba(255, 255, 255, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.recbtn .rec-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
  display: block;
}

.recbtn.on .rec-dot {
  width: 15px;
  height: 15px;
  border-radius: 3px;
}

.shutter:disabled,
.recbtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(155deg, #4a4640 0%, #17140f 100%);
}

.preview-empty .ms {
  font-size: 44px;
  color: rgba(255, 255, 255, 0.55);
}

.preview-empty span:last-child {
  font: 500 14px 'DM Sans';
  color: rgba(255, 255, 255, 0.7);
}

/* ---- stats ---- */

.stat-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.stat {
  flex: 1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 11px;
}

.stat-k {
  font: 600 9.5px 'DM Sans';
  color: var(--faint);
  letter-spacing: 0.08em;
}

.stat-v {
  font: 500 13px 'DM Sans';
  color: var(--ink);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ---- last recording ---- */

.lastrec {
  display: flex;
  gap: 12px;
  align-items: center;
}

.lastrec-icon {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  background: linear-gradient(150deg, #4a4640, #17140f);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex: none;
}

.lastrec-meta {
  flex: 1;
  min-width: 0;
}

.lastrec-title {
  font: 600 13px 'DM Sans';
  color: var(--ink);
}

.lastrec-sub {
  font: 400 12px 'DM Sans';
  color: var(--muted);
}

.lastrec-dl {
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
}

.lastrec-dl .ms {
  font-size: 22px;
}

/* ---- info card (slot B) ---- */

.info {
  background: var(--accent-tint);
  border-color: var(--accent-tint-border);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.info .ms {
  font-size: 20px;
  color: var(--accent);
  flex: none;
}

.info span:last-child {
  font: 400 12.5px/1.5 'DM Sans';
  color: #7a5230;
}

.info b {
  font-weight: 600;
}

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

.collapse {
  padding: 0;
  overflow: hidden;
}

.collapse-head {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.collapse-head .head-l {
  display: flex;
  align-items: center;
  gap: 9px;
  font: 600 14px 'DM Sans';
  color: var(--ink);
}

.collapse-head .head-l .ms {
  font-size: 20px;
  color: var(--accent);
}

.collapse-head .chevron {
  font-size: 22px;
  color: var(--faint);
}

.collapse-body {
  padding: 0 14px 16px;
}

.ctrl {
  margin-bottom: 14px;
}

.ctrl.disabled {
  opacity: 0.55;
}

.ctrl-label {
  font: 500 13px 'DM Sans';
  color: var(--ink);
  margin-bottom: 7px;
}

.ctrl-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
}

.ctrl-top span:first-child {
  font: 500 13px 'DM Sans';
  color: var(--ink);
}

.ctrl-val {
  font: 600 12px 'DM Sans';
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.seg {
  display: flex;
  gap: 5px;
  background: var(--accent-soft);
  padding: 3px;
  border-radius: 10px;
}

.seg-btn {
  flex: 1;
  text-align: center;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  font: 600 12px 'DM Sans';
  padding: 8px 0;
  border-radius: 8px;
}

.seg-btn.on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}

.ns-badge {
  background: var(--accent-soft);
  color: var(--muted);
  font: 600 9.5px 'DM Sans';
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.ctrl-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0 14px;
}

.res-grid {
  display: flex;
  gap: 9px;
  align-items: flex-end;
  margin-bottom: 10px;
}

.res-grid .field.sm {
  flex: 1;
  margin-bottom: 0;
}

.res-grid .swap-btn {
  width: 38px;
  min-height: 40px;
  margin-bottom: 0;
}

.field.sm {
  font-size: 11px;
}

.field.sm input,
.field.sm select {
  padding: 9px 11px;
  min-height: 40px;
  font-size: 13px;
}

.res-actions {
  display: flex;
  gap: 9px;
  align-items: flex-end;
}

.res-actions .field.sm.mode {
  flex: 1;
  margin-bottom: 0;
}

/* ---- log tab ---- */

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 12px;
}

.log-count {
  font: 400 13px 'DM Sans';
  color: var(--muted);
}

.log-count b {
  color: var(--ink);
  font-weight: 600;
}

.log-actions {
  display: flex;
  gap: 8px;
}

.log-btn {
  border: none;
  border-radius: 9px;
  padding: 8px 12px;
  font: 600 12px 'DM Sans';
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.log-btn .ms {
  font-size: 16px;
}

.log-btn.accent {
  background: var(--accent);
  color: #fff;
}

.log-btn.ghost {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
}

.log-search {
  position: relative;
  margin-bottom: 12px;
}

.log-search .ms {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--faint);
}

.log-search input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: 11px;
  font: 400 13px 'DM Sans';
  background: #fff;
  color: var(--ink);
  outline: none;
  min-height: 42px;
}

.log-search input:focus {
  border-color: var(--accent);
}

.log-empty {
  text-align: center;
  color: var(--faint);
  font: 400 13px 'DM Sans';
  padding: 30px 0;
}

.log-row {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}

.log-row > summary {
  cursor: pointer;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  list-style: none;
}

.log-row > summary::-webkit-details-marker {
  display: none;
}

.log-ic {
  font-size: 19px;
}

.log-main {
  flex: 1;
  min-width: 0;
}

.log-line1 {
  display: flex;
  gap: 7px;
  align-items: center;
}

.log-cmd {
  font: 600 13px 'DM Sans';
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-slot {
  font: 600 9.5px 'DM Sans';
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  flex: none;
}

.log-line2 {
  font: 400 11px 'DM Sans';
  color: var(--faint);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

.log-outcome {
  font: 600 11px 'DM Sans';
  text-align: right;
  max-width: 100px;
  flex: none;
}

.log-detail {
  padding: 2px 12px 12px;
  font: 400 11px/1.55 ui-monospace, Menlo, monospace;
  color: #5a5248;
  background: #faf7f2;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- capture modal (bottom sheet) ---- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 10, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.18s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet {
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  width: 100%;
  max-width: 440px;
  padding: 16px 18px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.22);
  animation: slideup 0.22s ease;
  max-height: 92vh;
  overflow: auto;
}

@keyframes slideup {
  from {
    transform: translateY(30px);
  }
}

.sheet-grip {
  width: 42px;
  height: 5px;
  border-radius: 99px;
  background: #ddd6cc;
  margin: 0 auto 16px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-head span {
  font: 600 17px 'DM Sans';
  color: var(--ink);
}

.sheet-close {
  background: var(--accent-soft);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-close .ms {
  font-size: 19px;
  color: var(--muted);
}

.sheet-photo {
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  background: #000;
  margin-bottom: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.json-box {
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
  margin-bottom: 16px;
}

.json-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: #f4f0ea;
  border-bottom: 1px solid var(--border);
}

.json-box-head .lbl {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 600 10px 'DM Sans';
  color: #8a8278;
  letter-spacing: 0.08em;
}

.json-box-head .lbl .ms {
  font-size: 15px;
  color: var(--faint);
}

.copy-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font: 600 10.5px 'DM Sans';
  color: var(--muted);
}

.copy-btn .ms {
  font-size: 14px;
}

.json-code {
  background: #fcfaf6;
  padding: 12px 14px;
  font: 400 11.5px/1.85 ui-monospace, Menlo, monospace;
  overflow: auto;
  white-space: pre;
  color: #b8af9f;
}

.json-code .j-key {
  color: #a15c2b;
}

.json-code .j-str {
  color: #2c8a5b;
}

.json-code .j-num {
  color: #c0621a;
}

.json-code .j-bool,
.json-code .j-null {
  color: #7a5230;
}

.sheet-actions {
  display: flex;
  gap: 10px;
}

.sheet-actions .btn {
  flex: 1;
}

.sheet-actions .btn.secondary {
  flex: none;
  width: auto;
  background: var(--accent-soft);
  color: var(--muted);
  padding: 13px 20px;
}

/* ---- error toast ---- */

.toast-root {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: 100%;
  max-width: 412px;
  background: #fff;
  border: 1px solid var(--danger-border);
  border-left: 4px solid var(--red);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  animation: toastin 0.22s ease;
}

.toast.out {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast > .ms {
  color: var(--red);
  font-size: 20px;
  flex: none;
}

.toast-body {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font: 600 13px 'DM Sans';
  color: var(--ink);
}

.toast-msg {
  font: 400 12px/1.4 'DM Sans';
  color: var(--muted);
  word-break: break-word;
  margin-top: 1px;
}

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--faint);
  flex: none;
  padding: 0;
  display: flex;
}

.toast-close .ms {
  font-size: 18px;
}

@keyframes toastin {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
}
