/* Estilo basado en cartasnauticasdigital.com: fondo marino oscuro, acentos
   aguamarina/azul, tarjetas tipo cristal y tipografías Sora + Manrope. */

@font-face {
  font-family: 'Manrope'; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url('../assets/fonts/manrope-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Sora'; font-style: normal; font-weight: 600 700; font-display: swap;
  src: url('../assets/fonts/sora-latin.woff2') format('woff2');
}

:root {
  --bg: #050d18;
  --bg-2: #0a1726;
  --bg-3: #0f1e35;
  --card: rgba(255, 255, 255, .045);
  --card-b: rgba(255, 255, 255, .09);
  --card-h: rgba(255, 255, 255, .08);
  --tx: #eaf2f8;
  --mut: #93a7b8;
  --aqua: #2fd3d0;
  --sky: #3d8bf0;
  --coral: #ff6a3d;
  --grad: linear-gradient(100deg, var(--aqua) 0%, var(--sky) 100%);
  --pos-blue: #2f86d6;
  --toolbar-w: 84px;
  --panel-w: 320px;
  --r: 14px;
  --font: 'Manrope', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: 'Sora', 'Manrope', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
html, body {
  /* Sin zoom del navegador ni selección de texto al mantener pulsado (iPad/iPhone) */
  touch-action: pan-x pan-y;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, select { -webkit-user-select: text; user-select: text; }
body {
  font-family: var(--font);
  color: var(--tx);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(10, 22, 40, .96);
  border-bottom: 1px solid rgba(56, 189, 248, .15);
  min-height: 62px; position: relative; z-index: 15;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-logo {
  width: 44px; height: 44px; object-fit: contain; flex: none;
  border-radius: 12px; background: #000;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, .25), 0 6px 18px -6px rgba(47, 211, 208, .45);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.brand-text strong { font-family: var(--font-head); font-size: 17px; letter-spacing: -.02em; font-weight: 700; }
.brand-text small { color: var(--mut); font-size: 12px; }

.exam-select {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px 5px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--card-b);
}
.label { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--aqua); }
.exam-select select {
  background: var(--bg-3); color: var(--tx); border: 1px solid var(--card-b); border-radius: 999px;
  padding: 6px 12px; max-width: 260px; font-weight: 600; font-size: 14px;
}
.spacer { flex: 1; }
.actions { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; border-radius: 12px; color: var(--tx);
  transition: background .15s, border-color .15s, color .15s;
}
.icon-btn:hover { background: var(--card-h); border-color: var(--card-b); color: var(--aqua); }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; border-color: transparent; color: var(--tx); }
.icon-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { color: var(--aqua); background: rgba(47, 211, 208, .1); border-color: rgba(47, 211, 208, .3); }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: 48px; z-index: 30; min-width: 240px;
  background: var(--bg-3); border: 1px solid rgba(56, 189, 248, .2); border-radius: 14px; padding: 6px;
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, .6);
}
.menu-list button {
  display: block; width: 100%; text-align: left; padding: 10px 12px; font-weight: 500;
  background: none; border: 0; border-radius: 9px;
}
.menu-list button:hover { background: rgba(56, 189, 248, .12); color: var(--aqua); }

/* ---------- Zona principal ---------- */
.main { flex: 1; display: flex; min-height: 0; position: relative; }

