:root {
  --bg: #14161a;
  --panel: #1b1e24;
  --panel-2: #22262e;
  --border: #2e333c;
  --text: #eef0f3;
  --text-dim: #9aa1ad;
  --accent: #f5a623;
  --accent-dim: #7a5619;
  --danger: #e0574f;
  --mono: "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.app-header {
  text-align: center;
  margin-bottom: 24px;
}

.app-header h1 {
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.slate { color: var(--accent); }

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.segmented {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.segmented.small { padding: 2px; gap: 2px; }

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
}

.segmented.small .seg-btn {
  padding: 6px 14px;
  font-size: 13px;
}

.seg-sub {
  font-size: 10px;
  font-weight: 500;
  opacity: 0.7;
  font-family: var(--mono);
}

.seg-btn.active {
  background: var(--accent);
  color: #201400;
}

.seg-btn:not(.active):hover {
  color: var(--text);
  background: #2a2f38;
}

.timecode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field select {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  min-width: 200px;
}

.tool-intro { margin-bottom: 16px; }

.rows-section { margin-bottom: 20px; }

.rows-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 8px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Widths/gaps below mirror .sign-btn, .row-fields, and .remove-btn exactly
   so each label sits directly above its corresponding input column. */
.col-sign { width: 36px; flex-shrink: 0; }
.col-fields {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.col-remove { width: 30px; flex-shrink: 0; }

.tc-label {
  width: 44px;
  text-align: center;
}
.tc-label.hh { width: 54px; }

.tc-sep.ghost { visibility: hidden; }

.rows-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
}

.sign-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sign-btn.negative {
  color: var(--danger);
  border-color: var(--danger);
}

.sign-btn.positive {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.row-fields {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.tc-input {
  width: 44px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
  padding: 8px 0;
}

.tc-input.hh { width: 54px; }

.tc-input:focus {
  outline: none;
  border-color: var(--accent);
}

.tc-sep {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
}

.remove-btn {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(224, 87, 79, 0.08);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.add-row-btn {
  border-style: dashed;
  color: var(--accent);
  border-color: var(--accent-dim);
}

.add-row-btn:hover {
  background: rgba(245, 166, 35, 0.08);
}

.result {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  text-align: center;
  margin-bottom: 16px;
}

.result-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 4px;
}

.result-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 700;
}

.result-value {
  font-family: var(--mono);
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
}

.result-value.negative { color: var(--danger); }

.result-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.copy-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
}

.result-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.actions { display: flex; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.app-footer {
  text-align: center;
  margin-top: 18px;
}

.app-footer p {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  max-width: 480px;
  margin: 0 auto;
}

/* Mode toggle: stretch to full width so 3 tabs share space evenly */
#modeToggle { display: flex; width: 100%; }
#modeToggle .seg-btn { flex: 1; }

/* ---------- Aspect ratio tool ---------- */

.aspect-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 20px;
}

.aspect-controls .field select { min-width: 260px; }

.ratio-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.num-input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
  padding: 9px 12px;
  width: 100%;
  text-align: center;
}

.num-input.sm { width: 68px; }

.num-input:focus {
  outline: none;
  border-color: var(--accent);
}

.dim-section { margin-bottom: 20px; }

.dim-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
}

.dim-field { flex: 1; }

.dim-x {
  color: var(--text-dim);
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 9px;
}

.letterbox {
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.tool-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.tool-desc {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
  cursor: pointer;
  user-select: none;
}

.checkbox-field input { accent-color: var(--accent); width: 16px; height: 16px; }

.lb-preview-wrap {
  display: flex;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}

#lbPreview {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
}

.lb-info {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-bottom: 14px;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .app { padding: 20px 12px 40px; }
  .result-value { font-size: 28px; }
  .tc-input { width: 36px; font-size: 14px; padding: 7px 0; }
  .tc-input.hh { width: 42px; }
  .tc-label { width: 36px; }
  .tc-label.hh { width: 42px; }
  .field select { min-width: 0; width: 100%; }
  .aspect-controls .field select { min-width: 0; }
  #modeToggle .seg-btn { padding: 8px 6px; }
}
