/* ================================================================
   AQUAMESH — ledger
   live trade & p&l record — same charcoal/bone system as the front
   ================================================================ */

:root {
  /* night (default) */
  --bg: #0d0d0e;
  --bg-rgb: 13, 13, 14;
  --ink: #e8e6e1;
  --ink-rgb: 232, 230, 225;
  --ink-dim: #7d7c77;
  --hairline: rgba(var(--ink-rgb), 0.1);
  --accent: #8ab8af; /* sea glass — one colour, one meaning: alive */
  --accent-rgb: 138, 184, 175;
  --gain: var(--accent);
  --loss: #c08e80;
  --breath: rgba(199, 206, 212, 0.035);

  --font-serif: "Cormorant Garamond", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --pad: clamp(22px, 3.4vw, 48px);
}

/* paper */
:root[data-theme="light"] {
  --bg: #eceae4;
  --bg-rgb: 236, 234, 228;
  --ink: #1b1c1c;
  --ink-rgb: 27, 28, 28;
  --ink-dim: #6f6d66;
  --accent: #4d8077; /* deepened for contrast on paper */
  --accent-rgb: 77, 128, 119;
  --loss: #9c5f4e;
  --breath: rgba(var(--accent-rgb), 0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { background: var(--bg); }

body {
  position: relative; /* anchors the absolute bottom corners */
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color 0.6s ease, color 0.6s ease;
}

html { transition: background-color 0.6s ease; }

::selection { background: var(--accent); color: var(--bg); }

a { color: inherit; text-decoration: none; }

/* ----------------------------------------------------------------
   Fixed layers
---------------------------------------------------------------- */

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; }

.haze {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(70% 42% at 50% 52%, var(--breath) 0%, transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, transparent 20%),
    linear-gradient(0deg, var(--bg) 0%, transparent 22%);
}

.grain {
  position: fixed;
  inset: -100px;
  z-index: 40;
  pointer-events: none;
  opacity: 0.038;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ----------------------------------------------------------------
   Access gate
---------------------------------------------------------------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 30; /* over content, under grain so the texture carries */
  /* frost: the tracker shows through plainly, nothing reads */
  background: radial-gradient(38% 30% at 50% 50%,
    rgba(var(--bg-rgb), 0.5) 0%,
    rgba(var(--bg-rgb), 0.08) 100%);
  -webkit-backdrop-filter: blur(7px) saturate(1.05);
  backdrop-filter: blur(7px) saturate(1.05);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* no backdrop-filter support → opaque, nothing shows */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .gate { background: var(--bg); }
}

.gate__eyebrow,
.gate__hint,
.gate__input {
  text-shadow: 0 0 14px rgba(var(--bg-rgb), 0.85);
}

.gate__brand {
  position: absolute;
  top: var(--pad);
  left: var(--pad);
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--ink);
}

.gate__brand sup { font-size: 6px; letter-spacing: 0; margin-left: 2px; color: var(--accent); }

.gate__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.gate__eyebrow {
  font-size: 10px;
  letter-spacing: 0.38em;
  text-indent: 0.38em;
  color: var(--ink-dim);
}

.gate__input {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.28em;
  color: var(--ink);
  padding: 10px 6px;
  width: min(300px, 78vw);
  text-align: center;
  outline: none;
  caret-color: var(--accent);
  transition: border-color 0.4s ease;
}

.gate__input:focus { border-color: rgba(var(--accent-rgb), 0.5); }
.gate__input::placeholder { color: var(--ink-dim); opacity: 0.55; }

.gate__hint {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--ink-dim);
  opacity: 0.7;
  min-height: 12px;
  transition: color 0.3s ease;
}

.gate.is-error .gate__input { border-color: rgba(192, 142, 128, 0.7); }
.gate.is-error .gate__hint { color: var(--loss); opacity: 1; }
.gate.is-busy .gate__hint { opacity: 1; }

/* ----------------------------------------------------------------
   Corners
---------------------------------------------------------------- */

.corner {
  position: fixed;
  z-index: 10;
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--ink-dim);
  opacity: 0;
}

.corner--tl {
  top: var(--pad);
  left: var(--pad);
  color: var(--ink);
  padding-bottom: 3px;
  position: fixed;
}

.corner--tl sup { font-size: 6px; letter-spacing: 0; margin-left: 2px; color: var(--accent); }

.corner--tl::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: right center;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.corner--tl:hover::after { transform: scaleX(1); transform-origin: left center; }

.corner--tr {
  top: var(--pad);
  right: var(--pad);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--ink-dim);
  transition: color 0.3s ease;
}

.theme-toggle:empty { display: none; }

.theme-toggle__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid currentColor;
  background: transparent;
  transition: background-color 0.3s ease;
}

:root[data-theme="light"] .theme-toggle__dot { background: currentColor; }

.theme-toggle:hover { color: var(--accent); }

/* bottom corners scroll with the document — this page is taller than
   the viewport, fixed ones would collide with the table */
.corner--bl { position: absolute; bottom: var(--pad); left: var(--pad); }
.corner--br { position: absolute; bottom: var(--pad); right: var(--pad); }

/* ----------------------------------------------------------------
   Layout
---------------------------------------------------------------- */

.ledger {
  position: relative;
  z-index: 10;
  max-width: 1160px;
  margin: 0 auto;
  padding: clamp(88px, 13vh, 140px) var(--pad) clamp(80px, 11vh, 120px);
}

.ledger__head { margin-bottom: clamp(30px, 4.5vh, 52px); }

