/* The shell and the shared components: header, buttons, panels, tabs, the segmented control, avatars, tables, the stat
   strip, skeletons and empty states. Every value comes from tokens.css; each screen adds its own sheet (markets.css,
   profile.css). */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; font: var(--t-md); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font: 600 var(--t-2xl); letter-spacing: -.02em; overflow-wrap: anywhere; text-wrap: balance; }
h2 { font: 600 var(--t-xl); letter-spacing: -.01em; }
h3 { font: 600 var(--t-lg); }
p { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); }
[hidden] { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 10; background: var(--veil); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.top-in { max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); display: flex; align-items: center; gap: var(--s-6); height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); flex: none; text-decoration: none; }
.brand .mark { width: 28px; height: 28px; flex: none; color: var(--accent); } /* the Krater mark (brand/krater/logo) */
.brand .word { font: 800 24px/1 var(--font-brand); font-stretch: 125%; letter-spacing: -.035em; }
#nav { display: flex; gap: var(--s-5); flex: 1; min-width: 0; height: 100%; }
#nav a { display: flex; align-items: center; height: 100%; color: var(--muted); font-weight: 500; text-decoration: none; white-space: nowrap; box-shadow: inset 0 -2px 0 transparent; transition: color .12s; }
#nav a:hover { color: var(--text); }
#nav a[aria-current="page"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--text); }
#connect { flex: none; gap: .3em; }

/* buttons: .btn is the primary (one per screen); .ghost is quiet; .sm is the compact size used in rows */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); height: 40px; padding: 0 var(--s-4); border: 0; border-radius: var(--radius-sm);
  font: 600 var(--t-md); white-space: nowrap; text-decoration: none; cursor: pointer; background: var(--accent); color: var(--accent-ink); transition: filter .12s, background .12s; }
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: var(--panel-2); color: var(--text); }
.btn.ghost:hover { filter: none; background: var(--panel-3); }
.btn.sm { height: 32px; padding: 0 var(--s-3); font: 600 var(--t-sm); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

/* page column */
#screen { max-width: var(--page); margin: 0 auto; padding: var(--s-6) var(--gutter) var(--s-7); }
.panel { background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); padding: var(--s-5); min-width: 0; }
.page-head { display: grid; gap: var(--s-2); margin-bottom: var(--s-5); }
.page-head p { color: var(--muted); max-width: 72ch; }
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin: 0 0 var(--s-3); }
.section-h h2 { font: 600 var(--t-lg); }
.section-h small { color: var(--faint); font: var(--t-sm); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font: var(--t-sm); }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.005em; white-space: nowrap; }
.up { color: var(--up); } .down { color: var(--down); }
.noscript { padding: var(--s-4); }

/* live dot: a steady dot with one ring going out from it */
.dot { position: relative; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--down); flex: none; }
.dot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: inherit; animation: ping 2s cubic-bezier(0, 0, .2, 1) infinite; }
@keyframes ping { 75%, 100% { transform: scale(2.6); opacity: 0; } }
@keyframes pulse { 50% { opacity: .3; } }

/* live numbers (lib/motion.js): changed digits roll in, the cell flashes once, a pot shows what just landed */
.roll { display: inline-block; animation: roll-up .45s var(--ease); }
.roll.dn { animation-name: roll-down; }
@keyframes roll-up { from { transform: translateY(.55em); opacity: 0; } }
@keyframes roll-down { from { transform: translateY(-.55em); opacity: 0; } }
.flash-up, .flash-down { border-radius: 4px; animation: flash-up 1.4s ease-out; }
.flash-down { animation-name: flash-down; }
@keyframes flash-up { from { background: color-mix(in srgb, var(--up) 22%, transparent); } }
@keyframes flash-down { from { background: color-mix(in srgb, var(--down) 22%, transparent); } }
[data-delta] { position: relative; }
.delta-tag { position: absolute; right: 0; bottom: 100%; font: 600 var(--t-xs); color: var(--up); pointer-events: none; animation: delta 2.4s ease-out forwards; }
@keyframes delta { from { opacity: 0; transform: translateY(4px); } 15% { opacity: 1; transform: none; } 70% { opacity: 1; } to { opacity: 0; transform: translateY(-4px); } }

