:root {
  color-scheme: dark;
  --bg: #07110f;
  --panel: #0c1815;
  --panel2: #12231e;
  --line: #203a32;
  --text: #edf7f3;
  --muted: #89a59b;
  --green: #18d69b;
  --red: #ff637a;
  --accent: #18d69b;
  --gold: #f3c969;
  --shadow: 0 18px 50px rgba(0, 0, 0, .32);
}

html { background: var(--bg); }
body {
  background:
    radial-gradient(circle at 12% -10%, rgba(24, 214, 155, .1), transparent 28rem),
    var(--bg);
}
body.market-dialog-open {
  position: fixed;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { transition: border-color .18s, background .18s, color .18s, transform .18s; }
button:active { transform: translateY(1px); }

#auth {
  margin-top: 10vh;
  background: linear-gradient(145deg, rgba(18, 35, 30, .98), rgba(8, 21, 17, .98));
  border-color: rgba(63, 116, 98, .55);
  box-shadow: var(--shadow);
}
#auth h1, header h1, .brand { color: var(--text); letter-spacing: -.03em; }
.brand-home { color: inherit; text-decoration: none; }
#auth h1::before, header h1::before, .brand::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 3px;
  background: var(--green);
  box-shadow: 0 0 18px rgba(24, 214, 155, .65);
  transform: rotate(45deg);
}
header h1::before { display: none; }
#auth button, button.primary { background: var(--green); color: #032018; }

header {
  min-height: 56px;
  height: auto;
  padding: 8px 16px;
  background: rgba(7, 17, 15, .92);
  border-color: var(--line);
}
header h1 { font-size: 17px; }
.badge { border: 1px solid var(--line); background: rgba(18, 35, 30, .72); }
.market-trigger, input, select {
  background: #0b1814;
  border-color: var(--line);
}
.market-trigger { min-width: 220px; border-radius: 10px; }
header .market-trigger {
  width: 38px;
  min-width: 38px;
  height: 38px;
  border-radius: 7px;
}
.market-trigger:hover, .market-trigger.open { border-color: var(--green); background: var(--panel2); }
.market-panel {
  background: #091612;
  border-color: #295044;
  box-shadow: var(--shadow);
}
.market-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, .72);
}
.market-row.selected { background: rgba(24, 214, 155, .1); }
.symtab.active, .type-toggle button.active { border-color: var(--green); }
.link { text-decoration: none; }
.link:hover { color: var(--green); }