.ledger__title {
  font-family: var(--font-serif);
  font-weight: 300;
  font-size: clamp(52px, 7vw, 96px);
  line-height: 0.9;
  letter-spacing: 0.005em;
}

.ledger__title .char { display: inline-block; will-change: transform, filter, opacity; }

.ledger__sub {
  margin-top: 16px;
  font-size: 10px;
  letter-spacing: 0.38em;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.8);
  animation: pulse 2.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ----------------------------------------------------------------
   Stats
---------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(26px, 4vh, 46px) clamp(20px, 4vw, 56px);
  border-top: 1px solid var(--hairline);
  padding-top: clamp(22px, 3vh, 32px);
}

.stat dt {
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  margin-bottom: 10px;
}

.stat dd {
  font-family: var(--font-serif);
  font-weight: 300;
  font-size: clamp(30px, 3.8vw, 54px);
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: lining-nums;
}

.stat dd small {
  display: block;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.26em;
  color: var(--ink-dim);
}

.stat dd.gain { color: var(--gain); }
.stat dd.loss { color: var(--loss); }

/* ----------------------------------------------------------------
   The equity instrument — svg scaffolding over the webgl shimmer
---------------------------------------------------------------- */

.strand-space {
  position: relative;
  height: clamp(230px, 34vh, 400px);
  margin: clamp(10px, 2vh, 24px) 0 clamp(14px, 2.5vh, 28px);
}

.strand-svg {
  position: absolute;
  inset: 0;
  display: block;
  overflow: visible;
}

.strand-svg text {
  font-family: var(--font-mono);
  fill: var(--ink-dim);
  font-size: 8.5px;
  letter-spacing: 0.18em;
}

.s-line {
  fill: none;
  stroke: rgba(var(--ink-rgb), 0.82);
  stroke-width: 1.25;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.s-area { fill: url(#s-fill); }
.s-fill-a { stop-color: rgba(var(--ink-rgb), 0.06); }
.s-fill-b { stop-color: rgba(var(--ink-rgb), 0); }

.s-base {
  stroke: rgba(var(--ink-rgb), 0.14);
  stroke-width: 1;
  stroke-dasharray: 2 6;
}

.s-tick { stroke: rgba(var(--ink-rgb), 0.22); stroke-width: 1; }

.s-node {
  fill: var(--ink);
  transform-box: fill-box;
  transform-origin: center;
}

.s-node--start { fill: var(--ink-dim); }

.s-ring {
  fill: none;
  stroke: rgba(var(--accent-rgb), 0.7);
  stroke-width: 1;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.s-tracker {
  stroke: rgba(var(--accent-rgb), 0.16);
  stroke-width: 1;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.strand-space.is-hover .s-ring,
.strand-space.is-hover .s-tracker { opacity: 1; }

.pnl-float {
  position: absolute;
  top: 0;
  left: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--gain);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.4s ease;
  text-shadow: 0 0 8px rgba(var(--bg-rgb), 0.9);
}

.pnl-float.loss { color: var(--loss); }
.strand-space.is-hover .pnl-float { opacity: 1; }

.terminal-label {
  position: absolute;
  z-index: 12;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 0 10px rgba(var(--bg-rgb), 0.9);
}

.terminal-label__dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.9);
  animation: pulse 2.2s ease-in-out infinite;
}

/* ----------------------------------------------------------------
   Trades table
---------------------------------------------------------------- */

.trades {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  letter-spacing: 0.06em;
}

.trades th {
  text-align: left;
  font-weight: 400;
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  padding: 0 10px 14px;
}

.trades th.num, .trades td.num { text-align: right; }

.trades td {
  padding: 14px 10px;
  border-top: 1px solid var(--hairline);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background-color 0.35s ease;
}

.trades tbody tr { cursor: default; }
.trades tbody tr:hover td { background: rgba(var(--ink-rgb), 0.03); }

.trades td.dim { color: var(--ink-dim); }
.trades td.gain { color: var(--gain); }
.trades td.loss { color: var(--loss); }

.trades .side { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-dim); }
.trades .side i { font-style: normal; font-size: 10px; color: var(--ink); opacity: 0.7; }

.trades .empty {
  text-align: center;
  color: var(--ink-dim);
  letter-spacing: 0.3em;
  padding: 40px 10px;
}

/* ----------------------------------------------------------------
   Noscript
---------------------------------------------------------------- */

.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
}

.noscript h1 { font-family: var(--font-serif); font-weight: 300; font-size: 38px; }
.noscript p { font-size: 12px; letter-spacing: 0.08em; color: var(--ink-dim); }
.noscript a { color: var(--ink); border-bottom: 1px solid var(--hairline); }

/* ----------------------------------------------------------------
   Small screens
---------------------------------------------------------------- */

@media (max-width: 880px) {
  .stats { grid-template-columns: repeat(2, 1fr); row-gap: 30px; }
}

@media (max-width: 640px) {
  .trades th:nth-child(4), .trades td:nth-child(4),
  .trades th:nth-child(5), .trades td:nth-child(5) { display: none; }
  .corner--br { display: none; }
  .terminal-label__prefix { display: none; }
  .s-ticklabel--minor { display: none; }
}

/* ----------------------------------------------------------------
   Reduced motion
---------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  [data-reveal], [data-reveal] * {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }
  .live-dot, .terminal-label__dot { animation: none; }
}

/* phones: the decorative clock yields to the functional toggle */
@media (max-width: 640px) {
  .corner--tr > span { display: none; }
}