.toolbar {
  width: var(--toolbar-w); background: var(--bg-2); border-right: 1px solid var(--card-b);
  display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; overflow-y: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar button {
  display: flex; flex-direction: column; align-items: center; gap: 3px; flex: none;
  padding: 8px 2px 7px; border: 1px solid transparent; border-radius: 14px; background: none;
  font-size: 11px; font-weight: 600; color: var(--mut);
  transition: background .15s, color .15s, border-color .15s;
}
.toolbar button:hover { background: var(--card-h); color: var(--tx); }
.toolbar button.active {
  background: linear-gradient(160deg, rgba(47, 211, 208, .22), rgba(61, 139, 240, .22));
  border-color: rgba(47, 211, 208, .45); color: #fff;
  box-shadow: 0 8px 24px -10px rgba(47, 211, 208, .7);
}
.toolbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.toolbar svg .fill { fill: currentColor; }
.toolbar svg.green { stroke: #000; stroke-width: 4.6; stroke-linecap: butt; }
.toolbar svg.green path + path { stroke: var(--pos-blue); stroke-width: 2.2; }
.toolbar svg.green path:first-child { stroke: #cfe6ff; stroke-width: 5.2; }
.toolbar svg .pink { stroke: #ec4fa0; stroke-width: 2.4; }
.toolbar-sep { height: 1px; background: var(--card-b); margin: 4px 6px; flex: none; }
.toolbar button.toggle.active {
  background: rgba(255, 106, 61, .15); border-color: rgba(255, 106, 61, .5); color: #ffb39b; box-shadow: none;
}

/* ---------- Carta ---------- */
.viewport {
  position: relative; flex: 1; min-width: 0; overflow: hidden; touch-action: none;
  background:
    radial-gradient(circle at 20% 10%, rgba(15, 111, 143, .35), transparent 50%),
    radial-gradient(circle at 85% 90%, rgba(23, 63, 134, .35), transparent 50%),
    #08131f;
}
#chart { display: block; width: 100%; height: 100%; cursor: crosshair; }
.viewport.tool-pan #chart { cursor: grab; }
.viewport.panning #chart { cursor: grabbing; }
.viewport.tool-text #chart { cursor: text; }
.viewport.tool-eraser #chart { cursor: cell; }
.viewport.tool-pan.over-link #chart { cursor: pointer; }

.text-editor {
  position: absolute; z-index: 5; min-width: 150px; padding: 3px 8px; color: #111;
  border: 2px solid var(--sky); border-radius: 8px; background: rgba(255, 255, 255, .97);
  outline: none; transform: translateY(-50%); font-weight: 600;
}

.zoom-ctrls {
  position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column;
  background: rgba(10, 23, 38, .88); border: 1px solid var(--card-b); border-radius: 14px;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .6); overflow: hidden; backdrop-filter: blur(10px);
}
.zoom-ctrls button {
  width: 44px; height: 42px; border: 0; background: none; color: var(--tx); font-size: 22px; line-height: 1;
  display: grid; place-items: center;
}
.zoom-ctrls button + button { border-top: 1px solid var(--card-b); }
.zoom-ctrls button:hover { background: var(--card-h); color: var(--aqua); }
.zoom-ctrls svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; }

.loading {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  font-size: 16px; color: var(--mut); background: var(--bg);
}
.loading img { width: 84px; border-radius: 18px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; transform: scale(.96); } }

/* Barras flotantes sobre la carta (transportador, ayuda para afinar puntos) */
.float-bar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px; padding: 7px 7px 7px 14px;
  background: rgba(10, 23, 38, .92); border: 1px solid rgba(56, 189, 248, .25); border-radius: 16px;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .7); backdrop-filter: blur(10px); white-space: nowrap;
}
.float-angle { font-family: var(--font-head); font-weight: 700; font-size: 20px; color: var(--aqua); min-width: 70px; }
.hint-bar { padding-left: 12px; font-size: 14px; font-weight: 600; }
.swatches.mini { gap: 6px; }
.swatches.mini .swatch { width: 26px; height: 26px; border-width: 2px; }
.btn-glass.on { background: rgba(47, 211, 208, .15); border-color: var(--aqua); color: var(--aqua); }
.card .btn-glass.flip { margin-top: 8px; }
.hint-bar svg { width: 20px; height: 20px; fill: none; stroke: var(--aqua); stroke-width: 1.8; stroke-linecap: round; }

