:root {
    --bg: #c9c9c9;
    --panel: #dcdcdc;
    --line-dark: #6f6f6f;
    --line-light: #ffffff;
    --text: #111111;
    --accent: #0039c6;
    --error: #a60000;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Verdana", "Tahoma", sans-serif;
    background: linear-gradient(145deg, #f3f3f3 0%, #bdbdbd 100%);
    color: var(--text);
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 14px;
}

.window {
    width: min(1080px, 100%);
    min-height: 760px;
    background: var(--bg);
    border: 1px solid var(--line-dark);
    box-shadow: inset -1px -1px 0 var(--line-dark), inset 1px 1px 0 var(--line-light);
}

.window-header {
    position: relative;
    padding: 14px 16px;
    background: linear-gradient(90deg, #ff31b0 0%, #5d34d8 40%, #00ba3c 100%);
    color: #fff;
    border-bottom: 1px solid var(--line-dark);
}

.window-header h1 {
    margin: 0;
    font-size: 1.7rem;
}

.app-version {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.65rem;
    font-weight: 400;
    color: #ffffff;
    opacity: 0.9;
    vertical-align: baseline;
}

.window-header p {
    margin: 4px 0 0;
}

.main-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px 0;
}

.sub-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px 0;
}

.tab-link {
    border: 1px solid #626f86;
    background: #ccd9ee;
    box-shadow: inset -1px -1px 0 #6f7f98, inset 1px 1px 0 #f5f8ff;
    padding: 7px 11px;
    font-size: 0.95rem;
    color: #0f1f3c;
    text-decoration: none;
    font-weight: 700;
}

.sub-tab {
    border: 1px solid var(--line-dark);
    background: #e7e7d8;
    box-shadow: inset -1px -1px 0 var(--line-dark), inset 1px 1px 0 var(--line-light);
    padding: 7px 11px;
    font-size: 0.95rem;
    color: var(--text);
    text-decoration: none;
}

.sub-tab .unit-katex,
.tab-link .unit-katex {
    display: inline-flex;
    align-items: center;
}

.sub-tab .katex,
.tab-link .katex {
    font-size: 0.95em;
}

.tab-link.active {
    background: #e8f0ff;
}

.sub-tab.active {
    background: #f5f5eb;
    font-weight: 700;
}

.sub-tabs-placeholder {
    visibility: hidden;
    pointer-events: none;
}

.content {
    padding: 14px;
}

.stage {
    min-height: 470px;
}

.panel {
    background: #d5d5d5;
    border: 1px solid #979797;
    box-shadow: inset -1px -1px 0 var(--line-dark), inset 1px 1px 0 var(--line-light);
    padding: 12px;
}

.primary-panel {
    min-height: 440px;
}

.fixed-height {
    min-height: 130px;
}

.intro {
    color: var(--accent);
    margin-top: 0;
}

.parallel-r-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: stretch;
}

.single-calc-layout {
    display: block;
}

.single-calc-main {
    max-width: 560px;
}

.calc-form {
    display: grid;
    gap: 8px;
    max-width: 100%;
}

.calc-form input {
    border: 1px solid #9e9e9e;
    background: #f6f6e8;
    padding: 7px 8px;
    font-size: 1rem;
    width: 100%;
}

.actions {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

button,
.reset-link {
    border: 1px solid var(--line-dark);
    background: var(--panel);
    box-shadow: inset -1px -1px 0 var(--line-dark), inset 1px 1px 0 var(--line-light);
    padding: 6px 10px;
    font-size: 0.95rem;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}

.message.error {
    margin: 12px 0;
    color: var(--error);
}

.result-block {
    margin-top: 12px;
    display: grid;
    gap: 6px;
}

.constants-box {
    width: fit-content;
    margin: 4px 0 12px;
    padding: 10px 12px;
    border: 1px solid #989898;
    background: #ececec;
}

.constants-box p {
    margin: 0;
}

.constants-box p + p {
    margin-top: 8px;
}

.mode-select {
    border: 1px solid #9a9a9a;
    padding: 8px 10px;
    margin: 0 0 2px;
    background: #ececec;
    display: grid;
    gap: 6px;
}

.mode-select label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.mode-select input[type="radio"] {
    width: auto;
    margin: 0;
}

.level-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: start;
}

.level-card {
    border: 1px solid #979797;
    background: #e7e7e7;
    padding: 8px;
}

