:root {
    --app-max-width: 980px;
    --footer-height: 54px;
    --composer-height: 220px;
    --composer-gap: 14px;
    --accent: #1f6fff;
    --accent-strong: #195be8;
    --bg-dark: rgba(61, 71, 89, 0.74);
    --panel-light: rgba(255, 255, 255, 0.97);
    --text-dark: #1e293b;
    --border-soft: rgba(50, 79, 126, 0.2);

    --depth0-b: hsl(215 18% 96.5%);
    --depth0-c: hsl(215 16% 94.5%);

    --depth1-a: hsl(205 66% 98%);
    --depth1-b: hsl(205 64% 96.5%);
    --depth1-c: hsl(205 58% 94.5%);

    --depth2-a: hsl(152 44% 97.5%);
    --depth2-b: hsl(152 42% 96%);
    --depth2-c: hsl(152 36% 94%);

    --depth3-a: hsl(350 62% 98%);
    --depth3-b: hsl(350 60% 96.5%);
    --depth3-c: hsl(350 54% 94.5%);
}

body.wide-layout {
    overflow-x: hidden;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7fc;
    background-image:
        linear-gradient(rgba(38, 79, 146, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(38, 79, 146, 0.05) 1px, transparent 1px),
        linear-gradient(rgba(38, 79, 146, 0.028) 1px, transparent 1px),
        linear-gradient(90deg, rgba(38, 79, 146, 0.028) 1px, transparent 1px);
    background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
    background-repeat: repeat;
    overflow-y: auto;
}

#app {
    min-height: 100dvh;
    padding: 24px 14px;
}

#messages {
    max-width: var(--app-max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
#messages article[data-empty="true"] {
    display: none;
}
.server-back-line {
    white-space: pre-wrap;
    word-break: break-word;
}

body.wide-layout #messages {
    max-width: none;
    width: 100%;
    margin-left: 0;
    margin-right: auto;
}

body.started #messages {
    padding-top: 86px;
    padding-bottom: calc(var(--composer-height) + var(--footer-height) + 34px);
}

.message {
    width: fit-content;
    max-width: min(860px, 100%);
    border-radius: 16px;
    padding: 14px 16px;
    line-height: 1.45;
    border: 1px solid rgba(63, 93, 146, 0.14);
    box-shadow: 0 12px 30px rgba(30, 53, 92, 0.14);
}

