:root {
  --bg0: #f3f6f1;
  --bg1: #ffffff;
  --ink: #152018;
  --muted: #5f6f62;
  --line: #d7e0d4;
  --accent: #1f7a4d;
  --accent-soft: #e5f5eb;
  --accent-ink: #ffffff;
  --danger: #c2412d;
  --ok: #1f7a4d;
  --panel: rgba(255, 255, 255, 0.92);
  --shadow: 0 18px 40px rgba(28, 42, 32, 0.08);
  --radius: 18px;
  --font-display: "Schibsted Grotesk", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: var(--font-mono);
  background:
    radial-gradient(900px 520px at 8% -10%, #dcecdb 0%, transparent 55%),
    radial-gradient(700px 420px at 100% 0%, #e8efe4 0%, transparent 50%),
    linear-gradient(180deg, #f7faf5 0%, #eef3eb 100%);
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.shell {
  width: min(820px, calc(100% - 2rem));
  margin: 2.5rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  flex-wrap: wrap;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem 1.25rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

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

.panel-head h1,
.panel > h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel > h1 {
  margin-bottom: 0.9rem;
}

.section-title {
  margin: 1rem 0 0.7rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.balance-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.balance-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdf9;
  padding: 0.75rem 0.85rem;
}

.balance-card span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.balance-card strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
}

label,
.key-field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.key-field {
  width: min(420px, 100%);
  min-width: min(320px, 100%);
}

.key-field input {
  min-width: 0;
  width: 100%;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

button {
  border: 1px solid var(--line);
  background: #f7faf5;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

button.primary:hover:not(:disabled) {
  background: #176341;
  border-color: transparent;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.tab {
  flex: 1;
}

.tab.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.market-card {
  margin-top: 0.9rem;
  padding: 0.9rem;
  border-radius: 14px;
  border: 1px dashed var(--line);
  background: #f8fbf6;
}

.market-card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.market-card h2,
.market-card-head h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  line-height: 1.25;
}

.market-card-head .meta {
  margin-bottom: 0;
}

.orderbook-actions {
  display: flex;
  gap: 0.4rem;
}

.market-card .meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.7rem;
}

#marketFilter {
  margin-bottom: 0.65rem;
}

.event-market-list {
  display: grid;
  gap: 0.4rem;
  max-height: 320px;
  overflow: auto;
  padding-right: 0.15rem;
}

.event-market-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
  width: 100%;
  background: #fff;
}

.event-market-item .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
}

.event-market-item .yes {
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.78rem;
}

.prices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.inventory-box {
  margin-top: 0.85rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.inventory-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}

.inventory-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.inventory-head .meta {
  margin: 0;
}

.inventory-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.45rem;
}

.orderbook-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.95rem 0 0.35rem;
}

.orderbook-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.orderbook {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.ob-col {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.ob-title {
  padding: 0.45rem 0.65rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.ob-title.asks-title {
  color: var(--danger);
}

.ob-title.bids-title {
  color: var(--ok);
}

.ob-levels {
  display: grid;
}

.ob-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
}

.ob-row:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: transparent;
}

.ob-row .bar {
  position: absolute;
  inset: 0 auto 0 0;
  opacity: 0.14;
  pointer-events: none;
}

.ob-row.ask .bar {
  background: var(--danger);
}

.ob-row.bid .bar {
  background: var(--ok);
}

.ob-row span {
  position: relative;
  z-index: 1;
}

.ob-row span:last-child {
  text-align: right;
  color: var(--muted);
}

.price-pill {
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  background: #fff;
  border: 1px solid var(--line);
}

.price-pill strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.positions {
  display: grid;
  gap: 0.55rem;
}

.positions.empty,
.orders.empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.orders {
  display: grid;
  gap: 0.55rem;
}

.order-card {
  display: grid;
  gap: 0.3rem;
  padding: 0.8rem 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fbfdf9;
}

.order-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.order-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.98rem;
  line-height: 1.3;
}

.order-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.order-meta.mono {
  word-break: break-all;
  font-size: 0.7rem;
}

.cancel-order {
  padding: 0.45rem 0.7rem;
  white-space: nowrap;
}

.position-card {
  display: grid;
  gap: 0.35rem;
  padding: 0.8rem 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fbfdf9;
}

.position-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.98rem;
  line-height: 1.3;
}

.position-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.position-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.stat.pos strong {
  color: var(--ok);
}

.stat.neg strong {
  color: var(--danger);
}

.log {
  margin: 0.9rem 0 0;
  min-height: 4.5rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7faf5;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.8rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.log.ok {
  color: var(--ok);
}

.log.err {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .row,
  .grid,
  .prices,
  .position-stats,
  .balance-cards,
  .orderbook,
  .inventory-row {
    grid-template-columns: 1fr 1fr;
  }

  .top {
    align-items: stretch;
  }

  .key-field {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .grid,
  .prices,
  .position-stats,
  .balance-cards,
  .orderbook,
  .inventory-row {
    grid-template-columns: 1fr;
  }
}
