:root {
    --background: #f3f1eb;
    --surface: #fbfaf6;
    --text: #20211e;
    --muted: #6c6e67;
    --border: #d5d4cd;
    --strong-border: #aaa9a1;
    --accent: #e45532;
    --dark: #252622;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    min-width: 320px;
    color: var(--text);
    background: var(--background);
    font-family: "Inter", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

.app {
    width: min(760px, calc(100% - 40px));
    margin: 0 auto;
    padding: 80px 0 64px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 40px;
}

.morse-mark {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 0 0 auto;
    border-radius: 10px;
    background: var(--dark);
}

.morse-mark i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #fff;
}

.morse-mark span {
    width: 13px;
    height: 5px;
    border-radius: 4px;
    background: var(--accent);
}

h1, h2, p { margin-top: 0; }

h1 {
    margin-bottom: 7px;
    font-size: 30px;
    line-height: 1.15;
    letter-spacing: -0.04em;
}

.page-header p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.mode-tabs {
    margin-bottom: 18px;
    padding: 4px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #e8e6df;
}

.mode-tabs button {
    min-height: 42px;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.mode-tabs button:hover { color: var(--text); }

.mode-tabs button[aria-selected="true"] {
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 2px 8px rgba(35, 35, 31, 0.08);
}

.mode-tabs button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.panel {
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 12px 36px rgba(35, 35, 31, 0.05);
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.label, .output-header > span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-family: "DM Mono", monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h2 {
    margin-bottom: 0;
    font-size: 20px;
    line-height: 1.25;
    letter-spacing: -0.025em;
}

.local-note {
    padding: 7px 10px;
    border-radius: 20px;
    color: #557150;
    background: #eaf0e4;
    font-size: 11px;
    white-space: nowrap;
}

.drop-zone {
    position: relative;
    min-height: 190px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px dashed var(--strong-border);
    border-radius: 10px;
    background: #f7f6f1;
    cursor: pointer;
    transition: border-color 160ms ease, background 160ms ease;
}

.drop-zone:hover, .drop-zone.is-dragging {
    border-color: var(--accent);
    background: #fff9f5;
}

.drop-zone input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.upload-symbol {
    width: 38px;
    height: 38px;
    margin-bottom: 16px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    font-size: 18px;
}

.drop-zone p { margin-bottom: 8px; font-size: 14px; }
.drop-zone .browse-text { color: var(--accent); font-weight: 600; }
.drop-zone > span { color: var(--muted); font-size: 11px; }

.selected-file {
    min-height: 76px;
    padding: 13px;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f7f6f1;
}

.selected-file:not([hidden]) { display: flex; }

.file-type {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 7px;
    color: #fff;
    background: var(--dark);
    font-family: "DM Mono", monospace;
    font-size: 9px;
}

.file-meta { min-width: 0; display: flex; flex: 1; flex-direction: column; gap: 5px; }
.file-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-meta span { color: var(--muted); font-size: 11px; }

.remove-file, .copy-button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
}

.remove-file:hover, .copy-button:not(:disabled):hover { color: var(--accent); }

.decode-button {
    width: 100%;
    min-height: 50px;
    margin-top: 14px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: var(--dark);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 160ms ease, opacity 160ms ease;
}

.decode-button:not(:disabled):hover { background: #3a3b35; }
.decode-button:disabled { opacity: 0.35; cursor: not-allowed; }

.decode-button.is-loading .button-arrow {
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    font-size: 0;
    animation: spin 700ms linear infinite;
}

.status {
    margin-top: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: var(--muted);
    font-size: 10px;
}

.status-indicator { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status[data-state="ready"] { color: #557150; }
.status[data-state="processing"] { color: #977520; }
.status[data-state="success"] { color: #557150; }
.status[data-state="error"] { color: #b7462b; }
.status.is-processing .status-indicator { animation: pulse 1s ease-in-out infinite; }

.results { margin-top: 42px; }
.section-heading { margin-bottom: 18px; }

.encoder-panel { margin-top: 0; }

.message-field > span,
.encoder-settings label > span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 9px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.message-field textarea {
    width: 100%;
    min-height: 126px;
    padding: 15px 16px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
    color: var(--text);
    background: #f7f6f1;
    font-size: 14px;
    line-height: 1.6;
    transition: border-color 160ms ease, background 160ms ease;
}

.message-field textarea:focus {
    border-color: var(--accent);
    background: var(--surface);
}

.message-field textarea::placeholder { color: #a2a39d; }

.message-field small {
    display: block;
    margin-top: 7px;
    color: var(--muted);
    text-align: right;
    font-size: 10px;
}

.encoder-settings {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.encoder-settings output {
    color: var(--text);
    font-family: "DM Mono", monospace;
    font-size: 10px;
    font-weight: 500;
}

.encoder-settings input {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
}

.encoder-preview { margin-top: 22px; }
.encoder-preview.has-content .morse-output { color: var(--accent); }

.generated-audio {
    margin-top: 14px;
    padding: 12px;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #f7f6f1;
}

.generated-audio:not([hidden]) { display: flex; }
.generated-audio audio { min-width: 0; height: 38px; flex: 1; }

.download-audio {
    min-height: 38px;
    padding: 0 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 7px;
    color: #fff;
    background: var(--accent);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
}

.download-audio:hover { background: #c94729; }

.output {
    margin-top: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.output-header {
    min-height: 42px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.output-header > span { margin: 0; }
.copy-button { padding: 7px 0 7px 12px; }
.copy-button:disabled { opacity: 0.35; cursor: default; }

pre {
    margin: 0;
    min-height: 92px;
    padding: 22px;
    overflow-x: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.plain-output {
    color: #a2a39d;
    font-family: "Inter", sans-serif;
    font-size: 24px;
    line-height: 1.45;
    letter-spacing: -0.025em;
}

.morse-output {
    min-height: 78px;
    color: #a2a39d;
    font-family: "DM Mono", monospace;
    font-size: 15px;
    line-height: 1.7;
}

.results.has-results .plain-output { color: var(--text); }
.results.has-results .morse-output { color: var(--accent); }

.help-text {
    margin: 18px 0 0;
    color: var(--muted);
    text-align: center;
    font-size: 11px;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }

@media (max-width: 600px) {
    .app { width: min(100% - 24px, 760px); padding: 38px 0; }
    .page-header { margin-bottom: 28px; }
    h1 { font-size: 26px; }
    .panel { padding: 20px 16px; }
    .panel-heading { gap: 12px; }
    .local-note { display: none; }
    .drop-zone { min-height: 170px; padding: 22px 12px; }
    .results { margin-top: 34px; }
    .encoder-settings { grid-template-columns: 1fr; gap: 16px; }
    .generated-audio:not([hidden]) { align-items: stretch; flex-direction: column; }
    .generated-audio audio { width: 100%; flex: auto; }
    pre { padding: 18px 16px; }
    .plain-output { font-size: 21px; }
}

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