.message.user {
    margin-left: auto;
    background: linear-gradient(140deg, #1f6fff 0%, #4164ff 52%, #4a5dff 100%);
    color: #ffffff;
    box-shadow: 0 16px 34px rgba(34, 84, 209, 0.28);
}

.message.assistant {
    margin-right: auto;
    max-width: 100%;
    background: var(--panel-light);
    color: var(--text-dark);
    overflow-x: auto;
}

body.wide-layout .message.assistant {
    width: 100%;
    max-width: 100%;
}

.line {
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 18px;
    line-height: 1.52;
}

.line + .line {
    margin-top: 4px;
}

.line.d0.indent, .line.res, .line.num {
    display: table;
    width: 100%;
}

.line.question {
    background: transparent;
    padding-left: 0;
    padding-right: 0;
    font-size: 17px;
}

.line.d0 {
    padding: 8px 0;
    background: transparent;
}

.line.d1 {
    margin-left: 40px;
    font-size: 17px;
    --fill: var(--depth1-a);
}

.line.d2 {
    margin-left: 80px;
    font-size: 16px;
    --fill: var(--depth2-a);
}

.line.d3 {
    margin-left: 120px;
    font-size: 15px;
    --fill: var(--depth3-a);
}

.line.d1, .line.d2, .line.d3 {
    padding: 8px;
    padding-left: 5px;
    background-color: var(--fill);
}

.line.indent {
    padding-left: 20px;
}

.line.d0.indent {
    --fill: var(--depth0-b);
    padding-right: 8px;
    background-color: var(--fill);
}

.line.d0.indent.alt {
    --fill: var(--depth0-c);
}

.line.d1.indent {
    --fill: var(--depth1-b);
}

.line.d1.indent.alt {
    --fill: var(--depth1-c);
}

.line.d2.indent {
    --fill: var(--depth2-b);
}

.line.d2.indent.alt {
    --fill: var(--depth2-c);
}

.line.d3.indent {
    --fill: var(--depth3-b);
}

.line.d3.indent.alt {
    --fill: var(--depth3-c);
}

.line.j {
    height: 18px;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.line.res, .line.num {
    padding: 8px;
    padding-left: 5px;
}

.line.res {
    background: rgba(250, 250, 220, 0.92);
    font-size: 18px;
    font-weight: 700;
}

.line.num {
    background: rgba(250, 250, 235, 0.92);
    font-size: 17px;
}

.numitem {
    margin-left: 10px;
    font-style: italic;
    font-weight: 700;
}

.line.ask {
    margin-top: 10px;
    padding: 6px 12px;
    background: transparent;
    border-left: 4px solid #1f6fff;
    border-radius: 0;
    font-size: 17px;
    font-style: italic;
    color: #33415c;
}

.asklabel {
    margin-right: 8px;
    font-style: normal;
    font-weight: 700;
    color: #1f6fff;
}

.line.sub {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 2px 0 4px;
    background: transparent;
}

.subicon {
    flex: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1f6fff;
    color: #fff;
    font: 700 10px/16px Georgia, serif;
    text-align: center;
}

.subbubble {
    display: inline-block;
    background: rgba(31, 111, 255, 0.1);
    border: 1px solid rgba(31, 111, 255, 0.28);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
    line-height: 1.3;
    color: #33415c;
    white-space: nowrap;
}

.subbubble math, .subbubble m {
    font-size: 1em;
}

.subbubble:has(mfrac) {
    font-size: 14px;
    padding: 5px 11px;
}

.line.key {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(31, 111, 255, 0.08);
    border: 1px solid rgba(31, 111, 255, 0.25);
    color: #33415c;
}

.keyinfo {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.keyicon {
    flex: none;
    width: 22px;
    height: 22px;
    margin-top: 3px;
    border-radius: 50%;
    background: #1f6fff;
    color: #fff;
    font: 700 14px/22px Georgia, serif;
    text-align: center;
}

math {
    math-style: normal;
}

.line math, .line m {
    font-size: 1.1em;
    line-height: 1.2;
}

.line.d0:not(.indent) math, .line.d0:not(.indent) m {
    background-color: var(--depth0-b);
    border-radius: 6px;
    padding: 2px 6px;
}

.line.res math, .line.res m {
    font-size: 1.2em;
}

.line math:has(+ math), .line math + math {
    margin: 4px 0;
}

.numitem math, .numitem m {
    font-size: 1.1em;
    line-height: 1.2;
}

.line.numbered {
    background: #ffffff !important;
    box-shadow: none !important;
}

.c {
    color: #0a6fd8;
    font-weight: 700;
}

.warn {
    color: #a86400;
}

.error {
    color: #bf1d1d;
    font-weight: 700;
}

#composerShell {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(var(--app-max-width), calc(100vw - 20px));
    background: linear-gradient(145deg, rgba(248, 251, 255, 0.94), rgba(235, 242, 255, 0.9));
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    padding: 12px;
    box-shadow: 0 18px 42px rgba(32, 55, 98, 0.2);
    backdrop-filter: blur(7px);
}

#heroLogoShell {
    position: fixed;
    left: 50%;
    top: calc(50% - (var(--composer-height) / 2) - 14px);
    transform: translate(-50%, -100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25;
    pointer-events: none;
    transition: top 220ms ease, left 220ms ease, transform 220ms ease;
}

#heroLogo {
    width: min(430px, 72vw);
    max-width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 9px 20px rgba(32, 55, 98, 0.2));
    transition: width 220ms ease;
}

body.started #composerShell {
    top: auto;
    bottom: calc(var(--footer-height) + var(--composer-gap));
    transform: translateX(-50%);
}

body.started #heroLogoShell {
    top: 14px;
    left: 14px;
    transform: none;
}

body.started #heroLogo {
    width: min(215px, 36vw);
}

#composerForm {
    margin: 0;
}

.composerRow {
    display: flex;
    gap: 10px;
    align-items: center;
}

#query {
    width: 100%;
    min-height: 88px;
    max-height: 32vh;
    border: 1px solid rgba(73, 100, 148, 0.25);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    color: #1f2a37;
    font-size: 16px;
    line-height: 1.45;
    padding: 12px 14px;
    resize: none;
    overflow-y: auto;
    outline: none;
}

#query:focus {
    border-color: rgba(31, 111, 255, 0.95);
    box-shadow: 0 0 0 3px rgba(31, 111, 255, 0.22);
    background: rgba(255, 255, 255, 1);
}

#submitButton {
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(145deg, var(--accent), #3d7bff);
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    flex: 0 0 52px;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(31, 111, 255, 0.34);
}

#submitButton:hover {
    background: linear-gradient(145deg, var(--accent-strong), #2e68ff);
}

.actionRow {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: stretch;
}

