﻿/* Layout and colors follow Modules/HinhHocPhang (assets/style.css): one full-height card,
   tool sidebar on the left, workspace on the right, status bar at the bottom. */
* {
    box-sizing: border-box;
}

:root {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 12px;
    color: #273c33;
    background: #f2f6f5;
    --accent: #087f78;
    --accent-hover: #066c65;
    --accent-soft: #edf7f3;
    --border: #d9e5df;
    --border-control: #bad6cd;
    --muted: #52695d;
    --title: #294c3c;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    background: #f2f6f5;
}

main {
    height: 100dvh;
    width: 100%;
    padding: 8px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
}

header {
    align-self: center;
    min-width: 0;
}

h1 {
    font-size: 18px;
    line-height: 1.4;
    margin: 0;
    font-weight: 650;
}

p {
    line-height: 1.5;
}

kbd {
    font: inherit;
    white-space: nowrap;
    font-weight: 600;
    color: var(--title);
}

.attribution {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
}

noscript {
    grid-column: 1 / -1;
    color: #a33927;
}

/* ---------- Card: sidebar | workspace, status below workspace ---------- */

.card {
    grid-column: 1 / -1;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 336px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    overflow: hidden;
}

.controls {
    grid-column: 1;
    grid-row: 1 / -1;
    min-height: 0;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
    background: #f5f9f7;
    border-right: 1px solid var(--border);
}

.toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
}

.tool-group {
    min-width: 0;
    margin: 0;
    padding: 10px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 7px;
}

.group-title {
    font-size: 13px;
    font-weight: 650;
    line-height: 1.4;
    margin: 0 0 8px;
    color: var(--title);
}

.sub-title {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    margin: 8px 0 4px;
    color: var(--muted);
}

    .group-title + .sub-title {
        margin-top: 0;
    }

.tool-hint {
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
    margin: 7px 0 0;
}

    .tool-hint.first {
        margin: 0 0 7px;
    }

/* ---------- Buttons ---------- */

.card button {
    font: inherit;
    font-size: 12px;
    min-height: 32px;
    padding: 6px 9px;
    border: 1px solid var(--border-control);
    border-radius: 5px;
    background: white;
    color: var(--accent);
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
}

    .card button:hover:not(:disabled) {
        background: var(--accent-soft);
        border-color: #80b7a5;
    }

    .card button:disabled {
        opacity: .45;
        cursor: default;
    }

    .card :is(button, summary):focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    .card .primary,
    .tabs button.is-active {
        background: var(--accent);
        border-color: var(--accent);
        color: white;
        font-weight: 600;
    }

        .card .primary:hover:not(:disabled),
        .tabs button.is-active:hover:not(:disabled) {
            background: var(--accent-hover);
            border-color: var(--accent-hover);
        }

.btn-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 5px;
}

    .btn-grid.wide {
        grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    }

    .btn-grid button {
        padding-inline: 4px;
    }

.hat-sample,
.bar-sample {
    font-family: "Times New Roman", serif;
    font-style: italic;
}

.hat-sample {
    position: relative;
    display: inline-block;
    padding-top: 3px;
}

    .hat-sample::before {
        content: "";
        position: absolute;
        top: 0;
        left: 15%;
        right: 15%;
        height: 5px;
        border-top: 1.5px solid currentColor;
        border-radius: 50% 50% 0 0;
    }

.bar-sample {
    text-decoration: overline;
}

/* ---------- Symbols ---------- */

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

    .card .tabs button {
        min-height: 28px;
        padding: 3px 8px;
    }

.palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 4px;
}

    .card .palette button {
        min-height: 34px;
        padding: 0;
        font-size: 16px;
        color: #273c33;
    }

/* ---------- Matrix ---------- */

.matrix-picker {
    display: grid;
    grid-template-columns: repeat(8, 24px);
    gap: 3px;
}

.card .matrix-cell {
    width: 24px;
    min-height: 0;
    height: 24px;
    padding: 0;
    border-radius: 3px;
    background: #e6eeea;
    border-color: #d3e0d9;
}

    .card .matrix-cell.is-selected {
        background: var(--accent);
        border-color: var(--accent);
    }

/* ---------- Export ---------- */

/* Copy is the main action: keep it visible at the bottom of the scrolling sidebar. */
.export-tools {
    position: sticky;
    bottom: 0;
    z-index: 1;
    border-color: var(--border-control);
    box-shadow: 0 -6px 12px -6px #0b3b2a26;
}

