:root {
    color-scheme: dark;
    --bg-base: #0a0d15;
    --bg-raised: rgba(148, 168, 214, 0.055);
    --bg-input: rgba(10, 13, 24, 0.55);
    --border: rgba(160, 180, 220, 0.14);
    --border-strong: rgba(160, 180, 220, 0.26);
    --text: #e9edf6;
    --text-dim: #9aa6bd;
    --text-faint: #5f6b84;
    --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
    --radius-lg: 16px;
    --radius-md: 11px;
    --radius-sm: 8px;
    --accent: hsl(42 95% 62%);
    --accent-soft: hsl(42 95% 62% / 0.14);
    --accent-border: hsl(42 95% 62% / 0.42);
    --accent-glow: hsl(42 95% 62% / 0.55);
    --err: #ff6474;
    --shadow-card: 0 18px 40px -18px rgba(0, 0, 0, 0.55);
    --ease-out: cubic-bezier(0.22, 0.68, 0.3, 1);
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    background: var(--bg-base);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- animated background ---------- */

.backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background:
        radial-gradient(ellipse 120% 90% at 50% -20%, rgba(120, 90, 40, 0.22), transparent 60%),
        var(--bg-base);
}

.backdrop::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(230, 200, 150, 0.12) 1px, transparent 1px);
    background-size: 26px 26px;
    mask-image: radial-gradient(ellipse 90% 70% at 50% 20%, black 20%, transparent 75%);
}

.orb {
    position: absolute;
    width: 46vmax;
    height: 46vmax;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.5;
    will-change: transform;
}

.orb-one {
    background: radial-gradient(circle, hsl(42 85% 55% / 0.16), transparent 65%);
    top: -18vmax;
    left: -10vmax;
    animation: orb-drift-one 34s ease-in-out infinite alternate;
}

.orb-two {
    background: radial-gradient(circle, hsl(215 80% 55% / 0.14), transparent 65%);
    bottom: -20vmax;
    right: -12vmax;
    animation: orb-drift-two 44s ease-in-out infinite alternate;
}

@keyframes orb-drift-one {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(9vmax, 7vmax) scale(1.15); }
}

@keyframes orb-drift-two {
    from { transform: translate(0, 0) scale(1.1); }
    to { transform: translate(-8vmax, -6vmax) scale(0.95); }
}

/* ---------- layout ---------- */

