/* ================= 基本 ================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --accent: #ea580c;
    --accent-soft: #fff7ed;
    --accent-line: #fed7aa;
    --ink: #1f2937;
    --muted: #6b7280;
    --faint: #9ca3af;
    --line: #e5e7eb;
    --mono: 'Consolas', 'Monaco', 'Meiryo', monospace;
}

body {
    font-family: 'Segoe UI', 'Meiryo', sans-serif;
    font-size: 14px;
    color: var(--ink);
    background-color: #f5f6f8;
    min-height: 100vh;
}

#app {
    min-height: 100vh;
    padding: 16px;
    padding-top: 84px;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
}

.page-head {
    margin-bottom: 18px;
}

h1 {
    font-size: 22px;
    color: var(--accent);
    margin-bottom: 4px;
}

.subtitle {
    color: var(--muted);
    font-size: 13px;
}

/* ================= レイアウト ================= */
.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
}

.col-input {
    min-width: 0;
}

.col-result {
    position: sticky;
    top: 84px;
}

/* ================= カード ================= */
.card {
    margin-bottom: 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: #fcfcfd;
}

.card-head h2 {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.stepno {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-body {
    padding: 16px;
}

/* ================= フォーム ================= */
.field {
    display: block;
    margin-bottom: 12px;
}

.field:last-child {
    margin-bottom: 0;
}

.field-label {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

.field-label em {
    font-style: normal;
    color: var(--faint);
    font-weight: 400;
}

input[type="number"],
select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 15px;
    font-family: var(--mono);
    background: #fff;
    color: var(--ink);
}

input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.12);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 12px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0 12px;
}

/* セグメント切替 */
.seg {
    display: inline-flex;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    overflow: hidden;
    background: #f3f4f6;
    margin-bottom: 12px;
}

.seg-wide {
    display: flex;
    width: 100%;
}

