@import url("../fonts/fonts.css");
@import "design-system.css";
@import "data-saver.css";
@import "theme-toggle.css";

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 100;
  padding: 0.5rem 0.85rem;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--focus-ring);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  text-decoration: none;
  transform: translateY(-140%);
  transition: transform 0.15s var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.mono,
.num,
.tabular,
td.num,
th.num,
.pill,
.ticker-line,
.range-tabs button,
.sparkline {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.03em;
}

a {
  color: var(--text);
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.up {
  color: var(--up);
}
.down {
  color: var(--down);
}

.holo-text {
  background: var(--holo);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* —— Shell —— */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.875rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 30;
}

.app-brand {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: -0.04em;
  margin-bottom: 1.75rem;
  color: var(--text);
  text-decoration: none;
  padding: 0 0.5rem;
}

.app-brand em {
  font-style: normal;
  background: var(--holo);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  flex: 1;
}

.app-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  min-height: 44px;
  display: flex;
  align-items: center;
  touch-action: manipulation;
}

.app-drawer-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin: -0.5rem -0.25rem 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.app-drawer-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.app-drawer-close {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  touch-action: manipulation;
}

.app-nav a:hover,
.app-nav a.active {
  background: var(--surface-2);
  color: var(--text);
}

.app-nav a.active {
  border-left: 2px solid transparent;
  border-image: var(--holo) 1;
  padding-left: calc(0.625rem - 2px);
}

.app-sidebar footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

.app-sidebar footer a {
  color: var(--muted);
  display: block;
  margin-top: 0.35rem;
  text-decoration: none;
  font-family: var(--font-mono);
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 1.25rem clamp(1rem, 2.5vw, 1.75rem) 2.5rem;
  max-width: 100%;
  min-width: 0;
}

.app-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: max(0.65rem, env(safe-area-inset-top)) 1rem 0.65rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 25;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.app-menu-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.app-nav-state {
  position: fixed;
  left: -100vw;
  top: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.app-sidebar-backdrop {
  display: none;
}

body.app-nav-open {
  overflow: hidden;
}

@media (max-width: 900px) {
  .app-drawer-bar {
    display: flex;
  }
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s var(--ease);
    visibility: hidden;
    pointer-events: none;
  }
  .app-sidebar.open,
  body.app-nav-open .app-sidebar,
  #appNavOpen:checked ~ .app-shell .app-sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }
  .app-main {
    margin-left: 0;
  }
  .app-topbar {
    display: flex;
  }
  .app-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--overlay-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s var(--ease);
  }
  body.app-nav-open .app-sidebar-backdrop,
  #appNavOpen:checked ~ .app-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-sidebar-backdrop,
  .skip-link {
    transition: none;
  }
}

/* —— Portfolio dashboard —— */
.dash-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem 2rem;
  align-items: end;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.dash-portfolio-value {
  font-size: clamp(2.75rem, 8vw, 4.5rem);
  line-height: 1;
  margin: 0;
}

.dash-pnl-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.dash-pnl {
  font-size: 1.125rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.pill.up {
  border-color: rgba(63, 185, 80, 0.35);
  background: rgba(63, 185, 80, 0.12);
}
.pill.down {
  border-color: rgba(248, 81, 73, 0.35);
  background: rgba(248, 81, 73, 0.12);
}

.dash-meta {
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
}

.stat-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 500;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  margin: 0;
}

.alloc-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.65rem;
  background: var(--surface-2);
}

.alloc-bar span {
  display: block;
  height: 100%;
}

.alloc-bar .singles {
  background: #06b6d4;
}
.alloc-bar .sealed {
  background: #d946ef;
}
.alloc-bar .slabs {
  background: #fcd34d;
}

.alloc-legend {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.6875rem;
  color: var(--muted);
}

.chart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem 0.75rem;
  margin-bottom: 1.25rem;
}

.chart-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.chart-panel h2 {
  margin: 0;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 500;
}

.range-tabs {
  display: flex;
  gap: 0.25rem;
}

.range-tabs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  font-size: 0.6875rem;
  border-radius: 6px;
  cursor: pointer;
}

.range-tabs button.active,
.range-tabs button:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-2);
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-axis {
  font-size: 10px;
  fill: var(--muted);
}

.ticker-strip {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0;
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.ticker-inner {
  font-size: 0.6875rem;
  color: var(--muted);
  white-space: nowrap;
  animation: ticker-scroll 40s linear infinite;
}

@keyframes ticker-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.dash-body {
  display: grid;
  grid-template-columns: 1fr var(--watch-w);
  gap: 1rem;
  align-items: start;
}

.dash-primary {
  min-width: 0;
}

.watch-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  position: sticky;
  top: 1rem;
}

.watch-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.watch-toggle {
  display: none;
  width: 100%;
  margin-bottom: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
}