/* trader colours and avatars */
[data-s="0"] { --c: var(--s0); } [data-s="1"] { --c: var(--s1); } [data-s="2"] { --c: var(--s2); } [data-s="3"] { --c: var(--s3); }
[data-s="4"] { --c: var(--s4); } [data-s="5"] { --c: var(--s5); } [data-s="6"] { --c: var(--s6); } [data-s="7"] { --c: var(--s7); }
.av { width: 32px; height: 32px; border-radius: 50%; flex: none; display: inline-grid; place-items: center; object-fit: cover;
  font: 600 13px/1 var(--font); color: var(--c, var(--muted)); background: color-mix(in srgb, var(--c, var(--muted)) 16%, var(--panel-2)); }
.av.sm { width: 24px; height: 24px; font-size: 11px; }
.av.lg { width: 40px; height: 40px; font-size: 16px; }
.swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c, var(--muted)); }

/* underline tabs */
.tabs { display: flex; gap: var(--s-5); border-bottom: 1px solid var(--line); margin-bottom: var(--s-5); overflow-x: auto; scrollbar-width: none; }
.tabs button { position: relative; height: 44px; padding: 0; border: 0; background: none; font: 500 var(--t-md); color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--text); }

/* segmented control (1D 7D 30D) */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--radius-sm); background: var(--panel-2); }
.seg button { height: 28px; min-width: 44px; padding: 0 var(--s-3); border: 0; border-radius: 6px; background: transparent; font: 600 var(--t-xs); color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--panel-3); color: var(--text); }

/* stat strip: label over value, cells split by hairlines */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-4) 0; }
.stat { padding: 0 var(--s-5); border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { padding-left: 0; border-left: 0; }
.stat .k { font: var(--t-sm); color: var(--muted); }
.stat .v { margin-top: var(--s-1); font: 600 var(--t-xl); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .d { margin-top: 2px; font: var(--t-xs); color: var(--faint); }

/* tables: numbers right-aligned */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 0 var(--s-3) var(--s-2); font: 500 var(--t-xs); color: var(--faint); white-space: nowrap; border-bottom: 1px solid var(--line); }
.table td { padding: var(--s-3); border-bottom: 1px solid var(--line); font: var(--t-md); vertical-align: middle; }
.table :is(th, td):first-child { padding-left: 0; } .table :is(th, td):last-child { padding-right: 0; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }

/* skeletons: shaped like what they stand in for */
.sk { display: block; height: 14px; border-radius: 6px; background: var(--panel-2); animation: pulse 1.6s ease-in-out infinite; }
.sk.w40 { width: 40%; } .sk.w60 { width: 60%; } .sk.w80 { width: 80%; } .sk.h28 { height: 28px; } .sk.h200 { height: 200px; }

/* empty and error states: heading, one line, one button */
.empty { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-7) var(--s-5); text-align: center; }
.empty h2 { font: 600 var(--t-lg); }
.empty p { color: var(--muted); max-width: 44ch; }
.empty .btn { margin-top: var(--s-3); }

@media (max-width: 720px) {
  :root { --gutter: 16px; }
  .top-in { flex-wrap: wrap; height: auto; padding-top: var(--s-3); gap: 0 var(--s-3); }
  #connect { margin-left: auto; height: 36px; padding: 0 var(--s-3); font-size: 13px; }
  #nav { order: 3; flex: 1 0 100%; height: 44px; gap: var(--s-5); }
  #screen { padding-top: var(--s-5); }
  h1 { font-size: 24px; line-height: 30px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { padding-left: 0; border-left: 0; }
}
@media (max-width: 360px) { .wide { display: none; } }
@media (prefers-reduced-motion: reduce) { .dot::after, .sk, .roll, .flash-up, .flash-down, .delta-tag { animation: none; } }

/* preview: the markets and bets are samples until the contracts are deployed (lib/data.js); quiet, never alarming */
.preview-tag { flex: none; padding: 3px 8px; border: 1px solid var(--line-2); border-radius: 999px; font: 500 var(--t-xs); color: var(--muted); white-space: nowrap; }
@media (max-width: 720px) { .preview-tag { padding: 2px 6px; } }
