:root {
    --font-text: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
    /* Fira Code에는 한글이 없으므로 한글은 Pretendard로 넘긴다. */
    --font-num: "Fira Code", "Pretendard Variable", Pretendard, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --content-width: 1200px;
    color-scheme: dark;

    --bg: #111214;
    --card: #1a1c20;
    --text: #e8e9ec;
    --text-muted: #9a9ea8;
    --border: #2c2f36;
    --hover: #23262c;
    --focus: #849dff;
    --danger: #ff6369;

    /* float.exposed와 같은 배색: 부호 빨강, 지수 초록, 가수 파랑 */
    --sign: #ff6369;
    --exponent: #3dd68c;
    --significand: #7b93f7;
    --combination: #bf7af0;
    --marker: #ff9a3d;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-text);
    font-size: 16px;
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}

a {
    color: var(--significand);
}

h1 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.01em;
}

h1:focus {
    outline: none;
}

button {
    font: inherit;
    color: inherit;
}

sup, sub {
    font-size: 0.68em;
    line-height: 0;
}

.num {
    font-family: var(--font-num);
    font-variant-ligatures: none;
}

.inline-link {
    margin-right: 0.6rem;
}

.k-sign { --kind: var(--sign); }
.k-exp { --kind: var(--exponent); }
.k-sig { --kind: var(--significand); }
.k-comb { --kind: var(--combination); }
.k-mark { --kind: var(--marker); }
.k-pad { --kind: var(--text-muted); }

.c-sign { color: var(--sign); }
.c-exp { color: var(--exponent); }
.c-sig { color: var(--significand); }

/* 형식 탭: 넓은 화면에서는 왼쪽 세로 목록, 좁은 화면에서는 위쪽 가로 목록 */
.explorer {
    display: grid;
    grid-template-columns: 9.5rem minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
    margin-top: 0.75rem;
}

.explorer-main {
    min-width: 0;
}

