/* Belay — granite surfaces, rope colours for state.
   Every colour is a variable so the two themes stay in lockstep. */

:root[data-theme="dark"] {
  --bg: #131619;
  --surface: #1B1F23;
  --surface-2: #22272C;
  --border: #2C3238;
  --border-strong: #3A424A;
  --text: #E4E7E4;
  --text-dim: #9BA3AB;
  --text-faint: #6E7681;
  --calm: #6BA3C4;
  --calm-bg: #1A2A35;
  --watch: #D9A040;
  --watch-bg: #2E2415;
  --catch: #D9564C;
  --catch-bg: #331A1A;
  --catch-glow: rgba(217, 86, 76, .30);
  --catch-glow-peak: rgba(217, 86, 76, .50);
  --track: #2C3238;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

:root[data-theme="light"] {
  --bg: #ECEEEA;
  --surface: #FFFFFF;
  --surface-2: #F2F4F0;
  --border: #D5D9D2;
  --border-strong: #AFB5AC;
  --text: #1C2024;
  --text-dim: #5B646D;
  --text-faint: #868E96;
  --calm: #35708F;
  --calm-bg: #E8F1F6;
  --watch: #A8701A;
  --watch-bg: #FBF1DF;
  --catch: #B23A31;
  --catch-bg: #FBEBEA;
  --catch-glow: rgba(178, 58, 49, .18);
  --catch-glow-peak: rgba(178, 58, 49, .32);
  --track: #DCE0D9;
  --shadow: 0 1px 3px rgba(28, 32, 36, .07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
}

h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.mono, .num {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

a { color: inherit; }

/* ------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--text);
}

.wordmark-glyph { color: var(--calm); flex-shrink: 0; }

.market {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-dim);
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.dot[data-open="true"] { background: var(--calm); box-shadow: 0 0 0 3px var(--calm-bg); }

.nav {
  margin-left: auto;
  display: flex;
  gap: 2px;
}

.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  color: var(--text-dim);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 500; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="light"] .icon-moon { display: none; }

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

.shell {
  max-width: 940px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.muted { color: var(--text-dim); font-size: 13px; }
.faint { color: var(--text-faint); font-size: 13px; }

/* ------------------------------------------------------------ add form */

.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

input[type="text"], input[type="password"], input[type="number"], select {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--calm);
  outline-offset: 1px;
}
input::placeholder { color: var(--text-faint); }

.ticker-input {
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

button {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--border-strong); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary {
  background: var(--calm);
  border-color: var(--calm);
  color: #fff;
  font-weight: 500;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }

button.ghost { background: transparent; }
button.danger { color: var(--catch); }
button.small { padding: 5px 10px; font-size: 13px; }

/* ---------------------------------------------------- attention band */

/* Its own recessed surface, so it reads as a different place rather than
   just a heading with cards under it. */
.attention {
  background: var(--surface-2);
  border: 1px solid var(--catch-glow);
  border-radius: 14px;
  padding: 12px 12px 4px;
  margin-bottom: 22px;
}

.band-head,
.rest-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 2px 4px 10px;
}

.band-head { color: var(--catch); }
.rest-head { color: var(--text-faint); margin-top: 4px; }

.band-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--catch);
  box-shadow: 0 0 0 3px var(--catch-glow);
}

.band-count {
  margin-left: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-faint);
}

.attention .card { background: var(--surface); }

/* -------------------------------------------------------------- cards */

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  transition: border-color .3s, box-shadow .3s;
}

/* A caught card breathes rather than blinks — roughly a 2.5s cycle, the same
   rhythm as ambient's critical state. Only the caught level animates: if the
   approaching state pulsed too, motion would stop meaning anything. */
.card[data-state="caught"] {
  border-color: var(--catch);
  box-shadow: 0 0 0 1px var(--catch-glow), 0 0 16px var(--catch-glow);
  animation: breathe 2.5s ease-in-out infinite;
}

/* The strip carries the state down the card edge, so it still reads from a
   distance where the glow itself may not. */
.card[data-state="caught"]::before {
  content: "";
  position: absolute;
  inset-block: -1px;
  left: -1px;
  width: 3px;
  border-radius: 12px 0 0 12px;
  background: var(--catch);
}

.card[data-state="caught"] .ticker {
  color: var(--catch);
  text-shadow: 0 0 14px var(--catch-glow-peak);
}

@keyframes breathe {
  50% {
    box-shadow: 0 0 0 1px var(--catch-glow-peak), 0 0 26px var(--catch-glow-peak);
  }
}

.card-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
}

.identity { min-width: 0; flex: 1; }