.level-info {
    border: none;
    background: transparent;
    padding: 0;
}

.level-card h3 {
    margin: 0 0 8px;
    color: #0024b0;
    font-size: 1rem;
}

.level-output {
    display: inline-block;
    width: 100%;
    min-height: 32px;
    border: 1px solid #9e9e9e;
    background: #f6f6e8;
    padding: 7px 8px;
    font-weight: 700;
}

.level-info p {
    margin: 0;
    line-height: 1.3;
    font-size: 0.95rem;
}

.level-info p + p {
    margin-top: 8px;
}

.level-formulas {
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.level-formula-box {
    justify-content: center;
    min-height: 84px;
}

.gain-layout {
    max-width: 560px;
}

.gain-mode-select {
    margin-top: 2px;
}

.gain-formulas-row {
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    max-width: 560px;
}

.gain-formula-box {
    justify-content: center;
    min-height: 78px;
}

.result-block output {
    display: inline-block;
    width: 100%;
    min-height: 36px;
    border: 1px solid #9e9e9e;
    background: #f6f6e8;
    padding: 8px;
    font-weight: 700;
}

.parallel-r-right {
    display: grid;
    place-items: center;
    height: 100%;
}

.parallel-r-right img {
    width: min(420px, 100%);
    height: auto;
    display: block;
}

.image-placeholder {
    width: min(420px, 100%);
    min-height: 230px;
    border: 1px dashed #8f8f8f;
    background: #e9e9e9;
    display: grid;
    place-items: center;
    color: #666;
    font-weight: 700;
}

.formula-box {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 2px solid #ffd400;
    background: linear-gradient(135deg, #d10000 0%, #ff2f2f 100%);
    color: #fff;
    font-weight: 700;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

.formula-box .katex {
    color: #ffffff;
    font-size: 1.6rem;
    font-weight: 400;
}

.formula-box .katex-display {
    margin: 0;
}

.formula-box [data-katex] {
    display: block;
}

.unit-katex {
    display: inline-block;
    vertical-align: baseline;
}

.unit-katex .katex {
    font-size: 1em;
}

.level-formula-box .katex,
.gain-formula-box .katex {
    font-size: 1.35rem;
}

.formula-box-triangle {
    width: min(290px, 100%);
    min-height: 190px;
    justify-content: center;
    padding: 10px 12px;
}

.triangle-svg {
    width: min(260px, 100%);
    height: auto;
    display: block;
}

.triangle-hybrid {
    position: relative;
    width: min(260px, 100%);
}

.triangle-svg line {
    stroke: #ffffff;
    stroke-width: 4;
    stroke-linecap: round;
}

.triangle-label {
    position: absolute;
    color: #ffffff;
    line-height: 1;
}

.triangle-label .katex {
    color: #ffffff;
    font-size: 1.2rem;
}

.triangle-label-u {
    left: 50%;
    top: 8%;
    transform: translateX(-50%);
}

.triangle-label-r {
    left: 26%;
    top: 76%;
    transform: translateX(-50%);
}

.triangle-label-i {
    left: 74%;
    top: 76%;
    transform: translateX(-50%);
}

.formula-prefix {
    font-size: 1.45rem;
}

.formula-inline {
    font-size: 1.45rem;
    line-height: 1;
}

.fraction {
    display: inline-grid;
    text-align: center;
    line-height: 1.1;
}

.fraction .top {
    border-bottom: 2px solid #fff;
    padding: 0 4px 2px;
}

.fraction .bottom {
    padding-top: 2px;
}

.placeholder-card {
    border: 1px dashed #8d8d8d;
    background: #ececec;
    padding: 14px;
}

.placeholder-card h2 {
    margin: 0 0 8px;
}

.placeholder-card p {
    margin: 0;
}

.header-actions {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    z-index: 6;
}

.darc-trigger {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line-dark);
    background: var(--panel);
    box-shadow: inset -1px -1px 0 var(--line-dark), inset 1px 1px 0 var(--line-light);
    padding: 6px;
}

.darc-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.homage-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid var(--line-dark);
    background: var(--panel);
    box-shadow: inset -1px -1px 0 var(--line-dark), inset 1px 1px 0 var(--line-light);
    padding: 8px 10px;
    cursor: pointer;
    user-select: none;
    font-weight: 700;
    color: #111;
    z-index: 6;
}

.homage-trigger span {
    display: inline-block;
    line-height: 1;
    text-align: center;
}

.fish-icon {
    width: 28px;
    height: 28px;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.homage-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: grid;
    align-items: start;
    justify-items: end;
    padding: 24px;
    z-index: 50;
}

.homage-overlay[hidden] {
    display: none;
}

.homage-dialog {
    width: min(420px, calc(100vw - 24px));
    border: 1px solid #6d6d6d;
    box-shadow: inset -1px -1px 0 #656565, inset 1px 1px 0 #ffffff, 0 10px 24px rgba(0, 0, 0, 0.35);
    background: #d9d9d9;
}

.homage-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    background: linear-gradient(90deg, #ff31b0 0%, #5d34d8 40%, #00ba3c 100%);
    border-bottom: 1px solid #4b4b4b;
}

.homage-dialog-head h2 {
    margin: 0;
    font-size: 1.05rem;
    color: #ffffff;
}

.homage-close {
    border: 1px solid #555;
    background: #e5e5e5;
    color: #111;
    font-weight: 700;
    width: 24px;
    height: 24px;
    line-height: 1;
    padding: 0;
    display: inline-grid;
    place-items: center;
    font-size: 14px;
    font-family: "Verdana", "Tahoma", sans-serif;
    cursor: pointer;
    box-shadow: inset -1px -1px 0 #666, inset 1px 1px 0 #fff;
}

.homage-content {
    padding: 12px;
    background: #efefef;
    border-top: 1px solid #ffffff;
    color: #0f0f0f;
    line-height: 1.45;
    font-size: 0.98rem;
}

.homage-panel[hidden] {
    display: none !important;
}

.homage-panel-farewell {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding: 0;
}

.homage-farewell-image {
    width: auto;
    max-width: 100%;
    max-height: 100%;
    height: auto;
    display: block;
}

.homage-dialog.is-farewell .homage-content {
    background: #ffffff;
    display: grid;
    align-items: center;
}

.portrait-frame {
    width: 106px;
    height: 136px;
    border: 1px solid #555;
    box-shadow: inset -1px -1px 0 #777, inset 1px 1px 0 #fff;
    background: #efefef;
    display: grid;
    place-items: center;
    margin-bottom: 10px;
}

.portrait-frame img {
    width: 92px;
    height: auto;
    border: 1px solid #9a9a9a;
}

.author-meta p,
.homage-text,
.explanation p {
    margin: 0;
}

.author-meta p + p,
.homage-text,
.explanation p + p {
    margin-top: 8px;
}

.explanation h2 {
    margin-top: 0;
}

.site-footer {
    padding: 8px 14px 12px;
    text-align: center;
}

.legal-link {
    font-size: 0.82rem;
    color: #3f3f3f;
    text-decoration: none;
}

.legal-link:hover,
.legal-link:focus-visible {
    text-decoration: none;
}

.legal-layout {
    width: min(1080px, 100%);
    min-height: 760px;
}

.legal-main {
    padding-top: 14px;
}

.legal-main .panel + .panel {
    margin-top: 12px;
}

.legal-main h2 {
    margin-top: 0;
}

.legal-main p {
    margin: 0;
    line-height: 1.45;
}

.legal-main p + p {
    margin-top: 8px;
}

.legal-back {
    margin-top: 14px;
}

@media (max-width: 900px) {
    body {
        padding: 0;
    }

    .parallel-r-layout {
        grid-template-columns: 1fr;
    }

    .level-layout,
    .level-formulas {
        grid-template-columns: 1fr;
    }

    .gain-layout {
        max-width: 100%;
    }

    .gain-formulas-row {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .parallel-r-right {
        min-height: 0;
    }

    .window-header {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }

    .window {
        width: 100%;
        min-height: 100vh;
    }

    .main-tabs,
    .sub-tabs {
        flex-wrap: wrap;
    }

    .calc-form {
        max-width: 100%;
    }

    .stage,
    .primary-panel,
    .fixed-height {
        min-height: 0;
    }

    .header-actions {
        position: static;
        transform: none;
        display: inline-flex;
        align-self: flex-end;
        margin-top: 8px;
    }

    .homage-trigger {
        margin-top: 0;
    }

    .homage-overlay {
        padding: 10px;
        justify-items: stretch;
    }

    .site-footer {
        text-align: center;
    }
}
