/* ================================
   CSS Base & Design Tokens
================================ */
:root {
    --app-max-width: 1400px;
    --page-bg: radial-gradient(circle at 15% 15%, #fff 0%, #f4f6fb 46%, #e2e8f0 85%);
    --surface: #fff;
    --surface-muted: #f8fafc;
    --border-soft: rgba(15, 23, 42, 0.06);
    --border-subtle: rgba(15, 23, 42, 0.025);
    --border-faint: rgba(15, 23, 42, 0.02);
    --primary: #2563eb;
    --primary-soft: rgba(37, 99, 235, 0.13);
    --text: #0f172a;
    --text-muted: #64748b;
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --radius-lg: 22px;
    --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.07);
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.11);
    --copy-btn-bg: #eef2ff;
    --copy-btn-bg-hover: #b2c7f9;
}

*,
*::before,
*::after { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 1.7rem;
    font-family: var(--font-sans);
    background: var(--page-bg);
    color: var(--text);
}

code { font-family: var(--font-mono); font-size: 0.6rem; }

.app-warning,
.topbar,
.container,
footer,
.footer-notice {
    width: min(var(--app-max-width), 96vw);
    margin: 0 auto;
}

/* ================================
   Header / Top Bar
================================ */
.topbar {
    margin: 1.35rem auto 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}
.topbar-title { display: flex; gap: 0.65rem; align-items: center; }
.topbar h1 { margin: 0; font-size: clamp(1.3rem, 3.3vw, 1.7rem); }
.topbar small { color: var(--text-muted); font-size: 0.68rem; }
.topbar-nav { display: flex; gap: 0.4rem; }
.topbar-link {
    background: transparent; border: 1px solid transparent; border-radius: 999px;
    padding: 0.28rem 0.7rem 0.33rem; font-size: 0.68rem; color: var(--text);
    text-decoration: none; transition: background 0.1s, border 0.1s, box-shadow 0.1s;
}
.topbar-link:hover { background: rgba(255, 255, 255, 0.3); }
.topbar-link.is-active { border-color: rgba(15, 23, 42, 0.05); background: #fff; box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05); }

/* ================================
   Notices / Footer
================================ */
.app-warning {
    margin-top: 0.7rem; padding: 0.4rem 0.65rem 0.45rem; background: #fff5f5; border: 1px solid #ffe4e6;
    border-radius: 14px; color: #b91c1c; font-size: 0.63rem; line-height: 1.4; text-align: center;
}
.footer-notice { margin-top: 1rem; text-align: center; }
footer { margin-top: 1.15rem; font-size: 0.7rem; color: var(--text-muted); }

/* ================================
   App Shell
================================ */
.container {
    position: relative; margin-top: 0.5rem; padding: 1.3rem clamp(1rem, 2.1vw, 1.6rem) 1.6rem;
    background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.page-desc { margin: 0 0 1.1rem; font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }

/* ================================
   Layout Helpers
================================ */
.grid { display: grid; gap: 1.05rem; }
.grid.grid-split-lg { grid-template-columns: 1.15fr 0.85fr; }
.margin-small-top { margin-top: 0.2rem; }

/* ================================
   Forms & Fields
================================ */
.field {
    position: relative; display: flex; flex-direction: column; gap: 0.55rem;
    padding: 0.8rem 0.85rem 0.9rem; background: var(--surface-muted);
    border: 1px solid var(--border-faint); border-radius: 16px;
}
.field label { display: flex; align-items: center; gap: 0.35rem; font-weight: 600; font-size: 0.78rem; }
.field small { color: var(--text-muted); line-height: 1.4; }

textarea,
input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"] {
    width: 100%; padding: 0.55rem 0.65rem 0.6rem; font-size: 0.82rem; color: var(--text);
    background: #fff; border: 1px solid var(--border-soft); border-radius: 13px; outline: none;
    transition: border 0.12s, box-shadow 0.12s, background 0.12s;
}
textarea {
    min-height: 120px; max-height: 240px; resize: vertical; font-family: var(--font-mono);
}
textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="search"]:focus {
    border-color: rgba(37, 99, 235, 0.85); box-shadow: var(--focus-ring); background: #fff;
}

.options-inline { display: flex; gap: 0.55rem; }
.options-inline .small-field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 30%; flex: 1; }
.label-small { font-size: 0.68rem; font-weight: 600; }
.label-passphrase { margin-top: 0.3rem; }

.mnemonic-select-wrapper { display: flex; gap: 0.4rem; align-items: center; flex-wrap: nowrap; }
.mnemonic-select {
    padding: 0.35rem 0.5rem; font-size: 0.7rem; background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.07); border-radius: 999px;
}

