:root {
    color-scheme: dark;
    --bg: #080b13;
    --panel: rgba(20, 25, 39, 0.92);
    --border: #2a3144;
    --text: #f4f6fb;
    --muted: #929bb0;
    --accent: #7667ff;
    --accent-strong: #8c80ff;
    --green: #48d597;
    --red: #ff667d;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: radial-gradient(circle at 85% 0%, rgba(118, 103, 255, 0.2), transparent 32rem), var(--bg);
    font-family: Inter, Pretendard, "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 1rem clamp(1rem, 4vw, 3.5rem);
    border-bottom: 1px solid var(--border);
    background: rgba(8, 11, 19, 0.9);
    backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 0.8rem; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 2.7rem; height: 2.7rem; border-radius: 0.85rem; background: linear-gradient(145deg, var(--accent-strong), #5143dc); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 0.15rem; color: var(--muted); font-size: 0.72rem; }
.topbar-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
.topbar-controls.collapsed .key-control { display: none; }
.topbar-meta { display: flex; align-items: center; gap: 0.65rem; }
.build-version { color: #697287; font: 0.64rem ui-monospace, monospace; }
.page-link, .login-panel-toggle { color: var(--muted); border: 0; background: transparent; font-size: 0.7rem; text-decoration: none; cursor: pointer; }
.page-link:hover, .login-panel-toggle:hover { color: var(--text); }
.key-control { display: grid; grid-template-columns: auto minmax(18rem, 30rem) auto auto; align-items: center; gap: 0.5rem; }
.key-control > label { color: var(--muted); font-size: 0.76rem; font-weight: 700; }
.remember-key { grid-column: 2; display: flex; align-items: center; gap: 0.4rem; }
.remember-key input { width: auto; min-height: auto; }

main { width: min(1280px, calc(100% - 2rem)); margin: 0 auto; padding: 2.5rem 0 5rem; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 1.3rem; }
.hero h1 { margin: 0; font-size: clamp(2.3rem, 6vw, 4.5rem); letter-spacing: -0.06em; }
.hero p:last-child { margin: 0.5rem 0 0; color: var(--muted); }
.eyebrow { margin: 0 0 0.4rem; color: var(--accent-strong); font-size: 0.7rem; font-weight: 850; letter-spacing: 0.14em; }
.market-badge { padding: 0.45rem 0.65rem; color: #d4ceff; border: 1px solid rgba(140, 128, 255, 0.4); border-radius: 0.5rem; font-size: 0.72rem; }

.panel { padding: 1.25rem; border: 1px solid var(--border); border-radius: 1rem; background: var(--panel); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
h2, h3 { margin: 0; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.create-panel { margin-bottom: 1rem; }
#account-form { display: grid; grid-template-columns: 1.2fr 0.8fr repeat(5, 0.8fr) auto; align-items: end; gap: 0.7rem; }
label { display: block; color: var(--muted); font-size: 0.73rem; font-weight: 700; }
input, select {
    width: 100%;
    min-height: 2.55rem;
    margin-top: 0.4rem;
    padding: 0.6rem 0.75rem;
    color: var(--text);
    border: 1px solid #343c51;
    border-radius: 0.6rem;
    outline: none;
    background: #0e1320;
}
input:focus, select:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(118, 103, 255, 0.14); }
.access-key-field { grid-column: span 2; min-width: 15rem; margin: 0; padding: 0.55rem 0.7rem; border: 1px solid #343c51; border-radius: 0.65rem; }
.access-key-field legend { padding: 0 0.3rem; color: var(--muted); font-size: 0.68rem; }
.access-key-options { display: flex; min-height: 2.2rem; align-items: center; flex-wrap: wrap; gap: 0.45rem; }
.access-key-option { display: inline-flex; max-width: 100%; padding: 0.42rem 0.58rem; align-items: center; gap: 0.38rem; border: 1px solid #343c51; border-radius: 999px; background: #111725; cursor: pointer; }
.access-key-option:has(input:checked) { color: #d8d3ff; border-color: var(--accent); background: rgba(118, 103, 255, 0.14); }
.access-key-option input { width: auto; min-height: auto; margin: 0; accent-color: var(--accent); }
.access-key-option span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.access-management-panel #access-key-form { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.7rem; }
.button { min-height: 2.55rem; padding: 0.58rem 0.9rem; color: var(--text); border: 1px solid transparent; border-radius: 0.6rem; cursor: pointer; font-weight: 750; }
.button:disabled { cursor: wait; opacity: 0.55; }
.button.primary { background: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.quiet { border-color: #343c51; background: #161c2a; }
.button.compact { min-height: 2rem; padding: 0.35rem 0.55rem; font-size: 0.72rem; }
.status { padding: 0.32rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 800; white-space: nowrap; }
.status.neutral { color: var(--muted); background: #171d2a; }
.status.ok { color: #b9f9d9; background: rgba(72, 213, 151, 0.13); }
.status.error { color: #ffd1d8; background: rgba(255, 102, 125, 0.13); }
.form-message { min-height: 1.2rem; margin: 0.6rem 0 0; color: var(--muted); font-size: 0.76rem; }
.form-message.error { color: var(--red); }
.form-message.success { color: var(--green); }

.account-workspace { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 1rem; align-items: start; }
.account-list-panel { position: sticky; top: 7rem; }
.account-list { display: grid; gap: 0.55rem; }
.account-card { width: 100%; padding: 0.8rem; color: var(--text); border: 1px solid #30384d; border-radius: 0.7rem; background: #101624; text-align: left; cursor: pointer; }
.account-card:hover, .account-card.active { border-color: var(--accent); background: rgba(118, 103, 255, 0.1); }
.account-card strong, .account-card span { display: block; }
.account-card span { margin-top: 0.3rem; color: var(--muted); font-size: 0.7rem; }
.empty-state { margin: 0; padding: 1.7rem 0.8rem; color: var(--muted); text-align: center; font-size: 0.8rem; }
.account-detail { min-width: 0; }
.detail-title { display: flex; align-items: center; justify-content: space-between; padding: 0.4rem 0.2rem 0.9rem; }
.account-id-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.45rem; color: var(--muted); font-size: 0.68rem; }
.account-id-row code { color: #b8c0d3; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.copy-id-button { min-height: 1.65rem; padding: 0.18rem 0.45rem; color: var(--muted); border: 1px solid #343c51; border-radius: 0.4rem; background: #131927; cursor: pointer; font-size: 0.65rem; }
.copy-id-button:hover { color: var(--text); border-color: var(--accent); }
.asset-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.7rem; }
.asset-summary > div { padding: 1rem; border: 1px solid var(--border); border-radius: 0.8rem; background: #101624; }
.asset-summary span, .asset-summary strong { display: block; }
.asset-summary span { color: var(--muted); font-size: 0.7rem; }
.asset-summary strong { margin-top: 0.45rem; font-size: 1.05rem; }
.up { color: var(--red); }
.down { color: #67a0ff; }
.inner-panel { margin-top: 1rem; }
.hint { color: var(--muted); font-size: 0.72rem; }
.table-wrap { overflow-x: auto; border: 1px solid #252c3c; border-radius: 0.75rem; background: #0d121e; }
table { width: 100%; min-width: 740px; border-collapse: collapse; }
th, td { padding: 0.7rem; border-bottom: 1px solid #222a3a; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.68rem; }
td { font-size: 0.78rem; }
tbody tr:last-child td { border-bottom: 0; }
.trade-side { display: inline-flex; justify-content: center; min-width: 2.7rem; padding: 0.22rem 0.42rem; border-radius: 999px; font-size: 0.7rem; font-weight: 800; }
.trade-side.buy { color: #ffd4db; background: rgba(255, 102, 125, 0.15); }
.trade-side.sell { color: #d1e3ff; background: rgba(92, 157, 255, 0.15); }
#order-form { display: grid; grid-template-columns: 1fr 0.7fr 0.7fr 2fr auto; align-items: end; gap: 0.7rem; }
.pagination { display: flex; justify-content: center; gap: 0.35rem; margin-top: 0.8rem; }
.pagination button { min-width: 2rem; min-height: 2rem; color: var(--muted); border: 1px solid #343c51; border-radius: 0.45rem; background: #131927; cursor: pointer; }
.pagination button.active { color: var(--text); border-color: var(--accent); }
.pagination button:disabled { opacity: 0.35; }

@media (max-width: 1100px) {
    #account-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .asset-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
    .topbar, .hero { align-items: stretch; flex-direction: column; }
    .topbar-controls { align-items: stretch; }
    .topbar-meta { justify-content: flex-end; }
    .key-control { grid-template-columns: 1fr auto auto; }
    .key-control > label { grid-column: 1 / -1; }
    .remember-key { grid-column: 1 / -1; }
    .account-workspace { grid-template-columns: 1fr; }
    .account-list-panel { position: static; }
    .account-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #order-form { grid-template-columns: 1fr 1fr; }
    .comment-field { grid-column: 1 / -1; }
    .access-management-panel #access-key-form { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
    main { width: min(100% - 1rem, 1280px); padding-top: 1.4rem; }
    .topbar { padding: 0.85rem; }
    .key-control { display: block; }
    .key-control > * { margin-top: 0.45rem; }
    #account-form, .asset-summary { grid-template-columns: 1fr 1fr; }
    #account-form .button { grid-column: 1 / -1; }
    .access-key-field { grid-column: 1 / -1; min-width: 0; }
    .account-list { grid-template-columns: 1fr; }
}