.tabs {
    position: sticky;
    top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.tab {
    font-family: var(--font-num);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.32rem 0.75rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}

/* 십진 형식은 색으로 구분한다. */
.tab.decimal {
    color: var(--combination);
}

.tab:hover {
    background: var(--hover);
}

.tab.active {
    background: var(--text);
    color: var(--bg);
}

.format-head {
    padding-bottom: 0.25rem;
}

.format-note {
    margin: 0.3rem 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

/* 항목: float.exposed처럼 가운데 맞춘 제목과 내용을 구분선으로 나눈다. */
.block {
    padding: 1.4rem 0;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.block:last-child {
    border-bottom: none;
}

.block-label {
    font-family: var(--font-num);
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.badge {
    font-family: var(--font-text);
    font-size: 0.75rem;
    padding: 0.05rem 0.5rem;
    margin-left: 0.35rem;
    border-radius: 999px;
    background: var(--hover);
}

.message {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.message.error {
    color: var(--danger);
}

/*
 * 한 줄 맞춤: 칸을 크기 컨테이너로 두고, 글씨 크기를 "(칸 너비 ÷ --chars − 1px) ÷ 0.6"과 기본 크기 중 작은 쪽으로 한다.
 * Fira Code는 고정폭이라 글자 폭이 0.6em이고, 작은 크기에서 글자 폭이 정수 px로 올림되는 몫을 글자당 1px로 잡는다.
 */
.value-fit, .fit, .neighbor {
    container-type: inline-size;
}

/* Value */
.value-fit {
    width: 100%;
    max-width: 52rem;
    margin: 0 auto;
}

.value-input {
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font-size: min(clamp(1.6rem, 4.5vw, 3rem), calc(((100cqw - 1rem - 6px) / var(--chars) - 1px) / 0.6));
    font-weight: 600;
    text-align: center;
}

.value-input:hover {
    border-color: var(--border);
}

.value-input:focus {
    outline: none;
    border-color: var(--focus);
    background: var(--card);
}

.value-input.invalid {
    border-color: var(--danger);
}

/* 입력한 값 · 저장된 값 · 차이 */
dl.entered {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.3rem 1rem;
    max-width: 52rem;
    margin: 0.9rem auto 0;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    text-align: left;
}

dl.entered dt {
    font-size: 0.82rem;
}

dl.entered dd {
    font-size: 0.95rem;
    overflow-wrap: anywhere;
}

.exact-note {
    margin-left: 0.4rem;
    font-family: var(--font-text);
    font-size: 0.82rem;
    color: var(--exponent);
}

/* Bit Pattern */
.bit-pattern {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem 1rem;
    /* 한 줄에 4바이트(32비트)씩 */
    max-width: 52rem;
    margin: 0 auto;
}

.bit-group {
    display: inline-flex;
    gap: 0.12rem;
}

.bit {
    width: 1.35rem;
    padding: 0 0 0.15rem;
    border: none;
    border-bottom: 3px solid var(--kind);
    border-radius: 1px;
    background: transparent;
    color: var(--text);
    font-family: var(--font-num);
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
}

.bit.alt {
    border-bottom-style: double;
}

.bit:hover:not(:disabled) {
    background: var(--hover);
}

.bit:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.bit:disabled {
    cursor: not-allowed;
    color: var(--text-muted);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.3rem 1rem;
    margin-top: 0.9rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.swatch {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 2px;
    background: var(--kind);
    margin-right: 0.35rem;
    vertical-align: -0.02rem;
}

/* Sign·Exponent·Significand / Raw 값 칸 */
.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 2.5rem;
    text-align: left;
    max-width: 50rem;
    margin: 0 auto;
}

.field-column {
    display: grid;
    gap: 0.8rem;
    align-content: start;
    min-width: 0;
}

.field-box {
    min-width: 0;
}

.field-label {
    display: block;
    font-family: var(--font-num);
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.field-row {
    display: flex;
    gap: 0.3rem;
    align-items: stretch;
}

.fit {
    flex: 1;
    min-width: 0;
}

.field-row input {
    width: 100%;
    min-width: 0;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    color: var(--kind, var(--text));
    font-size: min(1.05rem, calc(((100cqw - 1.2rem - 6px) / var(--chars) - 1px) / 0.6));
    font-weight: 600;
    text-align: right;
}

.field-row input:focus {
    outline: none;
    border-color: var(--focus);
}

.field-row input.invalid {
    border-color: var(--danger);
}

.stepper {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 2px;
    width: 1.4rem;
}

.stepper-spacer {
    width: 1.4rem;
}

.stepper button {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.stepper button:hover {
    color: var(--text);
    background: var(--hover);
}

/* Position within Significand–Exponent Range */
.chart {
    display: block;
    width: 100%;
    max-width: 50rem;
    margin: 0 auto;
    touch-action: none;
    cursor: crosshair;
    user-select: none;
}

.chart .axis {
    fill: var(--text-muted);
    font-family: var(--font-num);
    font-size: 15px;
    font-weight: 600;
}

.chart .row-line {
    stroke: var(--border);
    stroke-width: 2;
}

.chart .range-box {
    fill: var(--card);
    stroke: var(--border);
    stroke-width: 2;
}

.chart .cross-exp {
    stroke: var(--exponent);
    stroke-width: 3;
}

.chart .cross-sig {
    stroke: var(--significand);
    stroke-width: 3;
}

.chart .knob {
    fill: var(--bg);
    stroke: var(--text-muted);
    stroke-width: 2;
}

.chart .knob-dot {
    fill: var(--text-muted);
}

/* Evaluation, Exact value, Delta */
.evaluation {
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.9;
    overflow-wrap: anywhere;
}

.fold {
    margin-left: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    color: var(--text-muted);
    font-family: var(--font-text);
    font-size: 0.78rem;
    font-weight: 400;
    padding: 0.05rem 0.55rem;
    vertical-align: 0.1em;
    cursor: pointer;
    white-space: nowrap;
}

.fold:hover {
    color: var(--text);
    background: var(--hover);
}

.delta-pair {
    display: grid;
    gap: 1.2rem;
}

details.expand {
    margin-top: 0.4rem;
    text-align: left;
}

details.expand summary {
    cursor: pointer;
    font-family: var(--font-text);
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted);
    text-align: center;
}

details.expand .long {
    margin-top: 0.5rem;
    max-height: 18rem;
    overflow: auto;
    font-size: 0.85rem;
    padding: 0.6rem;
    border-radius: 8px;
    background: var(--card);
    overflow-wrap: anywhere;
}

.remarks p {
    margin: 0.2rem 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.block-text {
    margin: 0 0 0.75rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.copy {
    margin-left: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-text);
    font-size: 0.75rem;
    padding: 0.05rem 0.5rem;
    cursor: pointer;
}

.copy:hover {
    color: var(--text);
    background: var(--hover);
}

/* 이전 값 · 다음 값 */
.neighbor-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    max-width: 50rem;
    margin: 0 auto;
}

.neighbor {
    display: grid;
    gap: 0.15rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    text-align: left;
    cursor: pointer;
    min-width: 0;
}

button.neighbor:hover {
    border-color: var(--focus);
}

.neighbor.empty {
    cursor: default;
}

.neighbor-label {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.neighbor-value {
    font-size: min(1.05rem, calc((100cqw / var(--chars) - 1px) / 0.6));
    font-weight: 600;
    white-space: nowrap;
}

.neighbor-hex {
    font-size: min(0.82rem, calc((100cqw / var(--hex-chars) - 1px) / 0.6));
    color: var(--text-muted);
    white-space: nowrap;
}

/* 필드 해석 */
.table-wrap {
    overflow-x: auto;
    max-width: 56rem;
    margin: 0 auto;
}

table.fields {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

table.fields th {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
}

table.fields td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    overflow-wrap: anywhere;
}

table.fields tr:last-child td {
    border-bottom: none;
}

table.fields td:first-child {
    white-space: nowrap;
}

.bitstring {
    word-break: break-all;
    min-width: 8ch;
    max-width: 30ch;
}

/* 바로 가기, 형식 정보 */
.presets {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}

.chip {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.chip:hover {
    background: var(--hover);
}

.constants-label {
    margin-top: 1rem;
}

.chip.active {
    background: var(--text);
    color: var(--bg);
}

dl.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.5rem 1.25rem;
    margin: 0 auto;
    max-width: 44rem;
    text-align: left;
}

dl dt {
    color: var(--text-muted);
    font-size: 0.88rem;
    padding-top: 0.1rem;
}

dl dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 820px) {
    .explorer {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.75rem;
    }

    .tabs {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .tab {
        border: 1px solid var(--border);
        background: var(--card);
        border-radius: 999px;
        font-size: 0.85rem;
        padding: 0.28rem 0.65rem;
    }
}

@media (max-width: 640px) {
    .neighbor-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    /* 좁은 화면에서는 필드 표를 행마다 쌓는다. */
    table.fields thead {
        display: none;
    }

    table.fields, table.fields tbody, table.fields tr, table.fields td {
        display: block;
    }

    table.fields tr {
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--border);
    }

    table.fields tr:last-child {
        border-bottom: none;
    }

    table.fields td {
        border: none;
        padding: 0.1rem 0;
    }

    .bitstring {
        max-width: none;
    }

    .field-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.8rem;
    }

    .bit {
        width: 1.05rem;
        font-size: 1.05rem;
    }

    .bit-pattern {
        gap: 0.3rem 0.6rem;
    }

    .evaluation {
        font-size: 1rem;
    }

    dl.facts {
        grid-template-columns: 1fr;
        gap: 0.1rem;
    }

    dl dd {
        margin-bottom: 0.5rem;
    }
}
