/* Subnet Calculator
   Teal marks the network part of an address, marigold marks the host part.
   That pairing is the only colour logic in the interface. */

@font-face { font-family: "Inter Local"; font-weight: 400; font-display: swap; src: url("../fonts/inter-v12-latin-regular.woff2") format("woff2"); }
@font-face { font-family: "Inter Local"; font-weight: 500; font-display: swap; src: url("../fonts/inter-v12-latin-500.woff2") format("woff2"); }
@font-face { font-family: "Inter Local"; font-weight: 600; font-display: swap; src: url("../fonts/inter-v12-latin-600.woff2") format("woff2"); }
@font-face { font-family: "Inter Local"; font-weight: 800; font-display: swap; src: url("../fonts/inter-v12-latin-800.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --bg: #e9f0ee;
  --surface: #ffffff;
  --surface-2: #f3f8f7;
  --ink: #0d2a2e;
  --ink-2: #4a6468;
  --line: #d2dfdc;
  --line-strong: #b5c8c4;
  --net: #0e7c79;
  --net-2: #14606a;
  --net-ink: #0b6663;          /* text-safe teal on white */
  --net-soft: #d6eeeb;
  --host: #e8a22b;
  --host-soft: #fbebcb;
  --host-ink: #7a4a00;
  --danger: #b3303c;
  --danger-soft: #fbe4e6;
  --focus: #0e7c79;

  /* The bit panel is dark in both themes. It is the one loud element. */
  --panel: #0d2a2e;
  --panel-line: #1e4247;
  --panel-text: #e3f1ef;
  --panel-dim: #8fb0ad;
  --bit-net: #3cc9c0;
  --bit-net-ink: #062a2b;
  --bit-host: #f2b24a;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(13, 42, 46, .06), 0 8px 24px -12px rgba(13, 42, 46, .18);

  --font: "Figtree", "Inter Local", "Hind Siliguri", "Noto Sans Bengali", "Nirmala UI", "Kalpurush", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  --bg: #071619;
  --surface: #0f2326;
  --surface-2: #132a2e;
  --ink: #e3f1ef;
  --ink-2: #94b1ae;
  --line: #20393d;
  --line-strong: #2f5056;
  --net: #3cc9c0;
  --net-2: #8fe3dc;
  --net-ink: #6fe0d8;
  --net-soft: #123b3d;
  --host: #f2b24a;
  --host-soft: #3a2c10;
  --host-ink: #f5c26e;
  --danger: #ff8791;
  --danger-soft: #3b1a1e;
  --focus: #6fe0d8;
  --panel: #0b1d20;
  --panel-line: #1d3a3f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color .25s, color .25s;
}
/* Bengali needs more leading than Latin to keep matras and conjuncts clear. */
:root[lang="bn"] body { line-height: 1.7; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }

.skip-link { position: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 50; text-decoration: none; }
.skip-link:focus { top: 12px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

/* ---------- header ---------- */
.site-header { padding: 22px 0 8px; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { width: 44px; height: 44px; flex: none; }
.brand-title { margin: 0; font-size: 1.45rem; line-height: 1.2; font-weight: 800; letter-spacing: -.02em; }
:root[lang="bn"] .brand-title { letter-spacing: 0; font-weight: 700; }
.brand-tagline { margin: 2px 0 0; color: var(--ink-2); font-size: .92rem; max-width: 56ch; }
.header-tools { display: flex; align-items: center; gap: 10px; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: .9rem; font-weight: 600;
  padding: 7px 16px; border-radius: 999px; cursor: pointer; transition: background-color .2s, color .2s; min-height: 36px;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.icon-btn {
  appearance: none; display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; transition: border-color .2s, background-color .2s;
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn.small { width: 36px; height: 36px; border-radius: 10px; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.ico-sun { display: none; }
:root[data-theme="dark"] .ico-sun { display: block; }
:root[data-theme="dark"] .ico-moon { display: none; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; margin: 22px 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: transparent; font: inherit; font-weight: 700; font-size: 1rem; color: var(--ink-2);
  padding: 12px 20px; cursor: pointer; position: relative; white-space: nowrap; min-height: 46px;
  border-radius: 10px 10px 0 0; transition: color .2s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--net-ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--net); }

/* ---------- layout ---------- */
.panel { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 24px; align-items: start; padding-bottom: 48px; }
.inputs {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 22px;
  display: flex; flex-direction: column; gap: 20px; box-shadow: var(--shadow); position: sticky; top: 16px;
}
.field { display: flex; flex-direction: column; gap: 7px; margin: 0; padding: 0; border: 0; min-width: 0; }
label, .label, legend { font-weight: 700; font-size: .93rem; padding: 0; }
.hint { margin: 0; color: var(--ink-2); font-size: .85rem; }
.error { margin: 0; color: var(--danger); font-size: .88rem; font-weight: 600; }

.input {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink); background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; min-height: 46px; transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.input.mono { font-size: .97rem; }
.input:hover { border-color: var(--line-strong); }
.input:focus { outline: none; border-color: var(--net); box-shadow: 0 0 0 3px color-mix(in srgb, var(--net) 25%, transparent); background: var(--surface); }
.input[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-soft); }
select.input { appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='m3 5 4 4 4-4' fill='none' stroke='%234a6468' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  appearance: none; font: inherit; font-weight: 600; font-size: .93rem; color: var(--ink-2); background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: 999px; padding: 7px 18px; min-height: 40px; min-width: 56px; cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-checked="true"] { background: var(--net-soft); border-color: var(--net); color: var(--net-ink); }

.prefix-row { display: grid; grid-template-columns: auto 92px 1fr; align-items: center; gap: 10px; }
.slash { font-size: 1.3rem; color: var(--ink-2); }
.range { width: 100%; accent-color: var(--net); height: 28px; cursor: pointer; }

.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 700; font-size: .93rem;
  border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer; transition: all .15s;
}
.btn-ghost { background: transparent; color: var(--net-ink); border: 1.5px solid var(--line-strong); }
.btn-ghost:hover { background: var(--net-soft); border-color: var(--net); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .86rem; }

/* ---------- VLSM inputs ---------- */
.req-field { gap: 10px; }
.req-head, .req-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 36px; gap: 8px; align-items: center; }
.req-head { font-size: .8rem; color: var(--ink-2); font-weight: 600; padding: 0 2px; }
.req-rows { display: flex; flex-direction: column; gap: 8px; }
#vlsm-add { align-self: flex-start; }

/* VLSM: the table needs the full width, so inputs sit on top in two columns. */
#panel-vlsm { grid-template-columns: minmax(0, 1fr); }
#panel-vlsm .inputs { position: static; display: grid; grid-template-columns: minmax(260px, 360px) minmax(0, 1fr); gap: 20px 32px; align-items: start; }
@media (max-width: 920px) {
  #panel-vlsm .inputs { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- results ---------- */
.results { min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.empty { margin: 0; padding: 48px 24px; text-align: center; color: var(--ink-2); background: var(--surface); border: 1.5px dashed var(--line-strong); border-radius: 20px; }

/* Bit panel: the memorable part */
.bits { background: var(--panel); color: var(--panel-text); border-radius: 20px; padding: 22px 22px 20px; box-shadow: var(--shadow); }
.bits-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.bits-title { margin: 0; font-size: 1rem; font-weight: 700; color: var(--panel-text); }
.legend { margin: 0; display: flex; gap: 18px; flex-wrap: wrap; font-size: .86rem; color: var(--panel-dim); }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-item i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.legend-item.net i { background: var(--bit-net); }
.legend-item.host i { border: 2px solid var(--bit-host); }

.bit-groups { display: grid; gap: 14px 12px; }
.bit-groups-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bit-groups-8 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bit-head { display: block; font-size: .95rem; font-weight: 600; color: var(--panel-text); margin-bottom: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bit-groups-8 .bit-head { font-family: var(--font); font-size: .78rem; font-weight: 500; color: var(--panel-dim); }
.bit-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; }
.bit {
  display: grid; place-items: center; aspect-ratio: 1 / 1.5; max-height: 54px; border-radius: 6px; font-size: .86rem; font-weight: 600;
  border: 1.5px solid transparent; transition: background-color .3s ease, color .3s ease, border-color .3s ease;
  transition-delay: calc(var(--i) * 6ms);
}
.bit.is-net { background: var(--bit-net); color: var(--bit-net-ink); }
.bit.is-host { background: transparent; color: var(--bit-host); border-color: color-mix(in srgb, var(--bit-host) 70%, transparent); }
.bit.is-mix {
  color: var(--bit-net-ink); border-color: color-mix(in srgb, var(--bit-host) 70%, transparent);
  background: linear-gradient(90deg, var(--bit-net) var(--split, 50%), transparent var(--split, 50%));
}
.bit.is-mix { color: var(--panel-text); }
.bit-groups-8 .bit { aspect-ratio: 1 / 1.25; font-size: 1rem; }

.split-track { display: flex; height: 8px; border-radius: 8px; overflow: hidden; margin-top: 20px; gap: 3px; }
.split-net, .split-host { display: block; min-width: 0; transition: flex-grow .35s ease; }
.split-net { background: var(--bit-net); border-radius: 8px 3px 3px 8px; }
.split-host { background: color-mix(in srgb, var(--bit-host) 85%, transparent); border-radius: 3px 8px 8px 3px; }
.split-net[style*="flex-grow: 0"], .split-host[style*="flex-grow: 0"] { display: none; }

/* Key figures: one surface divided by hairlines, not four separate cards */
.keyfigs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
.keyfig { padding: 16px 20px 18px; min-width: 0; background: var(--surface); }
.keyfig.wide { grid-column: 1 / -1; }
.keyfig-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--ink-2); font-size: .86rem; font-weight: 600; min-height: 30px; }
.keyfig-value { font-size: 1.5rem; font-weight: 600; color: var(--ink); line-height: 1.25; overflow-wrap: anywhere; }
.keyfig-value.long { font-size: 1rem; }
.keyfig-note { margin-top: 4px; color: var(--host-ink); font-size: .86rem; font-weight: 600; overflow-wrap: anywhere; }
.vlsm-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.vlsm-stats .keyfig-note { color: var(--ink-2); font-weight: 500; }

.copy-btn {
  appearance: none; flex: none; display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; transition: background-color .15s, color .15s;
}
.copy-btn:hover { background: var(--net-soft); color: var(--net-ink); }
.copy-btn.done { color: var(--net-ink); background: var(--net-soft); }

/* Facts */
.facts, .alloc-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 6px 20px 8px; box-shadow: var(--shadow); }
.facts-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 8px; }
.facts-title { margin: 0; font-size: 1rem; font-weight: 700; }
.fact-list { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; }
.fact { padding: 11px 0; border-top: 1px solid var(--line); min-width: 0; }
.fact dt { color: var(--ink-2); font-size: .84rem; font-weight: 600; }
.fact dd { margin: 2px 0 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.fact-val { font-size: .95rem; overflow-wrap: anywhere; min-width: 0; }
dd:not(.mono) .fact-val { font-weight: 600; }

/* VLSM output */
.alloc-wrap { padding-bottom: 20px; }
.alloc { display: flex; gap: 3px; height: 52px; }
.alloc-seg {
  display: block; min-width: 3px; border-radius: 6px; padding: 0 8px; color: #fff; font-size: .8rem; font-weight: 700; line-height: 52px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: flex-grow .35s ease;
}
:root[data-theme="dark"] .alloc-seg:not(.free) { color: #04201f; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.chips.quick { margin-top: 2px; }
.chips.quick .chip { min-width: 0; padding: 6px 14px; min-height: 36px; font-family: var(--mono); font-size: .86rem; }
.chips.quick .chip:hover { border-color: var(--net); }
#main:focus { outline: none; }
.alloc-seg.free { background: repeating-linear-gradient(135deg, var(--host-soft) 0 6px, transparent 6px 12px); border: 1.5px dashed var(--host); color: var(--host-ink); }

.notice { margin: 0; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--host-soft); color: var(--host-ink); font-weight: 600; font-size: .92rem; }
.notice.bad { background: var(--danger-soft); color: var(--danger); }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; overflow-x: auto; box-shadow: var(--shadow); }
.vlsm-table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 860px; }
.vlsm-table th, .vlsm-table td { text-align: start; padding: 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.vlsm-table thead th { color: var(--ink-2); font-size: .82rem; font-weight: 700; background: var(--surface-2); }
.vlsm-table tbody th { font-weight: 700; position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 1; box-shadow: 1px 0 0 var(--line); }
.row-bad th { background: var(--danger-soft) !important; }
.vlsm-table tbody tr:last-child > * { border-bottom: 0; }
.vlsm-table .num { font-variant-numeric: tabular-nums; }
.vlsm-table .strong { color: var(--net-ink); font-weight: 600; }
.row-bad > * { background: var(--danger-soft); }
.bad-cell { color: var(--danger); font-weight: 700; }

/* ---------- toast & footer ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: .9rem; transition: opacity .2s, transform .2s; z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.site-footer { margin-top: auto; padding: 22px 0 32px; color: var(--ink-2); font-size: .88rem; border-top: 1px solid var(--line); }
.site-footer p { margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 920px) {
  .panel { grid-template-columns: minmax(0, 1fr); }
  .inputs { position: static; }
  .fact-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .wrap { padding: 0 16px; }
  .brand-tagline { display: none; }
  .brand-title { font-size: 1.2rem; }
  .bit-groups-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bit-groups-8 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bits { padding: 18px 16px; }
  .inputs { padding: 18px; }
  .keyfigs, .vlsm-stats { grid-template-columns: minmax(0, 1fr); }
  .keyfig-value { font-size: 1.3rem; }
  .facts, .alloc-wrap { padding-inline: 16px; }
}

@media print {
  body { background: #fff; color: #000; }
  .header-tools, .tabs, .inputs, .copy-btn, .btn, .toast, .skip-link, .site-footer { display: none !important; }
  .panel[hidden] { display: none !important; }
  .panel { display: block; }
  .bits { background: #fff; color: #000; border: 1px solid #999; box-shadow: none; }
  .keyfigs, .facts, .alloc-wrap, .table-wrap { box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; transition-delay: 0s !important; animation: none !important; }
}
