:root {
  color-scheme: dark;
  --bg: #050709;
  --panel: rgba(10, 15, 20, 0.96);
  --line: rgba(193, 211, 227, 0.14);
  --muted: #7f8d9c;
  --soft: #b6c0ca;
  --white: #f4f8fb;
  --green: #2de37f;
  --blue: #67a9ff;
  --orange: #f6a93d;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.tool-stage,
.tool-frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

.tool-frame[hidden] { display: none; }

.launcher-button {
  position: fixed;
  z-index: 80;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  min-width: 78px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid rgba(193, 211, 227, 0.24);
  border-radius: 999px;
  color: var(--white);
  background: rgba(7, 11, 15, 0.88);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.launcher-button[hidden] { display: none; }
.launcher-button:active { transform: translateY(1px); }

.launcher-grid {
  width: 15px;
  display: grid;
  grid-template-columns: repeat(2, 5px);
  gap: 3px;
}

.launcher-grid i {
  width: 5px;
  height: 5px;
  border-radius: 1.5px;
  background: var(--blue);
}

.hub-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: start center;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) max(26px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(26px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 18% 14%, rgba(103, 169, 255, 0.13), transparent 30%),
    radial-gradient(circle at 84% 80%, rgba(45, 227, 127, 0.09), transparent 30%),
    linear-gradient(135deg, rgba(4, 7, 10, 0.98), rgba(8, 13, 18, 0.98));
}

.hub-overlay[hidden] { display: none; }

.hub-shell {
  width: min(920px, 100%);
  margin: auto 0;
  padding: clamp(24px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5);
}

.hub-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 15px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #15100a;
  background: linear-gradient(135deg, #ffc55d, #e87924);
  box-shadow: 0 10px 28px rgba(232, 121, 36, 0.2);
  font-size: 31px;
  font-weight: 850;
}

.hub-heading { min-width: 0; }
.eyebrow { color: var(--blue); font-size: 10px; letter-spacing: 0.18em; font-weight: 760; }

h1 {
  margin: 3px 0 5px;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.hub-heading p { margin: 0; color: var(--muted); font-size: 13px; }

.close-hub {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--soft);
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  font-size: 24px;
}

.close-hub[hidden] { display: none; }

.tool-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.tool-card {
  min-width: 0;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--white);
  background: #0c1218;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.2);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.tool-card:hover,
.tool-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(103, 169, 255, 0.48);
  box-shadow: 0 22px 52px rgba(0, 0, 0, 0.34);
  outline: none;
}

.tool-card.active { border-color: rgba(45, 227, 127, 0.5); }
.card-topline { display: flex; align-items: center; justify-content: space-between; }
.card-index { color: var(--muted); font-family: "SF Mono", Menlo, monospace; font-size: 11px; }

.status-chip {
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--blue);
  background: rgba(103, 169, 255, 0.1);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.status-chip.live { color: var(--green); background: rgba(45, 227, 127, 0.1); }
.card-title { margin-top: 18px; font-size: 27px; font-weight: 790; letter-spacing: -0.035em; }
.card-description { min-height: 54px; margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.55; }

.ticker-preview,
.backtest-preview {
  position: relative;
  flex: 1;
  min-height: 142px;
  display: block;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid rgba(193, 211, 227, 0.1);
  border-radius: 13px;
  overflow: hidden;
  background: #070b0f;
}

.preview-symbol { display: block; color: var(--muted); font-size: 10px; letter-spacing: 0.08em; }
.ticker-preview > strong { display: block; margin-top: 9px; color: var(--green); font: 780 32px/1 "SF Mono", Menlo, monospace; letter-spacing: -0.06em; }
.preview-change { display: block; margin-top: 5px; color: var(--green); font-size: 11px; }

.mini-candles {
  position: absolute;
  right: 14px;
  bottom: 13px;
  left: 14px;
  height: 38px;
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 7px;
  border-bottom: 1px solid rgba(193, 211, 227, 0.12);
}