.seg label {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.seg label + label {
    border-left: 1px solid #d1d5db;
}

.seg input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.seg span {
    display: block;
    padding: 8px 14px;
    font-size: 12.5px;
    text-align: center;
    color: var(--muted);
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}

.seg label:hover span {
    background: #e9eaec;
}

.seg input:checked + span {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.seg input:focus-visible + span {
    box-shadow: inset 0 0 0 2px rgba(234, 88, 12, 0.5);
}

/* チップ（プリセットボタン） */
.chips {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.chips-label {
    font-size: 11px;
    color: var(--faint);
    margin-right: 2px;
}

.chip {
    padding: 6px 11px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #4b5563;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.chip.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* 諸元の1行表示 */
.specline {
    margin-top: 10px;
    padding: 8px 11px;
    background: #f9fafb;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 12.5px;
    color: #4b5563;
}

/* 導出値の表示 */
.derived {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    border-radius: 7px;
    font-size: 13px;
    color: #9a3412;
    line-height: 1.6;
}

.derived strong {
    font-family: var(--mono);
    font-size: 16px;
}

.hint {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--faint);
    line-height: 1.55;
}

.hint.warn {
    color: #b45309;
    font-weight: 500;
}

.hint:empty {
    display: none;
}

/* ================= 詳細設定 ================= */
.adv {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fafafa;
}

.adv-standalone {
    margin-top: 0;
    margin-bottom: 14px;
    background: #fff;
}

.adv summary {
    padding: 9px 13px;
    font-size: 12.5px;
    color: var(--muted);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.adv summary::-webkit-details-marker {
    display: none;
}

.adv summary::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 5px solid var(--faint);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.15s;
}

.adv[open] summary::before {
    transform: rotate(90deg);
}

.adv summary:hover {
    color: var(--accent);
}

.adv-body {
    padding: 4px 13px 14px;
    border-top: 1px solid var(--line);
}

.adv-body .field:first-child {
    margin-top: 12px;
}

/* ================= 図解 ================= */
.diagram {
    margin-top: 4px;
}

.diagram-block + .diagram-block {
    margin-top: 14px;
}

.diagram-caption {
    font-size: 11.5px;
    color: var(--muted);
    margin-bottom: 4px;
}

.diagram-caption b {
    color: var(--accent);
    font-family: var(--mono);
}

.diagram svg {
    display: block;
    width: 100%;
    max-width: 460px;
    height: auto;
}

/* ================= 結果パネル ================= */
.result-sticky {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    max-height: calc(100vh - 104px);
    overflow-y: auto;
}

.verdict {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 7px;
    border: 1px solid;
    margin-bottom: 10px;
    font-size: 12px;
    line-height: 1.55;
}

.verdict-icon {
    flex-shrink: 0;
    font-weight: 700;
}

.verdict-title {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 2px;
}

.verdict-ok {
    background: #ecfdf5;
    border-color: #6ee7b7;
    color: #065f46;
}

.verdict-ng {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #991b1b;
}

.key {
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
}

.key:first-of-type {
    border-top: 1px solid var(--line);
}

.key-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.key-label {
    font-size: 11.5px;
    color: var(--muted);
}

.key-value {
    font-family: var(--mono);
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
    margin-top: 2px;
}

.key-value small {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    margin-left: 3px;
}

.key-sub {
    font-size: 11px;
    color: var(--faint);
    margin-top: 4px;
    line-height: 1.5;
}

.sub-title {
    font-size: 11px;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 14px 0 4px;
}

.minor {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--line);
}

.minor:last-of-type {
    border-bottom: none;
}

.minor-label {
    font-size: 12px;
    color: var(--muted);
}

.minor-value {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
}

.minor-sub {
    font-size: 10.5px;
    color: var(--faint);
    line-height: 1.5;
    padding-bottom: 7px;
    border-bottom: 1px dashed var(--line);
    margin-top: -3px;
}

.minor-sub:last-child {
    border-bottom: none;
}

.copy-btn {
    flex-shrink: 0;
    padding: 3px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.copy-btn.copied {
    border-color: #10b981;
    color: #10b981;
    background: #ecfdf5;
}

.handoff-btn {
    display: block;
    margin-top: 14px;
    padding: 11px 12px;
    background: var(--accent);
    color: #fff;
    border-radius: 7px;
    text-align: center;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: background-color 0.15s;
}

.handoff-btn:hover {
    background: #c2410c;
}

.handoff-note {
    font-size: 10.5px;
    color: var(--faint);
    text-align: center;
    margin-top: 5px;
}

.error-box {
    padding: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 7px;
    color: #991b1b;
    font-size: 12.5px;
    line-height: 1.6;
}

/* ================= 計算式セクション ================= */
.usage-section {
    margin: 8px 0 24px;
}

.usage-section summary {
    padding: 12px 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    color: #4b5563;
    font-size: 13px;
}

.usage-section summary:hover {
    background: #fafafa;
}

.usage-section[open] summary {
    border-radius: 8px 8px 0 0;
    border-bottom: none;
}

.usage-content {
    padding: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.usage-content h3 {
    font-size: 13.5px;
    color: var(--accent);
    margin: 16px 0 8px;
}

.usage-content h3:first-child {
    margin-top: 0;
}

.usage-content p,
.usage-content ul {
    margin-bottom: 12px;
    color: #4b5563;
    line-height: 1.75;
    font-size: 13px;
}

.usage-content ul {
    margin-left: 20px;
}

.usage-content li {
    margin-bottom: 4px;
}

.usage-content code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 12.5px;
    color: #c2410c;
}

.reference-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 12.5px;
}

.reference-table th,
.reference-table td {
    padding: 8px;
    border: 1px solid var(--line);
    text-align: center;
}

.reference-table th {
    background: #f9fafb;
    font-weight: 500;
    color: var(--muted);
}

.reference-table td {
    font-family: var(--mono);
}

/* ================= レスポンシブ ================= */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    /* 結果は画面下に固定し、入力しながら主要値が常に見えるようにする */
    .col-result {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        z-index: 500;
        padding: 0;
    }

    .result-sticky {
        border-radius: 12px 12px 0 0;
        border-bottom: none;
        max-height: 42vh;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.13);
        padding: 12px 14px 14px;
    }

    /* 固定バーに隠れないよう下に余白を確保 */
    .col-input {
        padding-bottom: 44vh;
    }

    /*
     * スマホでは主要3値を横に並べてバーを薄くする。
     * 隠した値も入力側に出ている（GSD＝手順2の導出欄、主点間距離＝手順3の図解）ので
     * 情報は失われない。
     */
    .keys {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0 8px;
        border-top: 1px solid var(--line);
        padding-top: 8px;
    }

    .key {
        padding: 2px 0 4px;
        border-bottom: none;
    }

    .key:first-of-type {
        border-top: none;
    }

    .key-sub,
    .sub-title,
    .minor,
    .minor-sub,
    .result-sticky .copy-btn {
        display: none;
    }

    .key-value {
        font-size: 19px;
    }

    .key-value small {
        font-size: 11px;
    }

    .key-label {
        font-size: 10.5px;
    }

    .verdict {
        margin-bottom: 6px;
        padding: 8px 10px;
    }

    .handoff-btn {
        margin-top: 10px;
        padding: 10px 12px;
    }
}

@media (max-width: 560px) {
    #app {
        padding: 12px;
        padding-top: 74px;
    }

    h1 {
        font-size: 19px;
    }

    .card-body {
        padding: 13px;
    }

    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    .seg span {
        padding: 8px 8px;
        font-size: 11.5px;
    }

    .reference-table {
        font-size: 11px;
    }

    .reference-table th,
    .reference-table td {
        padding: 4px;
    }
}