.wrap { grid-template-columns: minmax(0, 58fr) minmax(220px, 19fr) minmax(280px, 23fr); }
.card, .market-overview, .trade-order-col { background: var(--panel); }
.market-overview { min-height: 78px; padding: 10px 16px; }
.coin-mark { background: linear-gradient(145deg, #20e6a8, #0e8d68); color: #032018; }
.overview-price strong { font-size: 21px; }
.krw-price { color: var(--muted); font-size: 10px; margin-top: 3px; }
.market-overview .cinfo { justify-content: flex-start; gap: 24px; }
.market-overview .cinfo b { font-size: 12px; }

.terminal-tabs, .chart-tools, .trade-book-col h3, .trade-book-col .book-head {
  background: rgba(6, 15, 13, .24);
}
.terminal-tab.active, .portfolio-tab.active { border-bottom-color: var(--green); }
.metric {
  background: linear-gradient(145deg, rgba(18, 35, 30, .95), rgba(10, 25, 20, .95));
  border: 1px solid var(--line);
}
.metric .v { margin-top: 3px; }
.side-toggle { margin-top: 0; }
.side-toggle .buy-side.active { color: var(--green); background: rgba(24, 214, 155, .08); border-color: var(--green); }
.side-toggle .sell-side.active { color: var(--red); background: rgba(255, 99, 122, .08); border-color: var(--red); }
.type-toggle { gap: 0; padding: 3px; border-radius: 8px; background: #081510; }
.type-toggle button { background: transparent; border: 1px solid transparent; }
.type-toggle button.active { background: var(--panel2); color: var(--text); }
.quick-buttons { grid-template-columns: repeat(5, 1fr); }
.quick-buttons.leverage-presets { grid-template-columns: repeat(6, 1fr); }
.quick-buttons button:hover, .quick-buttons button.active { color: var(--green); border-color: var(--green); }
.margin-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #081510;
}
.margin-mode span { color: var(--muted); font-size: 11px; }
.margin-mode button { padding: 4px 8px; color: var(--text); background: var(--panel2); border: 1px solid var(--line); }
.margin-mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.margin-mode .margin-mode-options button { min-width: 62px; border: 0; background: transparent; color: var(--muted); }
.margin-mode .margin-mode-options button.active { background: var(--green); color: #032018; box-shadow: 0 2px 8px rgba(14,203,129,.2); }
.margin-mode .margin-mode-options button:disabled { cursor: not-allowed; opacity: .45; }
.spot-only-hidden { display: none !important; }
.order-summary { background: #07120f; }
.buy { background: var(--green); color: #032018; }
.sell { background: var(--red); color: #26060c; }
.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0 12px 12px;
}
.summary-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
}
.summary-card span { display: block; color: var(--muted); font-size: 10px; }
.summary-card b { display: block; margin-top: 4px; font-size: 15px; }

.layout { grid-template-columns: 250px minmax(0, 1fr); }
.side { background: rgba(8, 21, 17, .96); border-color: var(--line); padding-top: 24px; }
.brand { font-size: 18px; }
.nav { gap: 3px; padding: 8px; }
.nav button { border: 1px solid transparent; border-radius: 8px; padding: 11px 12px; }
.nav button:hover { color: var(--text); background: rgba(18, 35, 30, .6); }
.nav button.active { color: var(--green); background: rgba(24, 214, 155, .09); border-color: rgba(24, 214, 155, .2); }
.main { width: 100%; max-width: 1500px; margin: 0 auto; padding: 32px; }
.head h1 { font-size: 25px; letter-spacing: -.035em; }
.card, .panel {
  background: linear-gradient(145deg, rgba(14, 29, 24, .98), rgba(9, 21, 17, .98));
  border-color: var(--line);
  border-radius: 12px;
}
.cards { gap: 12px; }
.card { padding: 17px; }
.panel { padding: 18px; }
.panel h2 { font-size: 15px; }
.bar i { background: linear-gradient(90deg, #13b985, #42edb6); }
.status { border: 1px solid var(--line); }

@media (max-width: 1100px) {
  .wrap { grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "overview order" "chart order" "book order" "portfolio portfolio"; }
  .market-overview { flex-wrap: wrap; }
  .trade-book-col { min-height: 520px; }
}
@media (max-width: 900px) {
  body > .market-panel {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    border: 0;
    border-radius: 0;
    overflow: hidden;
    overscroll-behavior: contain;
  }
  body > .market-panel .market-panel-head {
    padding-top: 12px;
  }
  body > .market-panel .market-list {
    min-height: 0;
    max-height: none;
    flex: 1;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  body > .market-panel .market-panel-foot {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "symbols symbols" "overview overview" "order book" "chart chart";
    grid-template-rows: 56px 64px minmax(0, 1fr) 42px;
  }
  .market-overview { min-height: 0; align-items: center; flex-wrap: nowrap; }
  .trade-book-col { min-height: 0; }
  .market-overview .cinfo { flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .summary-strip { grid-template-columns: 1fr; }
  .layout { display: block; }
  .side { position: sticky; top: 0; z-index: 20; padding: 10px 12px; background: rgba(7, 17, 15, .96); }
  .nav { flex-direction: row; padding: 5px 0 0; }
  .nav button { border-radius: 7px; }
  .main { padding: 18px 14px; }
}
@media (max-width: 900px) and (max-height: 750px) {
  .wrap {
    grid-template-areas: "symbols symbols" "overview overview" "order book" "chart chart";
    grid-template-rows: 52px 60px minmax(0, 1fr) 40px;
  }
}
@media (max-width: 560px) {
  header { padding: 8px 10px; }
  .spacer { width: 100%; overflow-x: auto; justify-content: flex-start; }
  .cards { grid-template-columns: 1fr; }
  .quick-buttons.leverage-presets { grid-template-columns: repeat(3, 1fr); }
  .head { align-items: flex-start; gap: 12px; }
  .head h1 { font-size: 21px; }
  th, td { padding: 8px 10px; }
}