/* ================================
   Mode Switcher
================================ */
.mode-switcher {
    display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.8rem;
}
.mode-btn {
    appearance: none; border: 1px solid rgba(15,23,42,0.07); background: #fff; color: var(--text);
    padding: 0.4rem 0.9rem; font-weight: 600; font-size: 0.78rem; border-radius: 999px; cursor: pointer;
}
.mode-btn.is-active { background: var(--primary); color: #fff; border-color: transparent; box-shadow: 0 12px 28px rgba(37,99,235,0.25); }
.mode-panel { display: none; }
.mode-panel.is-visible { display: block; }

/* ================================
   Buttons
================================ */
.buttons-row {
    display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; align-items: center;
}
.btn {
    appearance: none; display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.52rem 1.2rem 0.58rem; border: none; border-radius: 999px;
    background: var(--primary); color: #fff; font-weight: 600; font-size: 0.8rem;
    cursor: pointer; white-space: nowrap; box-shadow: 0 12px 28px rgba(37, 99, 235, 0.25);
    transition: transform 0.085s, box-shadow 0.085s, background 0.1s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 16px 30px rgba(37, 99, 235, 0.25); }
.btn.secondary {
    background: var(--copy-btn-bg); color: var(--text); border: 1px solid rgba(15, 23, 42, 0.06); box-shadow: none;
}
.btn.secondary:hover { background: var(--copy-btn-bg-hover); transform: translateY(-1px); box-shadow: none; }

.copy-btn {
    position: absolute; top: 12px; right: 12px; display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.25rem 0.7rem; background: var(--copy-btn-bg); color: var(--text); font-size: 0.7rem;
    border: 1px solid rgba(15, 23, 42, 0.06); border-radius: 999px; cursor: pointer; transition: background 0.1s, transform 0.1s;
}
.copy-btn:hover { background: var(--copy-btn-bg-hover); transform: translateY(-1px); }
.copy-btn.tiny { position: static; padding: 0.12rem 0.5rem 0.22rem; background: #fff; font-size: 0.63rem; }

/* ================================
   Cards / Docs / Results
================================ */
.doc-card {
    margin-top: 1.25rem; padding: 0.85rem 0.85rem 0.7rem; background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.045); border-radius: 16px;
}
.results-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.85rem; margin-top: 0.7rem; }
.doc-box { display: flex; flex-direction: column; gap: 0.4rem; min-height: 260px; padding: 0.5rem 0.6rem 0.6rem; background: #f8fafc; border: 1px solid var(--border-subtle); border-radius: 14px; }
.box-header { display: flex; justify-content: space-between; align-items: center; gap: 0.35rem; }
.doc-box h3 { margin: 0; font-size: 0.73rem; display: flex; gap: 0.35rem; align-items: center; }
.badge { padding: 0.2rem 0.6rem 0.3rem; background: var(--primary-soft); color: #1d4ed8; border-radius: 999px; font-size: 0.58rem; font-weight: 600; }
.path-info { margin: 0; font-size: 0.65rem; color: var(--text-muted); }

.master-keys { display: grid; gap: 0.35rem; }
.master-keys .mk-row { display: grid; grid-template-columns: 0.3fr 1fr auto; gap: 0.35rem; align-items: center; }
.master-keys label { font-size: 0.64rem; font-weight: 600; color: var(--text-muted); }

.table-wrapper { background: #fff; border: 1px solid rgba(15, 23, 42, 0.015); border-radius: 11px; overflow: hidden; }
.scrollable { margin-top: 0.3rem; max-height: 260px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.63rem; }
th, td { text-align: left; vertical-align: top; word-break: break-word; padding: 0.35rem 0.4rem 0.35rem 0.5rem; border-bottom: 1px solid rgba(15, 23, 42, 0.02); }
th { background: rgba(248, 250, 252, 0.7); font-size: 0.58rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
table th:first-child, table td:first-child { width: 3.2rem; min-width: 3.2rem; white-space: nowrap; word-break: normal; }
tbody tr:last-child td { border-bottom: none; }

/* Ensure Ethereum panel height visually balances with two stacked BTC tables */
.tall-eth { min-height: 560px; }

/* ================================
   Toast
================================ */
.toast {
    position: fixed; right: 20px; bottom: 20px; max-width: 280px; padding: 0.5rem 0.85rem 0.45rem;
    background: #fff; color: var(--text); font-size: 0.72rem; border: 1px solid rgba(15, 23, 42, 0.05);
    border-radius: 14px; box-shadow: 0 15px 40px rgba(15, 23, 42, 0.1); transform: translateY(120%); opacity: 0;
    transition: transform 0.22s, opacity 0.22s; z-index: 200;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ================================
   Modal
================================ */
.modal-backdrop {
    position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 1.1rem;
    background: rgba(15, 23, 42, 0.25); backdrop-filter: blur(2px); z-index: 400;
}
.modal {
    width: min(430px, 100%); padding: 1rem 1rem 0.6rem; background: #fff; border: 1px solid rgba(15, 23, 42, 0.05);
    border-radius: 18px; box-shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
}
.modal h3 { margin: 0 0 0.5rem; font-size: 0.9rem; }
.modal p { margin: 0 0 0.8rem; font-size: 0.76rem; color: var(--text-muted); }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.4rem; margin-bottom: 0.35rem; }

/* ================================
   Loading Overlay
================================ */
#loadingOverlay {
    position: absolute; inset: 0; display: none; gap: 0.65rem; align-items: center; justify-content: center;
    flex-direction: column; background: rgba(243, 244, 246, 0.85); border-radius: var(--radius-lg); backdrop-filter: blur(1px);
    z-index: 20;
}
.loading-text { font-size: 0.78rem; color: var(--text); opacity: 0.8; }
.spinner {
    width: 46px; height: 46px; border: 3.5px solid rgba(37, 99, 235, 0.15); border-top-color: rgba(37, 99, 235, 1);
    border-radius: 999px; animation: spin 0.55s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================
   Responsive
================================ */
@media (max-width: 950px) {
    .grid, .grid.grid-split-lg { grid-template-columns: 1fr; }
    .results-grid { grid-template-columns: 1fr; }
    .buttons-row { flex-direction: column; align-items: flex-start; }
    .btn { justify-content: center; }
    .options-inline { flex-direction: column; }
    .mnemonic-select-wrapper { flex-wrap: wrap; }
    .topbar { flex-wrap: wrap; }
    .master-keys .mk-row { grid-template-columns: 1fr; }
}