.actionRow > button {
    flex: 1 1 260px;
    border: 1px solid rgba(40, 63, 101, 0.22);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    letter-spacing: 0.01em;
    cursor: pointer;
    color: #1f2a37;
    background: rgba(255, 255, 255, 0.86);
    box-shadow: 0 6px 14px rgba(31, 57, 104, 0.08);
}

.actionRow > button:hover {
    background: rgba(255, 255, 255, 0.98);
}
.actionRow > button.active {
    border-color: rgba(31, 111, 255, 0.62);
    background: rgba(31, 111, 255, 0.16);
    color: #0f4fcf;
    box-shadow: inset 0 0 0 1px rgba(31, 111, 255, 0.18);
}

#stretchButton {
    flex: 0 0 92px;
    font-weight: 700;
}

.line.examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 2px 0 4px;
    background: transparent;
}

.examplesLabel {
    font-size: 13px;
    color: #33415c;
}

.exampleChip {
    max-width: 100%;
    border: 1px solid rgba(40, 63, 101, 0.22);
    border-radius: 999px;
    padding: 5px 11px;
    font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    line-height: 1.3;
    color: #1f2a37;
    background: rgba(255, 255, 255, 0.86);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.exampleChip:hover {
    border-color: rgba(31, 111, 255, 0.62);
    background: rgba(31, 111, 255, 0.12);
    color: #0f4fcf;
}

body.wide-layout #composerShell {
    left: 14px;
    right: 14px;
    width: auto;
    max-width: none;
    transform: translateY(-50%);
}

body.wide-layout.started #composerShell {
    transform: none;
}

#footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 54px;
    background: var(--bg-dark);
    border-top: 1px solid rgba(255, 255, 255, 0.24);
    color: #f1f5fd;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    text-align: center;
    padding: 8px 12px;
    font-size: 15px;
}

#footer a {
    color: #a9d3ff;
    text-decoration: none;
    font-weight: 800;
}

#footer a:hover {
    text-decoration: underline;
}

@media (max-width: 900px) {
    .message {
        max-width: 100%;
    }
    .line.d1 { margin-left: 14px; }
    .line.d2 { margin-left: 24px; }
    .line.d3 { margin-left: 34px; }
}

@media (max-width: 640px) {
    #app {
        padding: 12px 8px;
    }

    #composerShell {
        width: calc(100vw - 10px);
        border-radius: 14px;
        padding: 10px;
    }

    body.started #composerShell {
        bottom: calc(var(--footer-height) + 8px);
    }

    body.started #messages {
        padding-top: 0;
    }

    #query {
        min-height: 82px;
        font-size: 16px;
    }
    .line.d0, .line.res, .line.num {
        font-size: 16px;
    }

    .line.d1 {
        font-size: 15px;
    }

    .line.d2 {
        font-size: 14px;
    }

    .line.d3 {
        font-size: 13px;
    }

    #submitButton {
        width: 46px;
        height: 46px;
        flex-basis: 46px;
        border-radius: 12px;
        font-size: 22px;
    }

    .actionRow {
        flex-wrap: nowrap;
        gap: 6px;
    }

    .actionRow > button {
        flex: 1 1 0;
        min-width: 0;
        min-height: 42px;
        font-size: 11px;
        padding: 8px 6px;
        line-height: 1.15;
    }

    #stretchButton {
        display: none;
    }

    .exampleChip {
        font-size: 11px;
        padding: 4px 9px;
    }

    #heroLogo {
        width: min(300px, 76vw);
    }

    body.started #heroLogoShell {
        display: none;
    }

    #footer {
        font-size: 12px;
        gap: 6px;
    }

    #footerBuiltWithStar,
    #footerBuiltWith {
        display: none;
    }
}

.signtable {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    table-layout: fixed;
    margin: 4px 0;
    border: 1px solid rgba(33, 51, 82, 0.32);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-dark);
    font-size: 0.85em;
}

.signtable.datatable {
    table-layout: auto;
    width: auto;
    min-width: 100%;
    max-width: none;
}

.line:has(> .signtable.datatable) {
    overflow-x: auto;
}

.signtable th, .signtable td {
    border: 1px solid rgba(33, 51, 82, 0.32);
    padding: 8px 7px;
    margin: 0;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.signtable thead td {
    font-weight: 700;
    background: rgba(241, 246, 255, 0.86);
    white-space: normal;
    overflow-wrap: break-word;
    line-height: 1.25;
    font-size: 0.92em;
    padding: 7px 6px;
}

.signtable thead td math, .signtable thead td m {
    font-size: 0.95em;
}

.signtable tbody tr:last-child td:first-child {
    font-weight: 800;
}

.signtable math, .signtable m {
    font-size: 1em;
    line-height: 1.12;
}
