:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #18202a;
  --line: #232d3a;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #50d2c1;
  --up: #2ebd85;
  --down: #f6465d;
  --gold: #f0b90b;
  --silver: #c0c7d1;
  --bronze: #cd7f32;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
header.top h1 { margin: 0; font-size: 18px; font-weight: 600; }
header.top .spacer { flex: 1; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls label { color: var(--muted); font-size: 12px; }
select, button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
}
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

main { padding: 16px 20px 40px; }

.status { color: var(--muted); padding: 40px 0; text-align: center; }
.status.error { color: var(--down); }

/* 가로 5열 */
.board {
  position: relative; /* 카드 offsetLeft 기준 */
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), minmax(260px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 700;
  background: var(--panel-2);
  margin-right: 8px;
}
.rank-1 { background: var(--gold); color: #111; }
.rank-2 { background: var(--silver); color: #111; }
.rank-3 { background: var(--bronze); color: #111; }
.who { display: flex; align-items: center; min-width: 0; }
.who .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .addr { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-top: 12px;
}
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 14px; }

.section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section h3 {
  display: flex;
  justify-content: space-between;
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.empty { color: var(--muted); font-size: 12px; }

.item {
  padding: 8px 0;
  border-top: 1px dashed var(--line);
}
.item:first-of-type { border-top: 0; padding-top: 0; }
.item .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item .coin { font-weight: 600; }
.item .sub { font-size: 12px; color: var(--muted); }

.pill {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  font-weight: 600;
}
.pill.long { background: rgba(46, 189, 133, .15); color: var(--up); }
.pill.short { background: rgba(246, 70, 93, .15); color: var(--down); }
.pill.lev { background: var(--panel-2); color: var(--muted); }

.more {
  display: block;
  margin-top: 8px;
  padding: 6px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}
.more:hover { border-color: var(--accent); text-decoration: none; }

.card-foot { margin-top: auto; padding: 10px 14px; border-top: 1px solid var(--line); }
.card-foot a { font-size: 12px; }

/* 상세 페이지 */
.detail-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-bottom: 16px; }
.detail-head h2 { margin: 0; font-size: 20px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.panel h3 { margin: 0; padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: 12px; font-weight: 500; color: var(--muted); }
th:first-child, td:first-child { text-align: left; }
tr:last-child td { border-bottom: 0; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; padding: 14px; }

/* 로그인 */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
}
.login h1 { margin: 12px 0 4px; font-size: 18px; }
.login p { margin: 0 0 16px; }
.login input[type=text], .login input[type=password] {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 16px; /* iOS 자동 확대 방지 */
}
.login input:focus { outline: none; border-color: var(--accent); }
.login .login-error { color: var(--down); font-size: 13px; min-height: 20px; margin: 8px 0; }
.login button { width: 100%; padding: 12px; background: var(--accent); color: var(--bg); border: 0; font-weight: 700; }

/* 헤더 계정 영역 */
.account { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.account .who-am-i { color: var(--muted); }
.account a.admin-link { font-weight: 600; }

/* 관리자 */
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted); }
.tag.admin { background: rgba(80, 210, 193, .15); color: var(--accent); }
.tag.fail { background: rgba(246, 70, 93, .15); color: var(--down); }
.tag.ok { background: rgba(46, 189, 133, .15); color: var(--up); }
td.ua { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
td.left, th.left { text-align: left; }

/* 체결 기록 */
.collector { margin: 0 0 12px; font-size: 12px; }
.small { font-size: 12px; }
.trades-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.trader-list { display: flex; flex-direction: column; gap: 6px; }
.trader-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.trader-item.active { border-color: var(--accent); background: var(--panel-2); }
.trader-item .row { display: flex; justify-content: space-between; gap: 8px; }
.trader-item .sub { margin-top: 4px; font-size: 12px; color: var(--muted); }

/* 모바일: 카드 한 장씩 스와이프, 위에 순위 탭과 화살표 */
.ranknav { display: none; }

@media (max-width: 760px) {
  header.top { padding: 12px 16px; gap: 10px; }
  header.top h1 { font-size: 16px; }
  header.top .spacer { display: none; }
  #meta { width: 100%; font-size: 12px; }
  .controls { width: 100%; }
  .controls select { flex: 1 1 auto; min-width: 0; }

  main { padding: 0 0 32px; }
  .status { padding: 40px 16px; }

  .ranknav {
    display: flex;
    align-items: center;
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 8px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }
  .ranknav .arrow { width: 36px; height: 36px; padding: 0; font-size: 22px; line-height: 1; flex: 0 0 auto; }
  .chips { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; min-width: 34px; height: 34px; padding: 0 8px; border-radius: 17px; }
  .chip.active { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 700; }

  .board {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 100%;
    gap: 16px;
    padding: 12px 16px;
    scroll-padding-inline: 16px;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .board::-webkit-scrollbar { display: none; }
  .card { scroll-snap-align: start; }

  .detail-head .num { word-break: break-all; }
  th, td { padding: 8px 10px; }
  /* 표를 옆으로 밀어도 종목 열은 고정 */
  th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; background: var(--panel); }
  .summary { grid-template-columns: 1fr 1fr; }
  main > #content { padding: 16px; }
  .trades-layout { grid-template-columns: 1fr; padding: 0 16px; }
  .trader-list { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .trader-item { flex: 0 0 230px; }
  .collector { padding: 12px 16px 0; }
}