.watch-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.watch-item:last-child {
  border-bottom: none;
}

.watch-item .price {
  text-align: right;
  font-size: 0.8125rem;
}

.watch-item .alert {
  grid-column: 1 / -1;
  font-size: 0.6875rem;
  color: var(--muted);
}

.movers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.movers-col h3 {
  margin: 0 0 0.5rem;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.mover-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  align-items: center;
}

.mover-row .delta {
  text-align: right;
  min-width: 3.5rem;
}

/* —— Inventory table —— */
.inv-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.inv-panel h2 {
  margin: 0;
  padding: 0.85rem 1rem;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.inv-table-wrap {
  overflow-x: auto;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.inv-table th {
  text-align: left;
  padding: 0.55rem 0.75rem;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

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

.inv-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.inv-table tr:hover td {
  background: var(--surface-2);
}

.inv-table tr.expanded td {
  background: var(--surface-2);
}

.card-cell {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 10rem;
}

.card-thumb {
  width: 36px;
  height: 50px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
}

.card-name {
  font-weight: 500;
}

.rarity {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.625rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.rarity.holo {
  border: none;
  color: #0a0a0b;
  background: var(--holo);
  background-size: 200% 200%;
  transition: background-position 0.35s var(--ease), transform 0.2s var(--ease);
}

.rarity.holo:hover {
  background-position: 100% 50%;
  transform: translateY(-1px);
}

.sparkline {
  width: 56px;
  height: 20px;
  display: block;
}

.inv-detail {
  display: none;
  padding: 0.75rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.inv-detail.open {
  display: block;
}

.inv-detail-chart {
  width: 100%;
  max-width: 480px;
  height: 80px;
}

.inv-detail-chart svg {
  width: 100%;
  height: 80px;
}

/* Mobile card list */
.inv-cards {
  display: none;
}

@media (max-width: 768px) {
  .dash-header {
    grid-template-columns: 1fr;
  }
  .dash-meta {
    text-align: left;
  }
  .stat-row {
    grid-template-columns: 1fr;
  }
  .dash-body {
    grid-template-columns: 1fr;
  }
  .watch-panel {
    position: static;
  }
  .watch-toggle {
    display: block;
  }
  .watch-panel .watch-list {
    display: none;
  }
  .watch-panel.open .watch-list {
    display: block;
  }
  .inv-table-wrap {
    display: none;
  }
  .inv-cards {
    display: block;
  }
  .inv-card {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
  }
  .inv-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .inv-card .nums {
    text-align: right;
    font-size: 0.8125rem;
  }
  .movers-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .movers-grid {
    grid-template-columns: 1fr;
  }
}

/* Stagger reveal */
.reveal {
  opacity: 0;
  transform: translateY(20px);
}

.reveal.is-visible {
  animation: reveal-in 0.5s var(--ease) forwards;
}

.reveal:nth-child(1) {
  animation-delay: 0ms;
}
.reveal:nth-child(2) {
  animation-delay: 60ms;
}
.reveal:nth-child(3) {
  animation-delay: 120ms;
}
.reveal:nth-child(4) {
  animation-delay: 180ms;
}
.reveal:nth-child(5) {
  animation-delay: 240ms;
}
.reveal:nth-child(6) {
  animation-delay: 300ms;
}

@keyframes reveal-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
  }
  .reveal.is-visible {
    animation: none;
  }
  .ticker-inner {
    animation: none;
    white-space: normal;
  }
}

/* —— Forms / auth / legacy cards —— */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

.card h1,
.card h2 {
  margin-top: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin: 0 0 0.25rem;
  letter-spacing: -0.03em;
}

label {
  display: block;
  margin: 0.5rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input,
textarea,
select,
button {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 0.75rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
}

button,
.btn {
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
}

button.secondary,
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.holo-btn {
  background: var(--holo);
  color: #0a0a0b;
  border: none;
}

.error {
  color: var(--down);
}
.ok {
  color: var(--up);
}

.disclosure {
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 2px solid;
  border-image: var(--holo) 1;
  padding-left: 0.75rem;
  margin: 1rem 0;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 500px) {
  .grid2 {
    grid-template-columns: 1fr;
  }
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 100% 0%, rgba(6, 182, 212, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(217, 70, 239, 0.06), transparent);
}

.auth-card {
  max-width: 400px;
  width: 100%;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin-top: 0;
}

.public-page header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
}

.public-page main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem;
}

pre.muted {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  overflow-x: auto;
}

.app-ad-slot {
  margin: 1.25rem 0 0;
  padding: 0.65rem 1rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  text-align: center;
  max-width: 728px;
}
.app-ad-label {
  margin: 0 0 0.35rem;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.app-ad-slot ins.adsbygoogle {
  max-height: 90px;
  overflow: hidden;
}
.app-ad-fallback {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}
