@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
    --bg-outer: #d4c5a9;
    --bg-page: #faf6ee;
    --bg-card: #fdfbf7;
    --bg-insight: #fdf8ee;
    --text: #362b1f;
    --text-heading: #2c2416;
    --text-muted: #6b5b47;
    --border: #e0d5c4;
    --accent: #8b6f47;
    --accent-border: #c4a882;

    --fixed: #2f6fb0;
    --fixed-soft: #dbe8f6;
    --free: #c9bfae;
    --free-soft: #efe9de;
    --good: #2e7d4f;
    --bad: #b2452f;
    --pub: #e7a33c;
    --pub-soft: #fcefd8;
    --priv: #4c8a63;
    --priv-soft: #e1f0e6;
    --res: #c0573f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.97rem;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg-outer);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(139, 115, 85, .08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 115, 85, .05) 0%, transparent 50%);
    padding: 2.5rem;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background: var(--bg-page);
    padding: 2.5rem 3rem 3rem;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .06);
    border: 1px solid #e8dfd0;
}

.breadcrumb { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

h1 {
    font-size: 2.1rem;
    font-weight: 700;
    margin-bottom: 2rem;
    color: var(--text-heading);
    text-align: center;
    letter-spacing: -.5px;
    border-bottom: 1px solid var(--accent-border);
    padding-bottom: 1.1rem;
}

h2 { font-size: 1.35rem; font-weight: 600; margin: .4rem 0 .9rem; color: #3d2e1c; letter-spacing: -.3px; }

section { margin-bottom: 2rem; }
.intro p { margin-bottom: .9rem; max-width: 46rem; }
.lead { color: var(--text-muted); margin-bottom: .9rem; }

code, .mono { font-family: 'JetBrains Mono', monospace; font-size: .86em; }
.intro code { background: #f1e9da; padding: .05rem .3rem; border-radius: 3px; }

.key-insight {
    padding: .8rem 1.2rem;
    background: var(--bg-insight);
    border-left: 3px solid var(--accent-border);
    font-style: italic;
    color: #5a4630;
}

.panel-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1.3rem 1.4rem 1.4rem;
}

/* ---------- controls ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.4rem; margin-bottom: .8rem; }
.toolbar label { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .9rem; }
.toolbar input[type="text"], .toolbar input:not([type]), .check input, select {
    font-family: 'JetBrains Mono', monospace;
    font-size: .95rem;
    padding: .35rem .55rem;
    border: 1px solid #c4b99a;
    border-radius: 4px;
    background: #fff;
    color: var(--text);
}
#cidrIn { width: 12.5rem; }
#prefixIn { width: 12rem; accent-color: var(--fixed); }
.hint { font-size: .85rem; color: var(--text-muted); }

.btn {
    font: 500 .88rem 'Inter', sans-serif;
    padding: .4rem .9rem;
    border-radius: 4px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}
.btn:hover { background: #6d5636; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: #f1e9da; }

.presets { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.1rem; }
.preset {
    font: .82rem 'Inter', sans-serif;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 999px;
    padding: .2rem .75rem;
    cursor: pointer;
    color: var(--text);
}
.preset b { font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.preset:hover, .preset.on { border-color: var(--fixed); background: var(--fixed-soft); }

/* ---------- the 32 bits ---------- */
.bits { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; margin-bottom: .4rem; }
.octet { text-align: center; }
.octet .dec { font: 600 1.35rem 'JetBrains Mono', monospace; margin-bottom: .25rem; }
.octet .dec.free { color: var(--free); }
.octet .row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.bit {
    font: 600 .85rem 'JetBrains Mono', monospace;
    height: 2rem;
    display: grid;
    place-items: center;
    border-radius: 3px;
    transition: background .25s, color .25s;
}
.bit.fx { background: var(--fixed); color: #fff; }
.bit.fr { background: var(--free-soft); color: #a49882; }
.bit.cut { box-shadow: -3px 0 0 #222; }
.octet .pos { display: grid; grid-template-columns: repeat(8, 1fr); font-size: .62rem; color: var(--text-muted); margin-top: 2px; }
.bits-caption { display: flex; justify-content: space-between; font-size: .82rem; color: var(--text-muted); margin-bottom: 1rem; }
.bits-caption b { color: var(--fixed); }

.note.info { color: #4a3828; background: #f4efe4; border-left-color: var(--accent-border); }
.note { font-size: .88rem; color: #8a5a1a; background: #fbf1dc; border-left: 3px solid #e2b866; padding: .45rem .8rem; margin: .4rem 0 1rem; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; margin-bottom: 1.1rem; }
.fact { background: #fff; border: 1px solid var(--border); border-radius: 5px; padding: .5rem .8rem; }
.fact .k { font-size: .78rem; color: var(--text-muted); }
.fact .v { font: 600 1.05rem 'JetBrains Mono', monospace; }
.fact .s { font-size: .78rem; color: var(--text-muted); }

.check { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; }
.check label { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .9rem; }
.check-out { font-size: .92rem; }
.check-out .yes { color: var(--good); font-weight: 600; }
.check-out .no { color: var(--bad); font-weight: 600; }
.cmp { font: .8rem 'JetBrains Mono', monospace; display: block; margin-top: .25rem; letter-spacing: .5px; }
.cmp i { font-style: normal; }
.cmp .m { color: var(--good); }
.cmp .x { color: var(--bad); text-decoration: underline; }
.cmp .f { color: #b4a991; }

/* ---------- split diagram ---------- */
.icicle { position: relative; user-select: none; }
.irow { position: relative; height: 46px; margin-bottom: 4px; }
.blk {
    position: absolute;
    top: 0;
    bottom: 0;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, .12);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    cursor: pointer;
    font-size: .74rem;
    line-height: 1.2;
    white-space: nowrap;
    transition: filter .15s, transform .15s;
    animation: grow .35s ease-out both;
}
.blk:hover { filter: brightness(1.06); transform: translateY(-1px); }
.blk b { font-family: 'JetBrains Mono', monospace; font-size: .78rem; }
.blk.split { opacity: .45; }
.blk.tiny b, .blk.tiny span { display: none; }
@keyframes grow { from { opacity: 0; transform: scaleY(.6); } }
.leaves { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .8rem; font-size: .82rem; }
.leaves span { border-radius: 999px; padding: .1rem .6rem; font-family: 'JetBrains Mono', monospace; }

/* ---------- VPC diagram ---------- */
.vpc svg { width: 100%; height: auto; display: block; font-family: 'Inter', sans-serif; }
.vpc .sub { cursor: default; transition: filter .15s; }
.vpc .sub:hover { filter: brightness(.96); }
.vpc .lbl { font-size: 13px; font-weight: 600; fill: var(--text); }
.vpc .cidr { font: 600 13px 'JetBrains Mono', monospace; fill: var(--text); }
.vpc .small { font-size: 11.5px; fill: var(--text-muted); }
.vpc .mono-s { font: 11px 'JetBrains Mono', monospace; fill: var(--text-muted); }
.vpc .appear { animation: fadein .45s ease-out both; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ---------- reserved address grid ---------- */
.grid-wrap { display: flex; flex-wrap: wrap; gap: 1.2rem 2rem; align-items: flex-start; }
.grid { display: grid; grid-template-columns: repeat(16, 22px); gap: 2px; }
.cell { width: 22px; height: 22px; border-radius: 3px; background: var(--priv-soft); border: 1px solid #c5e0cf; font: 8px 'JetBrains Mono', monospace; color: #7a9c86; display: grid; place-items: center; cursor: default; }
.cell.res { background: var(--res); border-color: #9d3e29; color: #fff; font-weight: 600; }
.cell:hover { outline: 2px solid var(--text); }
.legend { display: grid; gap: .5rem; font-size: .9rem; min-width: 14rem; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: .5rem; }
.sw.res { background: var(--res); }
.sw.use { background: var(--priv-soft); border: 1px solid #c5e0cf; }
.grid-info { margin-top: .4rem; padding: .5rem .7rem; background: #fff; border: 1px solid var(--border); border-radius: 5px; min-height: 3.4rem; font-size: .82rem; }

/* ---------- sizes table ---------- */
.sizes { border-collapse: collapse; font-size: .9rem; min-width: 30rem; }
.sizes th, .sizes td { padding: .35rem .9rem; border-bottom: 1px solid var(--border); text-align: right; }
.sizes th { font-weight: 600; color: var(--text-muted); font-size: .82rem; }
.sizes td:first-child, .sizes th:first-child { text-align: left; font-family: 'JetBrains Mono', monospace; }
.sizes td:last-child, .sizes th:last-child { text-align: left; color: var(--text-muted); }
.sizes .bar { display: inline-block; height: 8px; background: var(--fixed); border-radius: 2px; vertical-align: 1px; }

/* ---------- practice ---------- */
.practice details { border: 1px solid var(--border); border-radius: 5px; background: var(--bg-card); padding: .6rem 1rem; margin-bottom: .55rem; max-width: 46rem; }
.practice summary { cursor: pointer; font-weight: 500; }
.practice details p { margin: .5rem 0 .1rem; color: #4a3828; }
.practice details[open] summary { color: var(--accent); }

@media (max-width: 720px) {
    body { padding: .6rem; }
    .container { padding: 1.4rem 1.1rem 2rem; }
    h1 { font-size: 1.6rem; }
    .bits { grid-template-columns: repeat(2, 1fr); }
    .grid { grid-template-columns: repeat(16, 17px); }
    .cell { width: 17px; height: 17px; font-size: 0; }
    .sizes { min-width: 0; width: 100%; }
    .panel-section { padding: 1rem .8rem; }
}