.ticker {
  font-family: "IBM Plex Mono", monospace;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.company {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price-block { text-align: right; min-width: 108px; }

.price {
  font-family: "IBM Plex Mono", monospace;
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.change {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.change.up { color: var(--calm); }
.change.down { color: var(--catch); }
.change.flat { color: var(--text-faint); }

/* ------------------------------------------ tension meter / signature */

.lines {
  padding: 0 16px 12px;
  display: grid;
  gap: 2px;
}

/* Fixed columns so names, meters and numbers line up down the whole card.
   Deliberately not a knob on a track — that reads as a slider you can drag. */
.line {
  display: grid;
  grid-template-columns: 104px minmax(60px, 1fr) 72px 52px 66px 92px;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  border-radius: 6px;
}
.line:hover { background: var(--surface-2); }
.line:hover .line-actions { opacity: 1; }

.line-name {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meter {
  position: relative;
  height: 6px;
  background: var(--track);
  border-radius: 3px;
  overflow: hidden;
}

.meter-fill {
  position: absolute;
  inset-block: 0;
  left: 0;
  border-radius: 3px;
  background: var(--calm);
  transition: width .45s cubic-bezier(.4, 0, .2, 1), background-color .3s;
}

.line-move,
.line-limit {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.line-move { color: var(--text); }
.line-limit { color: var(--text-faint); }

.line[data-level="watch"] .meter-fill { background: var(--watch); }
.line[data-level="watch"] .line-move { color: var(--watch); }
.line[data-level="catch"] .meter-fill { background: var(--catch); }
.line[data-level="catch"] .line-move { color: var(--catch); font-weight: 500; }
.line[data-warming="true"] .meter-fill { opacity: .3; }
.line[data-warming="true"] .line-move { color: var(--text-faint); }

.line-tags {
  display: flex;
  justify-content: flex-end;
  min-width: 0;
}

.line-actions {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}
/* Keyboard users never hover, so focus has to reveal them too. */
.line-actions:focus-within { opacity: 1; }

.card-actions {
  display: flex;
  gap: 2px;
  align-self: flex-start;
}

.linkish {
  background: none;
  border: none;
  padding: 2px 5px;
  font-size: 12px;
  color: var(--text-faint);
  cursor: pointer;
  border-radius: 4px;
}
.linkish:hover { color: var(--text); background: var(--surface-2); }

/* -------------------------------------------------------------- pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill.calm { background: var(--calm-bg); color: var(--calm); }
.pill.watch { background: var(--watch-bg); color: var(--watch); }
.pill.catch { background: var(--catch-bg); color: var(--catch); }
.pill.quiet { background: var(--surface-2); color: var(--text-faint); }

/* ------------------------------------------------------------- panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.panel h2 { margin-bottom: 4px; }
.panel > .muted:first-of-type { margin-bottom: 16px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
}
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; }

.divider { height: 1px; background: var(--border); margin: 18px 0; }

.check { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.check input { width: auto; }

/* ------------------------------------------------------------- alerts */

.alert-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.alert-row:last-child { border-bottom: none; }

.alert-move {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 15px;
  color: var(--catch);
  font-variant-numeric: tabular-nums;
}

.suspect {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--watch-bg);
  color: var(--watch);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}

/* -------------------------------------------------------------- empty */

.empty {
  text-align: center;
  padding: 48px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  color: var(--text-dim);
}
.empty h2 { margin-bottom: 6px; color: var(--text); }

/* ------------------------------------------------------------- footer */

.footer {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 20px 32px;
  text-align: center;
}

.footer a {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  text-decoration: none;
}
.footer a:hover { color: var(--text-dim); }

@media (max-width: 620px) {
  .footer { padding: 0 12px 24px; }
}

/* ------------------------------------------------------------- toasts */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: grid;
  gap: 8px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 40px));
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  animation: rise .18s ease-out;
}
.toast.error { border-color: var(--catch); color: var(--catch); }
.toast.ok { border-color: var(--calm); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------ banners */

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.55;
}
.banner.warn { background: var(--watch-bg); color: var(--watch); }
.banner a { font-weight: 500; }

/* ------------------------------------------------------------ spinner */

.spin {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--calm);
  border-radius: 50%;
  animation: turn .7s linear infinite;
}
@keyframes turn { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  /* The steady glow still marks the state; only the breathing stops. */
  .card[data-state="caught"] { animation: none; }
}

/* ------------------------------------------------------------- mobile */

@media (max-width: 620px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .market { display: none; }
  .nav a { padding: 6px 9px; font-size: 13px; }
  .shell { padding: 16px 12px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .line {
    grid-template-columns: 1fr auto auto;
    grid-template-areas: "name move limit" "meter meter meter" "acts acts acts";
    gap: 4px 8px;
  }
  .line-name { grid-area: name; }
  .meter { grid-area: meter; }
  .line-move { grid-area: move; }
  .line-limit { grid-area: limit; }
  .line-tags { display: none; }
  .line-actions { grid-area: acts; opacity: 1; justify-content: flex-start; }

  /* Keep the field and its button on one line — wrapping stranded the button
     on a row of its own. */
  .add-row { flex-wrap: nowrap; }
  .add-row input { min-width: 0; }

  .section-head { flex-wrap: wrap; }
  .section-head h1 { font-size: 20px; }

  /* Ticker and price first, actions on their own row, so long company names
     aren't truncated to three characters. */
  .card-head { flex-wrap: wrap; row-gap: 6px; }
  .identity { flex: 1 1 55%; }
  .price-block { min-width: 0; }
  .card-actions { flex: 1 0 100%; justify-content: flex-start; order: 3; }
}