/* Botones al estilo de la web */
.btn-main, .btn-glass {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; line-height: 1;
  border: 1px solid transparent; transition: transform .15s, box-shadow .2s, background .15s;
}
.btn-main {
  background: linear-gradient(135deg, #ff8a4c, var(--coral)); color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset, 0 10px 26px -12px rgba(255, 106, 61, .9);
}
.btn-main:hover { transform: translateY(-1px); }
.btn-glass { background: var(--card); border-color: var(--card-b); color: var(--tx); }
.btn-glass:hover { background: var(--card-h); }
.block { width: 100%; }

/* Ventana flotante (calculadora) */
.float-win {
  position: absolute; z-index: 8; top: 16px; left: 16px; width: 360px; height: 600px;
  max-width: calc(100% - 32px); max-height: calc(100% - 32px);
  background: var(--bg-2); border: 1px solid rgba(56, 189, 248, .25); border-radius: 18px;
  box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .75);
  display: flex; flex-direction: column; overflow: hidden; resize: both;
}
.float-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 7px 7px 14px; color: var(--tx); font-family: var(--font-head); font-weight: 600; font-size: 14px;
  cursor: move; user-select: none; touch-action: none; border-bottom: 1px solid var(--card-b);
}
.float-head span { display: flex; align-items: center; gap: 8px; }
.float-head svg { width: 18px; height: 18px; fill: none; stroke: var(--aqua); stroke-width: 1.8; }
.float-head button {
  width: 32px; height: 32px; border: 0; border-radius: 9px; background: none; color: var(--tx);
  font-size: 22px; line-height: 1;
}
.float-head button:hover { background: var(--card-h); color: var(--coral); }
.float-win iframe { flex: 1; width: 100%; border: 0; background: #f3f5f6; }
.float-win.dragging iframe { pointer-events: none; }

/* ---------- Panel lateral ---------- */
.panel {
  width: var(--panel-w); background: var(--bg-2); border-left: 1px solid var(--card-b);
  display: flex; flex-direction: column; min-height: 0; flex: none;
  transition: margin-right .22s ease, transform .22s ease;
}
.app.panel-hidden .panel { margin-right: calc(-1 * var(--panel-w)); }
.tabs { display: flex; align-items: center; gap: 4px; padding: 10px 10px 0; border-bottom: 1px solid var(--card-b); }
.tab {
  flex: 1; padding: 10px 6px 11px; border: 0; background: none;
  color: var(--mut); border-bottom: 2px solid transparent; font-weight: 700; font-size: 14px;
}
.tab:hover { color: var(--tx); }
.tab.active { color: var(--tx); border-bottom-color: var(--aqua); }
.panel-close {
  width: 34px; height: 34px; margin-bottom: 6px; border: 1px solid var(--card-b); border-radius: 10px;
  background: var(--card); color: var(--mut); display: grid; place-items: center; flex: none;
}
.panel-close:hover { color: var(--aqua); }
.panel-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.tab-body { padding: 16px 14px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.tool-head .kicker { font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--aqua); }
.tool-head h2 { font-family: var(--font-head); font-size: 22px; letter-spacing: -.03em; margin: 4px 0 6px; line-height: 1.15; }
.hint { color: var(--mut); font-size: 14px; margin: 0; line-height: 1.5; }
.hint.small { font-size: 12.5px; margin-top: 8px; }

.card {
  background: var(--card); border: 1px solid var(--card-b); border-radius: var(--r); padding: 14px;
}
.card h3 {
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--mut);
  margin: 0 0 10px; display: flex; justify-content: space-between;
}
.card h3 + * { margin-top: 0; }
.card * + h3 { margin-top: 16px; }
.card output { color: var(--aqua); letter-spacing: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--bg-2);
  box-shadow: 0 0 0 1px var(--card-b);
}
.swatch.active { box-shadow: 0 0 0 2px var(--aqua), 0 0 16px -2px var(--aqua); }

input[type=range] { width: 100%; accent-color: var(--aqua); }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; margin-top: 12px; cursor: pointer; color: var(--tx); }
.check input { accent-color: var(--aqua); width: 17px; height: 17px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--card-b); background: var(--card);
  font-size: 13px; font-weight: 600;
}
.chips button:hover { background: var(--card-h); }
.chips button.active { background: rgba(47, 211, 208, .15); border-color: var(--aqua); color: var(--aqua); }
code { background: rgba(47, 211, 208, .12); color: var(--aqua); padding: 0 5px; border-radius: 5px; }