.shell {
    max-width: 1060px;
    margin: 0 auto;
    padding: 28px 20px 60px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.site-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 18px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand-mark {
    display: inline-flex;
    width: 30px;
    height: 30px;
    padding: 5px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    color: var(--accent);
}

.brand-mark svg {
    width: 100%;
    height: 100%;
}

.brand-domain {
    color: var(--text-faint);
    font-weight: 500;
}

.tagline {
    margin: 0;
    color: var(--text-dim);
    font-size: 14px;
}

main {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 16px;
}

/* ---------- translator panes ---------- */

.translator {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.pane {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.pane-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.pane-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

textarea {
    width: 100%;
    resize: vertical;
    min-height: 120px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 15px;
    line-height: 1.6;
    padding: 12px;
    transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

textarea:focus {
    outline: none;
    border-color: var(--accent-border);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.pane-footer {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    min-height: 20px;
}

.counter {
    color: var(--text-faint);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.warning {
    color: var(--err);
    font-size: 12.5px;
    font-family: var(--font-mono);
    text-align: right;
    overflow-wrap: anywhere;
}

/* ---------- buttons ---------- */

button {
    font-family: var(--font-ui);
    cursor: pointer;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ghost-button,
.toggle-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 13px;
    padding: 5px 11px;
    transition: color 140ms var(--ease-out), border-color 140ms var(--ease-out), background 140ms var(--ease-out);
}

.ghost-button:hover:not(:disabled),
.toggle-button:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--border-strong);
    background: rgba(148, 168, 214, 0.08);
}

.ghost-button.is-confirming {
    color: var(--accent);
    border-color: var(--accent-border);
}

.toggle-button.is-toggled {
    color: var(--accent);
    border-color: var(--accent-border);
    background: var(--accent-soft);
}

.primary-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    padding: 7px 16px;
    transition: box-shadow 160ms var(--ease-out), background 160ms var(--ease-out);
}

.primary-button:hover:not(:disabled) {
    background: hsl(42 95% 62% / 0.22);
    box-shadow: 0 0 18px -4px var(--accent-glow);
}

.primary-button .icon,
.ghost-button .icon {
    width: 14px;
    height: 14px;
}

/* ---------- keyer ---------- */

.keyer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.keyer-button {
    width: 44px;
    height: 38px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 20px;
    line-height: 1;
    transition: transform 80ms var(--ease-out), border-color 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
}

.keyer-button:hover {
    border-color: var(--accent-border);
}

.keyer-button:active {
    transform: translateY(2px);
    box-shadow: 0 0 14px -2px var(--accent-glow);
}

.keyer-space {
    color: var(--text-dim);
    font-size: 15px;
}

.keyer-hint {
    color: var(--text-faint);
    font-size: 12.5px;
}

.keyer-hint kbd {
    font-family: var(--font-mono);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 11.5px;
}

/* ---------- playback ---------- */

.playback {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.playback-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.playback-spacer {
    flex: 1;
}

.signal-lamp {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    transition: background 60ms linear, box-shadow 60ms linear;
}

.signal-lamp.is-on {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 16px 2px var(--accent-glow);
}

.progress-track {
    height: 4px;
    border-radius: 2px;
    background: var(--bg-input);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
}

.playback-strip {
    font-family: var(--font-mono);
    font-size: 20px;
    line-height: 1.8;
    letter-spacing: 2px;
    overflow-wrap: anywhere;
    min-height: 36px;
}

.playback-strip.is-empty {
    color: var(--text-faint);
    font-family: var(--font-ui);
    font-size: 13px;
    letter-spacing: normal;
}

.strip-signal {
    color: var(--text-dim);
    transition: color 60ms linear, text-shadow 60ms linear;
}

.strip-dot {
    font-size: 26px;
}

.strip-signal.is-active {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-glow);
}

.strip-separator {
    color: var(--text-faint);
    padding: 0 4px;
}

.strip-gap {
    padding: 0 3px;
}

.strip-unknown {
    color: var(--err);
}

/* ---------- options ---------- */

details.card summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-dim);
    user-select: none;
    transition: color 140ms var(--ease-out);
}

details.card summary:hover {
    color: var(--text);
}

details.card[open] summary {
    color: var(--text);
    margin-bottom: 14px;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px 22px;
}

.option {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.option-name {
    display: flex;
    justify-content: space-between;
    color: var(--text-dim);
}

.option-name output {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.option input[type="range"] {
    accent-color: var(--accent);
}

.option select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    padding: 6px 8px;
}

.option-checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    align-self: end;
    padding-bottom: 4px;
}

.option-checkbox input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
}

/* ---------- reference chart ---------- */

.reference-hint {
    margin: 0 0 10px;
    color: var(--text-faint);
    font-size: 12.5px;
}

.chart-group-title {
    margin: 14px 0 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
    gap: 8px;
}

.chart-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 140ms var(--ease-out), background 140ms var(--ease-out);
}

.chart-cell:hover {
    border-color: var(--accent-border);
    background: var(--accent-soft);
}

.chart-cell.is-pulsing {
    animation: chart-pulse 500ms var(--ease-out);
}

@keyframes chart-pulse {
    0% { box-shadow: 0 0 0 0 var(--accent-glow); }
    100% { box-shadow: 0 0 0 10px transparent; }
}

.chart-character {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.chart-code {
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 1.5px;
    color: var(--accent);
}

/* ---------- light overlay ---------- */

.light-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 26px;
    background: #000;
    cursor: pointer;
}

.light-overlay.is-open {
    display: flex;
}

.light-overlay-lamp {
    width: min(46vmin, 300px);
    height: min(46vmin, 300px);
    border-radius: 50%;
    background: #15130d;
    transition: background 40ms linear, box-shadow 40ms linear;
}

.light-overlay.is-flashing .light-overlay-lamp {
    background: #fff8e6;
    box-shadow: 0 0 120px 40px rgba(255, 244, 200, 0.85);
}

.light-overlay-hint {
    color: rgba(255, 255, 255, 0.35);
    font-size: 13px;
}

/* ---------- footer ---------- */

.site-footer {
    color: var(--text-faint);
    font-size: 12.5px;
    text-align: center;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
    .translator {
        grid-template-columns: 1fr;
    }

    .shell {
        padding: 18px 12px 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }
}
