html, body { touch-action: pan-x pan-y; }
:root {
  --bg: #07101d;
  --panel: #0d1828;
  --panel-2: #101e31;
  --surface: #15243a;
  --surface-light: #edf3fb;
  --text: #f4f7fb;
  --muted: #9aaac0;
  --line: rgba(255,255,255,.09);
  --accent: #3f8cff;
  --accent-2: #68a8ff;
  --success: #45d483;
  --warning: #f0b64a;
  --danger: #ff6464;
  --shadow: 0 18px 60px rgba(0,0,0,.24);
  --radius: 18px;
  --font-size: 16px;
  --font-family: Roboto, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { font-size: var(--font-size); }
body {
  margin: 0;
  background: radial-gradient(circle at top, #13233b 0, var(--bg) 48%);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--font-size);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
select, input[type="text"], input[type="number"] { min-height: 44px; font-size: max(16px, var(--font-size)); }

.app-shell { min-height: 100vh; padding-bottom: 90px; }
.app-header { position: sticky; top: 0; z-index: 30; display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; background: rgba(7,16,29,.86); backdrop-filter: blur(18px); border-bottom: 1px solid var(--line); }
.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 42px; height: 42px; display: block; flex: 0 0 auto; border-radius: 12px; }
.brand-title { font-size: 1.02rem; font-weight: 800; letter-spacing: -.02em; }
.brand-subtitle { color: var(--muted); font-size: .78rem; margin-top: 1px; }
.header-actions { display: flex; gap: 8px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: rgba(255,255,255,.04); display: grid; place-items: center; }

.main-content { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 22px 0 40px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.hero-section { width: 100%; display: grid; grid-template-columns: 1.35fr .95fr; gap: 18px; }
.hero-copy, .mode-card { background: linear-gradient(160deg, rgba(20,34,56,.9), rgba(11,23,40,.95)); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); }
.eyebrow { display: inline-block; color: var(--accent-2); text-transform: uppercase; letter-spacing: .14em; font-size: .7rem; font-weight: 800; }
h1, h2, h3, p { margin: 0; }
h1 { margin-top: 9px; font-size: clamp(1.8rem, 3.8vw, 3.3rem); line-height: 1.03; max-width: 800px; letter-spacing: -.04em; }
.hero-copy p { margin-top: 15px; color: var(--muted); max-width: 740px; line-height: 1.6; }
.mode-card { display: grid; gap: 18px; align-content: center; }
.mode-row, .gravity-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mode-row > span { font-weight: 700; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.segment { border-radius: 9px; padding: 10px 14px; color: var(--muted); }
.segment.active { background: var(--accent); color: #fff; }
.gravity-row { align-items: flex-end; }
.gravity-row strong { font-size: 1.12rem; }
.gravity-actions { display: inline-flex; align-items: center; gap: 7px; }
.gravity-info-icon { width: 24px; height: 24px; flex: 0 0 auto; display: inline-grid; place-items: center; color: var(--accent-2); cursor: pointer; border-radius: 50%; }
.gravity-info-icon:hover { color: #8cc0ff; transform: translateY(-1px); }
.gravity-info-icon:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.gravity-info-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; }
.gravity-info-icon svg .fill { fill: currentColor; stroke: none; }
.mini-label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 3px; }
.well-note, .settings-info, .physics-note, .temporary-file-note { color: var(--muted); line-height: 1.55; padding: 12px 14px; background: rgba(255,255,255,.035); border-radius: 12px; border: 1px solid var(--line); }

.panel { width: 100%; background: linear-gradient(170deg, rgba(16,30,49,.97), rgba(10,20,34,.97)); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.panel-heading h2 { font-size: 1.06rem; }
.panel-heading p { margin-top: 6px; color: var(--muted); line-height: 1.45; font-size: .88rem; }
.status-pill, .precision-badge { white-space: nowrap; padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.06); border: 1px solid var(--line); font-size: .75rem; color: var(--muted); }
.status-pill.active { color: var(--success); border-color: rgba(69,212,131,.3); background: rgba(69,212,131,.08); }

.capture-actions, .results-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; margin-bottom: 16px; }
.primary-button, .secondary-button { min-height: 44px; padding: 11px 16px; border-radius: 12px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; transition: transform .15s ease, background .15s ease; }
.primary-button { background: var(--accent); color: white; }
.secondary-button { background: rgba(255,255,255,.045); color: var(--text); border-color: var(--line); }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button:disabled, .secondary-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.compact { min-height: 38px; padding: 8px 12px; font-size: .86rem; }
.tiny { min-height: 34px; padding: 6px 10px; font-size: .78rem; }
.full { width: 100%; }
.button-icon { font-size: 1.1rem; }
.zoom-controls { position: absolute; z-index: 4; display: inline-flex; gap: 6px; }
.video-zoom-controls { top: 10px; right: 10px; }
.timeline-zoom-controls { top: 10px; right: 10px; }
.zoom-button { min-height: 30px; padding: 4px 9px; font-size: .72rem; border-radius: 9px; background: rgba(8,18,31,.82); color: var(--text); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(10px); }
.zoom-button:hover { background: rgba(8,18,31,.82); }
.zoom-button:focus-visible { background: rgba(8,18,31,.82); outline: 2px solid var(--accent-2); outline-offset: 2px; }

.video-stage { position: relative; height: 300px; min-height: 300px; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #02070e; display: grid; place-items: center; }
.video-stage.has-video { min-height: 0; }
.video-viewport { width: 100%; height: 100%; overflow: hidden; display: grid; place-items: center; position: relative; background: #000; touch-action: none; }
.video-stage video { width: 100%; height: auto; display: block; background: #000; transform: translate3d(0,0,0) scale(1); transform-origin: center center; transition: transform .08s linear; cursor: default; touch-action: none; user-select: none; }
.video-hud { position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 6; display: grid; grid-template-columns: auto auto auto minmax(80px,1fr); align-items: center; gap: 7px; padding: 6px 8px; border-radius: 10px; background: rgba(8,18,31,.84); color: #fff; border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(10px); }
.video-hud-button { min-width: 30px; min-height: 28px; border: 0; border-radius: 7px; background: transparent; color: #fff; padding: 3px 6px; font: inherit; cursor: pointer; }
.video-hud-button:hover, .video-hud-button:focus-visible { background: rgba(255,255,255,.08); outline: none; }
.video-time { font-size: .72rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.video-progress { width: 100%; accent-color: var(--accent-2); touch-action: manipulation; }
.empty-video { text-align: center; color: var(--muted); padding: 30px; }
.empty-icon { width: 66px; height: 66px; margin: 0 auto 14px; border: 1px solid var(--line); border-radius: 18px; display: grid; place-items: center; font-size: 1.35rem; background: rgba(255,255,255,.04); color: var(--accent-2); }
.empty-title { color: var(--text); font-weight: 800; }
.empty-text { margin-top: 5px; }

.timeline-wrap { position: relative; height: 156px; border: 1px solid var(--line); border-radius: 16px; background: #060d18; overflow: hidden; }
#timelineCanvas { display: block; width: 100%; height: 154px; touch-action: none; }
.marker-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.marker-card { display: flex; gap: 10px; align-items: center; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.035); border: 1px solid var(--line); }
.marker-card.start { border-color: rgba(59,191,255,.3); }
.marker-card.end { border-color: rgba(255,101,125,.3); }
.marker-card.selected { box-shadow: 0 0 0 2px rgba(63,140,255,.28); background: rgba(63,140,255,.08); }
.marker-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.marker-card.start .marker-dot { background: #3bc0ff; }
.marker-card.end .marker-dot { background: #ff6c84; }
.marker-card strong { font-size: 1rem; }
.marker-actions { display: flex; gap: 7px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.precision-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: .84rem; }
.precision-badge.high { color: var(--success); border-color: rgba(69,212,131,.28); }
.precision-badge.medium { color: var(--warning); border-color: rgba(240,182,74,.28); }
.precision-badge.low { color: var(--danger); border-color: rgba(255,100,100,.28); }

.results-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.metric-card { position: relative; padding: 18px; background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 14px; min-height: 132px; display: flex; flex-direction: column; justify-content: center; }
.metric-card.highlight { border-color: rgba(63,140,255,.4); }
.metric-label { color: var(--muted); font-size: .82rem; }
.metric-card strong { margin-top: 7px; font-size: clamp(1.7rem, 4vw, 2.55rem); letter-spacing: -.04em; }
.metric-unit { color: var(--muted); margin-top: 2px; }
.physics-note { margin-top: 14px; font-size: .83rem; }
.temporary-file-note { margin-top: 12px; font-size: .78rem; }

.history-list { display: grid; gap: 10px; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; padding: 13px 14px; background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 12px; }
.history-main strong { display: block; }
.history-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 5px; color: var(--muted); font-size: .76rem; }
.history-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.empty-history { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }

.install-footer { padding: 18px 16px 26px; text-align: center; }
.install-link { appearance: none; border: 1px solid var(--line); background: rgba(128,128,128,.14); color: var(--text); padding: 7px 12px; border-radius: 9px; font: inherit; font-size: .78rem; cursor: pointer; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; transition: color .18s ease, background .18s ease, text-decoration-color .18s ease; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.install-link:hover, .install-link:focus-visible { color: var(--text); background: rgba(128,128,128,.22); text-decoration-color: currentColor; outline: none; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.62); display: grid; place-items: center; padding: 18px; }
/* La regla display del modal tiene prioridad sobre el estilo UA de [hidden].
   Forzamos display:none para que un modal oculto no bloquee la aplicación. */
.modal-backdrop[hidden] { display: none !important; }
.modal { width: min(860px, 100%); max-height: min(92vh, 900px); overflow: auto; background: #0a1423; border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.45); }
.modal-header { padding: 20px 20px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin-top: 5px; }
.settings-info { margin: 16px 20px 0; font-size: .82rem; }
.settings-grid { padding: 16px 20px; display: grid; gap: 12px; }
.setting-item { display: grid; gap: 8px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); }
.setting-item > span:first-child, .settings-section-title { font-weight: 750; }

.setting-item select, .setting-item input[type="range"] { width: 100%; }
/* Desplegables de configuración: acabado glassmorphism sin cambiar la lógica de los controles. */
.settings-grid .setting-item select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 46px;
  padding: 10px 42px 10px 14px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
  color: var(--text);
  background-color: rgba(255,255,255,.055);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2368a8ff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 15px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 8px 24px rgba(0,0,0,.10);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
  color-scheme: dark;
}
.settings-grid .setting-item select:hover {
  border-color: rgba(104,168,255,.42);
  background-color: rgba(255,255,255,.075);
}
.settings-grid .setting-item select:focus-visible {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(104,168,255,.18), inset 0 1px 0 rgba(255,255,255,.08);
}
.settings-grid .setting-item select option {
  color: var(--text);
  background: #0d1828;
}
body.light .settings-grid .setting-item select {
  border-color: rgba(31,48,71,.16);
  background-color: rgba(255,255,255,.62);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.85), 0 8px 24px rgba(33,52,79,.08);
  color-scheme: light;
}
body.light .settings-grid .setting-item select:hover {
  background-color: rgba(255,255,255,.82);
  border-color: rgba(63,140,255,.35);
}
body.light .settings-grid .setting-item select option {
  color: var(--text);
  background: #ffffff;
}
.range-item input { accent-color: var(--accent); }
.theme-buttons { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
.theme-buttons button { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.035); color: var(--text); }
.theme-buttons button.active { border-color: var(--accent); background: rgba(63,140,255,.14); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row input[type="checkbox"] { width: 46px; height: 26px; appearance: none; background: rgba(255,255,255,.12); border-radius: 999px; position: relative; cursor: pointer; }
.toggle-row input[type="checkbox"]::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: white; transition: transform .2s ease; }
.toggle-row input[type="checkbox"]:checked { background: var(--accent); }
.toggle-row input[type="checkbox"]:checked::after { transform: translateX(20px); }
.settings-section-title { color: var(--accent-2); margin-top: 6px; padding: 2px 2px; }
.settings-footer { border-top: 1px solid var(--line); padding: 16px 20px 22px; }
.app-credit { text-align: center; margin-top: 13px; color: #718197; font-size: .72rem; }
.app-credit a { color: inherit; text-decoration: underline; }
.help-modal { max-width: 760px; }
.summary-modal { max-width: 980px; }
.summary-preview-wrap { padding: 20px; }
.gravity-info-modal { max-width: 650px; }
.gravity-info-body { padding: 20px; color: var(--muted); line-height: 1.65; }
.summary-preview-wrap img { width: 100%; height: auto; display: block; border-radius: 14px; border: 1px solid var(--line); background: #000; }
.tutorial-content { padding: 20px; display: grid; gap: 12px; }
.tutorial-step { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.025); }
.tutorial-step strong { display: block; margin-bottom: 5px; }
.tutorial-step p { color: var(--muted); line-height: 1.55; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 11px 15px; border-radius: 999px; background: #0f1f35; color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); transition: opacity .2s ease, transform .2s ease; max-width: calc(100% - 40px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.light { --bg: #f4f7fb; --panel: #ffffff; --panel-2: #ffffff; --surface: #eef3f9; --text: #152037; --muted: #5f6e83; --line: rgba(31,48,71,.13); --shadow: 0 18px 55px rgba(33,52,79,.12); background: linear-gradient(#edf3fb, #f7f9fc); }
body.light .app-header { background: rgba(247,249,252,.84); }
body.light .hero-copy, body.light .mode-card, body.light .panel, body.light .modal { background: #fff; }
body.high-contrast { --line: rgba(255,255,255,.28); --muted: #cdd7e4; }

@media (max-width: 980px) {
  .hero-section { grid-template-columns: 1fr; }
  .results-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .main-content { width: min(100% - 18px, 1500px); padding-top: 12px; }
  .app-header { padding: 10px 12px; }
  .brand-title { font-size: .94rem; }
  .brand-subtitle { font-size: .7rem; }
  .brand-mark { width: 38px; height: 38px; }
  .hero-copy, .mode-card, .panel { padding: 16px; }
  h1 { font-size: 2.05rem; }
  .gravity-row, .panel-heading { align-items: stretch; flex-direction: column; }
  .mode-row { align-items: stretch; flex-direction: column; }
  .segmented-control { width: 100%; }
  .capture-actions .primary-button { flex: 1; }
  .video-stage { height: 300px; min-height: 300px; }
  .timeline-wrap { height: 134px; }
  #timelineCanvas { height: 132px; }
  .marker-controls { grid-template-columns: 1fr; }
  .marker-actions { width: 100%; margin-left: 0; justify-content: stretch; }
  .marker-actions .tiny { flex: 1 1 0; min-width: 0; }
  .history-item { grid-template-columns: 1fr; }
  .history-actions { justify-content: flex-end; }
  .theme-buttons { grid-template-columns: 1fr; }
}


.clear-history-actions { display:flex; gap:10px; justify-content:flex-end; margin-top:20px; padding:0 20px 20px; flex-wrap:wrap; }
@media (max-width: 520px) { .clear-history-actions { flex-direction:column-reverse; } .clear-history-actions button { width:100%; } }