input[type=number], input[type=time], select, textarea {
  background: var(--bg); border: 1px solid var(--card-b); border-radius: 10px; color: var(--tx);
}
input[type=number]:focus, input[type=time]:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--aqua); box-shadow: 0 0 0 3px rgba(47, 211, 208, .15);
}
input[type=time] { padding: 7px 10px; margin-top: 8px; }

.coord-row { display: flex; align-items: center; gap: 5px; margin-bottom: 8px; font-size: 14px; }
.coord-row > span { width: 18px; font-weight: 800; color: var(--aqua); font-family: var(--font-head); }
.coord-row i { font-style: normal; color: var(--mut); }
.coord-row input[type=number] { width: 66px; padding: 7px 8px; }
.coord-row select { padding: 7px 6px; }
.field-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; color: var(--mut); }
.field-row input[type=number] { width: 96px; padding: 8px 10px; }
.field-row .btn-glass { margin-left: auto; }
.card .btn-main.block { margin-top: 6px; padding: 12px; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row button { flex: 1; }

.result dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.result dt { color: var(--mut); }
.result dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.result dd.big {
  font-family: var(--font-head); font-size: 26px; letter-spacing: -.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.big-angle {
  font-family: var(--font-head); font-size: 38px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}

.exam-text { font-size: 14.5px; line-height: 1.6; color: #cfe0ec; }
.exam-text p:first-child { margin-top: 0; }
.exam-text ol { padding-left: 20px; margin-bottom: 0; }
.exam-text li { margin-bottom: 6px; }
textarea { width: 100%; padding: 10px; resize: vertical; font-size: 14px; line-height: 1.5; }

/* ---------- Barra de estado ---------- */
.statusbar {
  display: flex; gap: 16px; align-items: center; padding: 5px 14px; font-size: 12.5px;
  padding-bottom: max(5px, env(safe-area-inset-bottom));
  background: var(--bg-2); border-top: 1px solid var(--card-b); color: var(--mut);
  font-variant-numeric: tabular-nums; min-height: 30px;
}
#coords { color: var(--aqua); font-weight: 700; white-space: nowrap; }
.status-hint { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

dialog {
  border: 1px solid rgba(56, 189, 248, .2); border-radius: 20px; max-width: 580px; padding: 22px 26px;
  background: var(--bg-3); color: var(--tx); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8);
}
dialog::backdrop { background: rgba(5, 13, 24, .7); backdrop-filter: blur(4px); }
dialog h2 { margin-top: 0; font-family: var(--font-head); letter-spacing: -.03em; }
dialog li { margin-bottom: 8px; line-height: 1.5; color: #cfe0ec; }
dialog b { color: var(--tx); }
dialog form { text-align: right; }

/* ---------- Móvil / tablet vertical ---------- */
@media (max-width: 820px) {
  .topbar { gap: 8px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); min-height: 56px; }
  .brand-text { display: none; }
  .brand-logo { width: 40px; height: 40px; }
  .exam-select { padding: 0; border: 0; background: none; }
  .exam-select .label { display: none; }
  .exam-select select { max-width: 150px; }
  .actions { gap: 0; }
  .icon-btn { width: 36px; }
  .main { flex-direction: column-reverse; }
  .toolbar {
    width: 100%; flex-direction: row; overflow-x: auto; border-right: 0; border-top: 1px solid var(--card-b);
    padding: 6px;
  }
  .toolbar button { min-width: 64px; }
  .toolbar-sep { width: 1px; height: auto; margin: 6px 2px; }
  .panel {
    position: absolute; right: 0; top: 0; bottom: 76px; width: min(340px, 92vw); z-index: 10;
    border: 1px solid rgba(56, 189, 248, .2); border-radius: 18px 0 0 18px;
    box-shadow: -10px 0 40px rgba(0, 0, 0, .5); transform: translateX(105%);
  }
  .app.panel-open .panel { transform: none; }
  .app.panel-hidden .panel { margin-right: 0; }
  .status-hint { display: none; }
  .float-win { width: 330px; height: 560px; }
}
@media (max-width: 440px) {
  .exam-select select { max-width: 112px; }
  .icon-btn { width: 33px; }
}
