:root {
    --bg: #eef4f8;
    --panel: #ffffff;
    --text: #152033;
    --muted: #65758b;
    --line: #d7e0ea;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --chalk: #f2fffb;
    --teal-board: #0b4b40;
    --teal-board-dark: #083b34;
    --blue-line: #1d67d8;
    --orange-line: #e26b2c;
    --gold: #b7791f;
    --gold-soft: #fff7e6;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --success-bg: #ecfdf3;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.18), transparent 30%),
        linear-gradient(140deg, rgba(183, 121, 31, 0.12), transparent 42%),
        var(--bg);
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 40px 20px;
}

.hero {
    width: min(100%, 900px);
    padding: 0;
    text-align: center;
}

.hero p {
    margin: 0 0 12px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.hero h1 {
    margin: 0;
    font-size: 44px;
    line-height: 1.08;
}

.hero strong {
    display: block;
    margin-top: 10px;
    color: var(--accent-dark);
    font-size: 16px;
    letter-spacing: 0;
}

.hero span {
    display: block;
    margin: 14px auto 0;
    max-width: 560px;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.6;
}

.panel {
    width: min(100%, 860px);
    padding: 26px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 26px 80px rgba(21, 32, 51, 0.16);
}

.calculator {
    display: grid;
    gap: 18px;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr 160px;
    gap: 12px;
    align-items: end;
}

.order-picker {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.workspace {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.matrix-card {
    border: 1px solid var(--line);
    border-radius: 8px;
}

.matrix-card {
    padding: 16px;
    background: var(--teal-board);
    border-color: rgba(242, 255, 251, 0.22);
    box-shadow: inset 0 0 0 2px rgba(242, 255, 251, 0.08);
    overflow: hidden;
}

.matrix-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.matrix-title span {
    color: var(--text);
    font-weight: 800;
}

.matrix-card .matrix-title span {
    color: var(--chalk);
}

.matrix-title small {
    color: rgba(242, 255, 251, 0.7);
}

select,
input {
    width: 100%;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background: #fbfdff;
    font-size: 18px;
}

select {
    padding: 0 14px;
}

input {
    text-align: center;
}

input:focus,
select:focus {
    outline: 3px solid rgba(15, 118, 110, 0.18);
    border-color: var(--accent);
}

.matrix {
    display: none;
    gap: 10px;
    position: relative;
    padding: 10px 16px 10px 64px;
}

.matrix.is-active {
    display: grid;
}

.matrix-shell {
    position: relative;
    width: max-content;
    min-height: 176px;
    margin: 14px auto 8px;
    display: grid;
    align-items: center;
    justify-content: center;
}

.det-label {
    position: absolute;
    left: 0;
    top: 50%;
    z-index: 4;
    color: var(--chalk);
    font-size: 30px;
    font-weight: 800;
    transform: translateY(-50%);
}

.matrix-shell::before,
.matrix-shell::after {
    content: "";
    position: absolute;
    top: 14px;
    bottom: 14px;
    width: 12px;
    z-index: 1;
    border: 3px solid rgba(242, 255, 251, 0.95);
}

.matrix-shell::before {
    left: 54px;
    border-right: 0;
}

.matrix-shell::after {
    left: 184px;
    right: auto;
    border-left: 0;
}

.matrix-2 {
    grid-template-columns: repeat(2, 50px);
    grid-template-rows: repeat(2, 50px);
    width: auto;
    gap: 20px 24px;
    margin-left: 118px;
    padding: 0;
}

.matrix-3 {
    grid-template-columns: repeat(5, 38px);
    grid-template-rows: repeat(3, 38px);
    width: 310px;
}

.matrix-3.sarrus-board {
    isolation: isolate;
}

.cell {
    position: relative;
    z-index: 3;
}

.matrix-3 input,
.matrix-2 input {
    min-height: 38px;
    padding: 0;
    border: 0;
    color: var(--chalk);
    background: transparent;
    font-size: 24px;
    font-family: Georgia, "Times New Roman", serif;
    text-align: center;
}

.matrix-2 input {
    border: 0;
    border-radius: 0;
}

.matrix-card.order-2 {
    padding-bottom: 18px;
}

.matrix-card.order-2 .matrix-shell {
    width: 360px;
    min-height: 162px;
    margin-top: 10px;
}

.matrix-card.order-2 .det-label {
    left: 28px;
}

.matrix-card.order-2 .matrix-shell::before {
    left: 150px;
}

.matrix-card.order-2 .matrix-shell::after {
    left: 300px;
}

.matrix-card.order-2 .matrix-shell::before,
.matrix-card.order-2 .matrix-shell::after {
    top: 18px;
    bottom: 18px;
}

.matrix-card.order-2 .matrix-2 input {
    min-height: 50px;
    font-size: 30px;
    background: transparent;
}

.matrix-card.order-2 .matrix-title small::after {
    content: " - gunakan rumus ad - bc";
}

.matrix-3 input::placeholder,
.matrix-2 input::placeholder {
    color: rgba(242, 255, 251, 0.95);
    opacity: 1;
}

.matrix-3 input:focus,
.matrix-2 input:focus {
    outline: 2px solid rgba(242, 255, 251, 0.7);
    background: rgba(242, 255, 251, 0.12);
}

.ghost {
    display: grid;
    place-items: center;
    color: var(--chalk);
    font-size: 24px;
    font-family: Georgia, "Times New Roman", serif;
}

.line {
    position: absolute;
    z-index: 2;
    width: 136px;
    height: 3px;
    border-radius: 99px;
    opacity: 0.9;
    pointer-events: none;
    transform-origin: left center;
}

.line.down {
    background: var(--blue-line);
    transform: rotate(45deg);
}

.line.up {
    background: var(--orange-line);
    transform: rotate(-45deg);
}

.down-1 {
    left: 83px;
    top: 29px;
}

.down-2 {
    left: 131px;
    top: 29px;
}

.down-3 {
    left: 179px;
    top: 29px;
}

.up-1 {
    left: 83px;
    top: 125px;
}

.up-2 {
    left: 131px;
    top: 125px;
}

.up-3 {
    left: 179px;
    top: 125px;
}

button {
    min-height: 52px;
    border: 0;
    border-radius: 6px;
    color: #ffffff;
    background: var(--accent);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

button:hover {
    background: var(--accent-dark);
}

.result {
    display: grid;
    gap: 10px;
    margin-top: 22px;
    padding: 20px;
    border-radius: 8px;
}

.result div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.result span {
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.result strong {
    color: var(--accent-dark);
    font-size: 36px;
    line-height: 1;
}

.result p {
    margin: 0;
    color: var(--text);
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.result-detail {
    color: var(--muted) !important;
}

.result.success {
    background: var(--success-bg);
    border: 1px solid #abefc6;
}

.result.error {
    background: var(--danger-bg);
    border: 1px solid #fecdca;
}

.result.error strong {
    color: var(--danger);
    font-size: 18px;
}

.result.muted {
    background: #f8fafc;
    border: 1px dashed var(--line);
}

@media (max-width: 900px) {
    .page {
        justify-content: flex-start;
        padding: 32px 18px;
    }

    .hero h1 {
        font-size: 38px;
    }

    .panel {
        width: min(100%, 760px);
    }
}

@media (max-width: 680px) {
    .page {
        gap: 18px;
        padding: 28px 14px;
    }

    .hero h1 {
        font-size: 34px;
    }

    .hero strong {
        font-size: 14px;
    }

    .hero span {
        max-width: 420px;
        font-size: 15px;
    }

    .panel {
        padding: 18px;
    }

    .toolbar {
        grid-template-columns: 1fr;
    }

    button,
    select {
        min-height: 48px;
    }

    .matrix-title {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .result div {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }
}

@media (max-width: 520px) {
    .page {
        display: flex;
        padding: 22px 12px;
    }

    .hero {
        padding: 0;
    }

    .hero h1 {
        font-size: 30px;
        line-height: 1.15;
    }

    .hero span {
        font-size: 15px;
    }

    .panel {
        padding: 18px;
    }

    .toolbar,
    .workspace {
        grid-template-columns: 1fr;
    }

    .matrix {
        gap: 8px;
        padding: 8px 8px 8px 48px;
    }

    input {
        min-height: 46px;
        font-size: 16px;
    }

    .matrix-shell {
        min-height: 150px;
    }

    .det-label {
        font-size: 22px;
    }

    .matrix-shell::before {
        left: 42px;
    }

    .matrix-shell::after {
        left: 146px;
    }

    .matrix-2 {
        grid-template-columns: repeat(2, 36px);
        grid-template-rows: repeat(2, 36px);
        gap: 18px 20px;
        margin-left: 88px;
        width: auto;
    }

    .matrix-3 {
        grid-template-columns: repeat(5, 30px);
        grid-template-rows: repeat(3, 30px);
        width: 230px;
    }

    .matrix-3 input,
    .matrix-2 input,
    .ghost {
        min-height: 30px;
        font-size: 20px;
    }

    .matrix-card.order-2 .matrix-shell {
        width: 300px;
        max-width: 100%;
        min-height: 150px;
    }

    .matrix-card.order-2 .det-label {
        left: 0;
    }

    .matrix-card.order-2 .matrix-shell::before {
        left: 96px;
    }

    .matrix-card.order-2 .matrix-shell::after {
        left: 250px;
    }

    .matrix-card.order-2 .matrix-shell::before,
    .matrix-card.order-2 .matrix-shell::after {
        top: 14px;
        bottom: 14px;
    }

    .matrix-card.order-2 .matrix-2 input {
        min-height: 44px;
        font-size: 26px;
    }

    .matrix-card.order-2 .matrix-2 {
        grid-template-columns: repeat(2, 44px);
        grid-template-rows: repeat(2, 44px);
        gap: 20px 28px;
        margin-left: 122px;
        padding: 0;
    }

    .line {
        width: 104px;
    }

    .down-1 {
        left: 62px;
        top: 25px;
    }

    .down-2 {
        left: 100px;
        top: 25px;
    }

    .down-3 {
        left: 138px;
        top: 25px;
    }

    .up-1 {
        left: 62px;
        top: 101px;
    }

    .up-2 {
        left: 100px;
        top: 101px;
    }

    .up-3 {
        left: 138px;
        top: 101px;
    }

    .result {
        padding: 16px;
    }

    .result strong {
        font-size: 30px;
    }
}

@media (max-width: 380px) {
    .page {
        padding: 18px 10px;
    }

    .hero h1 {
        font-size: 26px;
    }

    .panel {
        padding: 14px;
    }

    .matrix-card {
        padding: 12px;
    }

    .matrix-title small {
        font-size: 12px;
    }

    .matrix-shell {
        min-height: 138px;
    }

    .det-label {
        font-size: 20px;
    }

    .matrix {
        padding-left: 42px;
    }

    .matrix-3 {
        grid-template-columns: repeat(5, 27px);
        grid-template-rows: repeat(3, 27px);
        width: 208px;
    }

    .matrix-3 input,
    .matrix-2 input,
    .ghost {
        min-height: 27px;
        font-size: 18px;
    }

    .matrix-shell::before {
        left: 36px;
    }

    .matrix-shell::after {
        left: 128px;
    }

    .line {
        width: 92px;
    }

    .down-1,
    .up-1 {
        left: 56px;
    }

    .down-2,
    .up-2 {
        left: 91px;
    }

    .down-3,
    .up-3 {
        left: 126px;
    }

    .down-1,
    .down-2,
    .down-3 {
        top: 24px;
    }

    .up-1,
    .up-2,
    .up-3 {
        top: 94px;
    }

    .matrix-card.order-2 .matrix-shell {
        width: 250px;
        min-height: 138px;
    }

    .matrix-card.order-2 .matrix-shell::before {
        left: 76px;
    }

    .matrix-card.order-2 .matrix-shell::after {
        left: 210px;
    }

    .matrix-card.order-2 .matrix-2 {
        grid-template-columns: repeat(2, 36px);
        grid-template-rows: repeat(2, 36px);
        gap: 18px 20px;
        margin-left: 10dvw;
        padding: 0;
    }

    .matrix-card.order-2 .matrix-2 input {
        min-height: 36px;
        font-size: 22px;
    }
}