.mini-candles i { width: 6px; border-radius: 1px; background: var(--green); }
.mini-candles i:nth-child(1) { height: 12px; }
.mini-candles i:nth-child(2) { height: 21px; background: #ff6171; }
.mini-candles i:nth-child(3) { height: 16px; }
.mini-candles i:nth-child(4) { height: 28px; }
.mini-candles i:nth-child(5) { height: 23px; background: #ff6171; }
.mini-candles i:nth-child(6) { height: 31px; }
.mini-candles i:nth-child(7) { height: 25px; }
.mini-candles i:nth-child(8) { height: 36px; }

.backtest-preview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: auto 1fr;
  gap: 8px;
  background: #f7f9fc;
  color: #1f2430;
}

.preview-stat { padding: 10px; border: 1px solid #e2e5ea; border-radius: 8px; background: white; }
.preview-stat small { display: block; color: #7a8492; font-size: 8px; letter-spacing: 0.06em; }
.preview-stat strong { display: block; margin-top: 4px; color: #16a34a; font-size: 16px; }
.preview-chart { position: relative; grid-column: 1 / -1; min-height: 52px; border: 1px solid #e2e5ea; border-radius: 8px; background: white; overflow: hidden; }

.preview-chart::before,
.preview-chart::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 16px, rgba(31, 36, 48, 0.06) 17px);
}

.preview-chart i {
  position: absolute;
  z-index: 1;
  right: 9px;
  bottom: 11px;
  left: 9px;
  height: 25px;
  border-top: 3px solid #2563eb;
  border-radius: 50% 45% 0 0;
  transform: skewY(-7deg);
}

.card-action { display: flex; align-items: center; justify-content: space-between; color: var(--soft); font-size: 12px; font-weight: 720; }
.card-action b { color: var(--blue); font-size: 18px; }
.ticker-card .card-action b { color: var(--green); }

.alarm-card {
  margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #0c1218;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.2);
}

.alarm-card-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
}

.alarm-card-heading h2 { margin: 12px 0 5px; font-size: 27px; letter-spacing: -0.035em; }
.alarm-card-heading p { max-width: 620px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.alarm-card-signal {
  width: 76px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(45, 227, 127, 0.28);
  border-radius: 15px;
  color: var(--green);
  background: rgba(45, 227, 127, 0.09);
  font: 850 27px/1 "SF Mono", Menlo, monospace;
  letter-spacing: -0.12em;
}

.alarm-card-signal.warning { color: #ffd84d; border-color: rgba(255, 216, 77, 0.42); background: rgba(255, 216, 77, 0.1); }
.alarm-card-signal.danger { color: #ff6171; border-color: rgba(255, 97, 113, 0.46); background: rgba(255, 97, 113, 0.12); }
.status-chip.alarm-idle { color: var(--muted); background: rgba(127, 141, 156, 0.1); }
.status-chip.alarm-safe { color: var(--green); background: rgba(45, 227, 127, 0.1); }
.status-chip.alarm-warning { color: #ffd84d; background: rgba(255, 216, 77, 0.1); }
.status-chip.alarm-danger { color: #ff6171; background: rgba(255, 97, 113, 0.12); }

.alarm-control-row {
  display: grid;
  grid-template-columns: minmax(140px, 0.7fr) minmax(220px, 1.2fr) minmax(140px, 0.55fr);
  gap: 12px;
  margin-top: 18px;
}

.alarm-symbol-box,
.alarm-price-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid rgba(193, 211, 227, 0.12);
  border-radius: 11px;
  background: #070b0f;
}

.alarm-symbol-box span,
.alarm-price-field span { color: var(--muted); font-size: 9px; letter-spacing: 0.08em; }
.alarm-symbol-box strong { color: var(--blue); font: 760 16px/1.2 "SF Mono", Menlo, monospace; }
.alarm-symbol-input-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}
.alarm-symbol-input-row input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--blue);
  background: transparent;
  font: 760 16px/1.2 "SF Mono", Menlo, monospace;
  text-transform: uppercase;
}
.alarm-symbol-input-row button {
  flex: 0 0 auto;
  padding: 5px 7px;
  border: 1px solid rgba(103, 169, 255, 0.3);
  border-radius: 7px;
  color: var(--blue);
  background: rgba(103, 169, 255, 0.08);
  cursor: pointer;
  font-size: 9px;
  white-space: nowrap;
}
.alarm-symbol-box:focus-within { border-color: rgba(103, 169, 255, 0.55); }
.alarm-price-field input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--white);
  background: transparent;
  font: 760 19px/1.2 "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
.alarm-price-field:focus-within { border-color: rgba(103, 169, 255, 0.55); }

.start-alarm-button {
  min-height: 62px;
  padding: 0 16px;
  border: 1px solid rgba(246, 169, 61, 0.48);
  border-radius: 11px;
  color: #171008;
  background: linear-gradient(135deg, #ffc55d, #e87924);
  cursor: pointer;
  font-size: 14px;
  font-weight: 820;
}
.start-alarm-button:active { transform: translateY(1px); }
.start-alarm-button:disabled { opacity: 0.55; cursor: wait; }

.alarm-detail-row,
.alarm-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 11px;
  color: var(--muted);
  font-size: 10px;
}

.alarm-message { min-height: 17px; margin-top: 8px; color: var(--orange); font-size: 11px; }
.alarm-message.error { color: #ff6171; }
.alarm-message.success { color: var(--green); }
.alarm-legend { justify-content: flex-start; flex-wrap: wrap; padding-top: 11px; border-top: 1px solid var(--line); }
.alarm-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-face { min-width: 26px; font-style: normal; font: 800 12px/1 "SF Mono", Menlo, monospace; text-align: center; }
.legend-face.safe { color: var(--green); }
.legend-face.warning { color: #ffd84d; }
.legend-face.danger { color: #ff6171; }

.hub-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 10px;
}

.footer-dot { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 9px var(--orange); }

@media (max-width: 700px), (max-height: 650px) {
  .hub-overlay { place-items: start center; padding: 14px; }
  .hub-shell { padding: 20px; border-radius: 18px; }
  .hub-header { margin-bottom: 18px; }
  .brand-mark { width: 40px; height: 40px; font-size: 25px; }
  .tool-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tool-card { min-height: 280px; padding: 17px; }
  .card-title { margin-top: 12px; font-size: 22px; }
  .card-description { min-height: 48px; font-size: 11px; }
  .ticker-preview, .backtest-preview { min-height: 105px; margin: 12px 0; }
  .ticker-preview > strong { font-size: 25px; }
  .alarm-card { padding: 17px; }
  .alarm-control-row { grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1.1fr) minmax(120px, 0.55fr); }
}

@media (max-width: 620px) {
  html, body { overflow: auto; }
  .hub-overlay { position: absolute; overflow: visible; }
  .tool-card-grid { grid-template-columns: 1fr; }
  .alarm-control-row { grid-template-columns: 1fr; }
  .alarm-card-heading h2 { font-size: 22px; }
  .alarm-card-signal { width: 64px; height: 52px; }
  .alarm-detail-row { align-items: flex-start; flex-direction: column; }
  .hub-footer { align-items: flex-start; flex-direction: column; }
}
