/* Morse Code · Reachy Mini — mobile-first, dark/light themed. */

:root {
    --bg: #0d1117;
    --bg-soft: #161b22;
    --panel: #1b222c;
    --panel-2: #232c38;
    --text: #e8edf3;
    --muted: #93a1b3;
    --line: #2b3442;
    --accent: #5b8cff;
    --accent-2: #8a6cff;
    --danger: #ff5a78;
    --good: #36d399;
    --scope-fill: rgba(91, 140, 255, 0.45);
    --scope-mark: rgba(255, 90, 120, 0.95);
    --radius: 16px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
    --bg: #f4f6fb;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #eef2f9;
    --text: #131923;
    --muted: #5d6b7e;
    --line: #dde3ee;
    --accent: #2f6bff;
    --accent-2: #7a4dff;
    --scope-fill: rgba(47, 107, 255, 0.30);
    --scope-mark: rgba(214, 40, 79, 0.95);
    --shadow: 0 10px 30px rgba(20, 30, 60, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

#app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 720px;
    margin: 0 auto;
}

/* ─── App bar ─────────────────────────────────────────────── */
.appbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
.brand-logo { font-size: 22px; }
.brand-logo-img { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; display: block; }

.icon-btn {
    appearance: none;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    width: 40px; height: 40px;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn.tiny { width: 32px; height: 32px; font-size: 14px; }

/* App / Demo mode toggle in the header */
.mode-seg { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.mode-btn {
    appearance: none; background: transparent; border: 0; color: var(--muted);
    padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.mode-btn.active { background: var(--panel-2); color: var(--text); box-shadow: var(--shadow); }
.page-host { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ─── Scrolling single page ───────────────────────────────── */
.scroller { flex: 1; padding: 12px 14px 40px; display: flex; flex-direction: column; gap: 12px; }
.divider { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 0; }
.view-host { flex: 1; padding: 16px 16px 96px; }
.view { display: flex; flex-direction: column; gap: 9px; scroll-margin-top: 64px; }
.view h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.view h3 { margin: 6px 0; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.muted { color: var(--muted); }

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
}
.tab {
    flex: 1 1 0;
    max-width: 160px;
    appearance: none;
    background: transparent;
    border: 0;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.tab-ico { font-size: 20px; }
.tab.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ─── Fields & controls ───────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.send-row { margin-top: 4px; }

.compose-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 17px;
    font-family: inherit;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
}
.compose-input:focus { border-color: var(--accent); }

.btn {
    appearance: none;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    padding: 12px 18px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { flex: 1; padding: 16px; font-size: 17px; }
.btn.listening { background: linear-gradient(135deg, var(--danger), #ff9a5a); }

.segmented { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg {
    flex: 1;
    appearance: none;
    background: transparent;
    border: 0;
    color: var(--muted);
    padding: 8px 6px;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.seg.active { background: var(--panel-2); color: var(--text); box-shadow: var(--shadow); }

.range { width: 100%; accent-color: var(--accent); }
.range-val { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }

.status { font-size: 13px; min-height: 16px; }
.send-row { margin-top: 0; }
.warn { color: var(--danger); font-size: 14px; font-weight: 600; }

/* ─── Morse chips ─────────────────────────────────────────── */
.morse-out {
    min-height: 34px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 10px;
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
}
.pattern { display: inline-flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 100%; }
.pattern .dot, .pattern .dash {
    display: inline-block;
    height: 10px;
    border-radius: 5px;
    background: var(--accent);
}
.pattern .dot { width: 10px; }
.pattern .dash { width: 22px; background: var(--accent-2); }
.wordsep { color: var(--muted); font-weight: 800; padding: 0 2px; }

/* ─── Listen ──────────────────────────────────────────────── */
.scope {
    width: 100%;
    height: 84px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    display: block;
}
.decoded-text {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: 0.04em;
    min-height: 26px;
    word-break: break-word;
}
.decoded-morse { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px; word-break: break-all; color: var(--muted); }
.transcript { display: flex; flex-direction: column; gap: 6px; max-height: 30vh; overflow-y: auto; }
.line {
    display: flex; flex-direction: column; gap: 1px;
    padding: 7px 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.line-text { font-family: "JetBrains Mono", monospace; font-weight: 700; font-size: 16px; }
.line-morse { font-family: "JetBrains Mono", monospace; font-size: 12px; }

/* ─── Learn chart ─────────────────────────────────────────── */
.chart-section { display: flex; flex-direction: column; gap: 8px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.chart-cell {
    appearance: none;
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px;
    padding: 12px 8px;
    min-height: 78px;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--text);
    cursor: pointer;
}
.chart-cell:active { transform: scale(0.96); }
.cell-char { font-size: 22px; font-weight: 800; }
.chart-cell.ping { animation: ping 0.4s ease; border-color: var(--accent); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
.legend { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }

/* ─── Settings sheet / overlay ────────────────────────────── */
.overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(0, 0, 0, 0.5);
    display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
    width: 100%;
    max-width: 720px;
    max-height: 88dvh;
    overflow-y: auto;
    background: var(--bg-soft);
    border-radius: 22px 22px 0 0;
    box-shadow: var(--shadow);
    padding: 16px 18px calc(28px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg-soft); padding-bottom: 8px; }
.settings-body { display: flex; flex-direction: column; gap: 14px; }
.version { text-align: center; font-size: 12px; margin-top: 6px; }

/* ─── Toast ───────────────────────────────────────────────── */
.toast {
    position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--line);
    padding: 12px 18px; border-radius: 12px;
    box-shadow: var(--shadow);
    opacity: 0; pointer-events: none; transition: all 0.25s ease;
    z-index: 100; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Demo mode ───────────────────────────────────────────── */
.scope-big { height: 110px; }
.demo-decoded {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 40px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-align: center;
    min-height: 50px;
    word-break: break-word;
    color: var(--accent);
}
.demo-status { text-align: center; min-height: 16px; }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; flex: 0 0 auto; }

.demo-setup { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.tiny { font-size: 12px; }
.rule-list { display: flex; flex-direction: column; gap: 8px; }
.rule-row { display: flex; align-items: center; gap: 6px; }
.rule-input {
    flex: 1; min-width: 0; padding: 9px 10px; font-size: 14px; font-family: inherit;
    color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; outline: none;
}
.rule-input:focus { border-color: var(--accent); }
.rule-arrow { color: var(--muted); font-weight: 800; }

@media (max-width: 420px) {
    .brand-name { display: none; }
}
@media (min-width: 560px) {
    .tab-label { font-size: 13px; }
}
