:root {
    --ms-bg: #f7f4ed;
    --ms-panel: #ffffff;
    --ms-ink: #17211f;
    --ms-muted: #60706b;
    --ms-border: #d8ded8;
    --ms-primary: #23403d;
    --ms-primary-strong: #17302d;
    --ms-accent: #d75f32;
    --ms-accent-soft: #f4d6c9;
    --ms-danger: #9f2a1f;
    --ms-shadow: 0 18px 48px rgba(27, 49, 45, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--ms-bg);
}

body.ms-body {
    min-height: 100vh;
    margin: 0;
    color: var(--ms-ink);
    background:
        linear-gradient(180deg, rgba(35, 64, 61, 0.08), rgba(35, 64, 61, 0)),
        var(--ms-bg);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

.ms-app-shell,
.ms-frame {
    min-height: 100vh;
}

.ms-frame {
    width: min(1180px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 18px 0 34px;
}

.ms-header,
.ms-library-head,
.ms-editor-head,
.ms-panel-head,
.ms-card-actions,
.ms-editor-actions,
.ms-header-actions {
    display: flex;
    align-items: center;
}

.ms-header {
    justify-content: space-between;
    min-height: 50px;
    margin-bottom: 18px;
    gap: 14px;
}

.ms-brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
    color: var(--ms-ink);
    text-decoration: none;
    font-weight: 760;
}

.ms-brand img {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    box-shadow: 0 5px 14px rgba(35, 64, 61, 0.18);
}

.ms-header-actions {
    justify-content: flex-end;
    gap: 10px;
}

.ms-user {
    color: var(--ms-muted);
    font-size: 0.92rem;
}

.ms-main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ms-library-head,
.ms-editor-head,
.ms-auth-panel,
.ms-editor-panel,
.ms-sentence-panel,
.ms-speech-card {
    background: var(--ms-panel);
    border: 1px solid var(--ms-border);
    border-radius: 8px;
    box-shadow: var(--ms-shadow);
}

.ms-library-head,
.ms-editor-head {
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
}

.ms-eyebrow {
    margin: 0 0 6px;
    color: var(--ms-accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 8px;
    font-size: clamp(1.8rem, 4vw, 2.7rem);
    line-height: 1.08;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 6px;
    font-size: 1.05rem;
    letter-spacing: 0;
}

.ms-muted,
.ms-speech-card p {
    color: var(--ms-muted);
    line-height: 1.55;
}

.ms-button,
.ms-icon-button,
.ms-audio-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 720;
    text-decoration: none;
    white-space: nowrap;
}

.ms-button-primary,
.ms-audio-button {
    color: #ffffff;
    background: var(--ms-primary);
}

.ms-button-primary:hover,
.ms-audio-button:hover {
    background: var(--ms-primary-strong);
}

.ms-button-secondary,
.ms-icon-button {
    color: var(--ms-primary);
    background: #f9fbf8;
    border-color: var(--ms-border);
}

.ms-button-danger {
    color: var(--ms-danger);
    background: #fff7f5;
    border-color: #f1c9bf;
}

.ms-button:disabled,
.ms-audio-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.ms-loading {
    display: grid;
    min-height: 100vh;
    place-items: center;
    gap: 12px;
    color: var(--ms-muted);
}

.ms-loading img {
    width: 58px;
    height: 58px;
    border-radius: 12px;
}

.ms-loading-page,
.ms-empty {
    display: grid;
    min-height: 180px;
    place-items: center;
    color: var(--ms-muted);
    background: var(--ms-panel);
    border: 1px dashed var(--ms-border);
    border-radius: 8px;
}

.ms-auth {
    display: grid;
    min-height: calc(100vh - 100px);
    place-items: center;
}

.ms-auth-panel {
    width: min(450px, 100%);
    padding: 24px;
}

.ms-form {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--ms-ink);
    font-size: 0.92rem;
    font-weight: 680;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    color: var(--ms-ink);
    background: #fbfcfa;
    border: 1px solid var(--ms-border);
    border-radius: 7px;
}

textarea {
    min-height: 260px;
    resize: vertical;
    line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus,
.ms-button:focus-visible,
.ms-audio-button:focus-visible {
    outline: 3px solid rgba(215, 95, 50, 0.25);
    outline-offset: 2px;
}

.ms-auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    color: var(--ms-primary);
    font-weight: 680;
}

.ms-full {
    width: 100%;
    margin-top: 12px;
}

.ms-alert {
    margin: 14px 0;
    padding: 12px 14px;
    border-radius: 7px;
    line-height: 1.45;
}

.ms-alert-error {
    color: var(--ms-danger);
    background: #fff7f5;
    border: 1px solid #f1c9bf;
}

.ms-alert-success {
    color: #1f5f48;
    background: #eef8f1;
    border: 1px solid #c8e5d2;
}

.ms-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.ms-speech-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

.ms-card-preview {
    flex: 1;
}

.ms-card-actions,
.ms-editor-actions {
    flex-wrap: wrap;
    gap: 8px;
}

.ms-editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
    gap: 16px;
    align-items: start;
}

.ms-editor-panel,
.ms-sentence-panel {
    padding: 16px;
}

.ms-editor-panel {
    display: grid;
    gap: 13px;
}

.ms-editor-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--ms-muted);
    font-size: 0.88rem;
}

.ms-over-limit {
    color: var(--ms-danger);
    font-weight: 800;
}

.ms-panel-head {
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.ms-sentence-list {
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    gap: 10px;
    margin: 0;
    padding: 0;
    overflow: auto;
    list-style: none;
}

.ms-sentence {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
    background: #fbfcfa;
    border: 1px solid var(--ms-border);
    border-radius: 8px;
}

.ms-sentence-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: var(--ms-primary);
    background: #e8eee9;
    border-radius: 999px;
    font-weight: 760;
}

.ms-sentence p {
    margin: 2px 0 0;
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.ms-sentence-actions {
    display: grid;
    grid-column: 2;
    grid-template-columns: 62px 62px;
    gap: 8px;
}

.ms-audio-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.9rem;
}

.ms-empty-list {
    min-height: 120px;
}

.ms-offline {
    position: fixed;
    right: 18px;
    bottom: 18px;
    padding: 10px 14px;
    color: #ffffff;
    background: var(--ms-danger);
    border-radius: 6px;
    box-shadow: var(--ms-shadow);
    font-weight: 760;
}

@media (max-width: 880px) {
    .ms-frame {
        width: min(100vw - 22px, 720px);
        padding-top: 12px;
    }

    .ms-header,
    .ms-library-head,
    .ms-editor-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .ms-header-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .ms-editor-grid {
        grid-template-columns: 1fr;
    }

    .ms-sentence-list {
        max-height: none;
    }
}

@media (max-width: 560px) {
    .ms-auth-panel,
    .ms-library-head,
    .ms-editor-head,
    .ms-editor-panel,
    .ms-sentence-panel,
    .ms-speech-card {
        padding: 14px;
    }

    .ms-header-actions,
    .ms-card-actions,
    .ms-editor-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    .ms-user {
        grid-column: 1 / -1;
    }

    .ms-button,
    .ms-icon-button {
        width: 100%;
    }

    .ms-editor-meta {
        flex-direction: column;
    }
}