.copy-action {
    display: block;
    width: 100%;
}

.pair-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 6px;
}

/* ---------- Collapsible groups ---------- */

.tool-details {
    padding: 0;
}

    .tool-details > summary {
        position: relative;
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 40px;
        padding: 10px;
        cursor: pointer;
        font-size: 13px;
        font-weight: 600;
        color: var(--title);
        list-style: none;
        line-height: 1.5;
    }

        .tool-details > summary::-webkit-details-marker {
            display: none;
        }

        .tool-details > summary::after {
            content: "";
            flex: none;
            width: 7px;
            height: 7px;
            margin-left: auto;
            margin-right: 3px;
            border-right: 1.5px solid var(--muted);
            border-bottom: 1.5px solid var(--muted);
            transform: rotate(-45deg);
            transition: transform .15s;
        }

    .tool-details[open] > summary::after {
        transform: rotate(45deg);
    }

    .tool-details[open] > summary {
        border-bottom: 1px solid var(--border);
    }

    .tool-details > summary:hover {
        background: #f1f8f4;
        border-radius: 7px;
    }

.details-content {
    padding: 10px;
}

.help-tools :is(p, li) {
    font-size: 12px;
    color: var(--muted);
}

.help-tools p {
    margin: 0 0 10px;
}

    .help-tools p:last-child {
        margin-bottom: 0;
    }

.help-tools ol {
    margin: 0 0 10px;
    padding-left: 18px;
    line-height: 1.5;
}

.help-tools strong {
    font-weight: 600;
    color: var(--title);
}

.help-tools code {
    overflow-wrap: anywhere;
}

/* ---------- Workspace ---------- */

.workspace {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 12px 16px 16px;
    display: flex;
    flex-direction: column;
}

.workspace-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 32px;
    margin-bottom: 6px;
}

    .workspace-bar:not(:first-child) {
        margin-top: 16px;
    }

.workspace-title {
    font-size: 13px;
    font-weight: 650;
    color: var(--title);
}

.history-actions {
    display: flex;
    gap: 6px;
}

math-field {
    display: block;
    width: 100%;
    min-height: 120px;
    font-size: 30px;
    padding: 14px;
    border: 1px solid var(--border-control);
    border-radius: 7px;
    background: white;
    --caret-color: var(--accent);
    --selection-background-color: #cfe9e1;
}

    math-field:focus-within {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px #d5ede5;
    }

.preview {
    min-height: 90px;
    padding: 10px 14px;
    font-size: 15px;
    border: 1px dashed var(--border);
    border-radius: 7px;
    background: #fbfdfc;
    overflow-x: auto;
}

/* ---------- Status ---------- */

#editorStatus {
    grid-column: 2;
    grid-row: 2;
    font-size: 12px;
    line-height: 1.5;
    margin: 0;
    padding: 5px 10px;
    border-top: 1px solid var(--border);
    max-height: 48px;
    overflow: auto;
    color: var(--muted);
}

    #editorStatus.is-error {
        color: #a33927;
    }

[hidden] {
    display: none !important;
}

/* ---------- Export (off-screen) ---------- */

#exportArea {
    position: absolute;
    left: -9999px;
}

.formula-export {
    display: inline-block;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    margin: 0;
}

.katex {
    line-height: 1.2;
}

.katex-display {
    margin: 0 !important;
}

    .katex-display > .katex {
        padding: 0 !important;
    }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
    .card {
        grid-template-columns: 316px minmax(0, 1fr);
    }
}

@media (max-width: 760px) {
    main {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto minmax(0, 1fr);
        gap: 6px;
        padding: 6px;
    }

    .attribution {
        justify-content: flex-start;
    }

    .card {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) minmax(0, 45%) auto;
    }

    /* Keep the editor on top on phones; tools scroll underneath. */
    .workspace {
        grid-column: 1;
        grid-row: 1;
        padding: 8px;
    }

    .controls {
        grid-column: 1;
        grid-row: 2;
        border-right: 0;
        border-top: 1px solid var(--border);
    }

    .toolbar {
        padding: 8px;
    }

    .export-tools {
        position: static;
        box-shadow: none;
    }

    math-field {
        min-height: 80px;
        font-size: 24px;
    }

    #editorStatus {
        grid-column: 1;
        grid-row: 3;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tool-details > summary::after {
        transition: none;
    }
}
