:root {
  --ink: #13233f;
  --muted: #5c6c84;
  --line: #d9e2ef;
  --line-strong: #c5d2e4;
  --surface: #ffffff;
  --surface-soft: #f6f8fc;
  --surface-blue: #edf4ff;
  --brand: #2366d1;
  --brand-dark: #194fa8;
  --success: #147d56;
  --success-soft: #e8f7f0;
  --danger: #b94343;
  --danger-soft: #fff0f0;
  --parity: #efe9ff;
  --facility: #e6f3ff;
  --card: #e8f7ef;
  --shadow: 0 18px 50px rgba(28, 56, 95, 0.1);
  --radius-large: 22px;
  --radius-medium: 14px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(96, 165, 250, 0.12), transparent 28rem),
    linear-gradient(180deg, #f8fbff 0, #f6f8fc 44rem, #ffffff 44rem);
  font-family: var(--font-sans);
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(197, 210, 228, 0.75);
  background: rgba(248, 251, 255, 0.88);
  backdrop-filter: blur(16px);
}

.header-inner {
  width: min(1180px, calc(100% - 40px));
  height: 70px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #ffffff;
  background: var(--ink);
  box-shadow: 0 7px 16px rgba(19, 35, 63, 0.2);
}

.brand-mark svg {
  width: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.github-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
  font-weight: 700;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.github-button:hover {
  border-color: #9cacc2;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(28, 56, 95, 0.08);
}

.github-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

main {
  overflow: hidden;
}

.hero {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 66px 0 58px;
}

.hero-copy {
  max-width: 760px;
  margin-bottom: 27px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4.5rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.hero-copy > p:last-child {
  max-width: 680px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
}

.mode-tabs {
  width: max-content;
  max-width: 100%;
  display: flex;
  gap: 5px;
  margin-bottom: 14px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #eef3fa;
}

.mode-tab {
  min-height: 42px;
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
}

.mode-tab.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 3px 10px rgba(35, 62, 100, 0.1);
}

.calculator-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  gap: 18px;
  align-items: start;
}

.panel,
.bit-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.panel {
  min-height: 520px;
  padding: 26px;
}

.panel-heading,
.bit-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading {
  margin-bottom: 24px;
}

.panel-heading h2,
.bit-panel-heading h2 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.025em;
}

.format-tag,
.status-pill {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.format-tag {
  padding: 7px 10px;
  color: var(--brand-dark);
  background: var(--surface-blue);
}

.status-pill {
  gap: 7px;
  padding: 7px 11px;
  color: var(--success);
  background: var(--success-soft);
}

.status-pill.is-invalid {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.field-group {
  margin-bottom: 20px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.9rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input,
select {
  height: 48px;
  padding: 0 13px;
}

textarea {
  min-height: 92px;
  padding: 12px 13px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
}

select:disabled {
  color: var(--ink);
  background: var(--surface-soft);
  opacity: 1;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(35, 102, 209, 0.12);
}

input.is-invalid,
select.is-invalid,
textarea.is-invalid {
  border-color: var(--danger);
  background: #fffafa;
}

small {
  color: var(--muted);
}

.field-group > small {
  display: block;
  margin-top: 6px;
  font-size: 0.77rem;
}

.form-error {
  min-height: 23px;
  margin: -4px 0 8px;
  color: var(--danger);
  font-size: 0.84rem;
  font-weight: 650;
}

.button-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 5px;
}

.primary-button,
.secondary-button,
.text-button,
.copy-button {
  border-radius: 10px;
  cursor: pointer;
  font-weight: 750;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 0 18px;
}

.primary-button {
  border: 1px solid var(--brand);
  color: #ffffff;
  background: var(--brand);
  box-shadow: 0 8px 18px rgba(35, 102, 209, 0.2);
}

.primary-button:hover {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
}

.text-button {
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  color: var(--brand-dark);
  background: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(35, 102, 209, 0.35);
  outline-offset: 3px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 18px;
}

.summary-item {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.summary-item span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 1.18rem;
  text-overflow: ellipsis;
}

.result-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.result-row {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.result-row:last-child {
  border-bottom: 0;
}

.result-row > div {
  min-width: 0;
}

.result-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
}

.result-label small {
  margin-left: 4px;
  font-weight: 500;
}

.result-row code {
  display: block;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
}

.copy-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  color: var(--brand-dark);
  background: var(--surface);
  font-size: 0.76rem;
}

.copy-button:hover {
  border-color: #9eb2ce;
  background: var(--surface-blue);
}

.bit-panel {
  margin-top: 18px;
  padding: 22px 24px 24px;
}

.bit-panel-heading {
  margin-bottom: 16px;
}

.bit-panel-heading > span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.bit-map {
  display: grid;
  grid-template-columns: minmax(82px, 1fr) minmax(180px, 8fr) minmax(310px, 16fr) minmax(82px, 1fr);
  gap: 5px;
}

.bit-segment {
  min-width: 0;
  padding: 13px 10px;
  border-radius: 11px;
  text-align: center;
}

.parity-segment {
  background: var(--parity);
}

.facility-segment {
  background: var(--facility);
}

.card-segment {
  background: var(--card);
}

.segment-label,
.segment-range {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.bit-segment code {
  display: block;
  margin: 9px 0 7px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: clamp(0.78rem, 1.4vw, 1rem);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.segment-range {
  color: var(--muted);
  font-size: 0.7rem;
}

.parity-detail {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.content-section {
  width: min(1080px, calc(100% - 40px));
  margin: 0 auto;
  padding: 76px 0;
}

.content-heading {
  max-width: 740px;
  margin-bottom: 30px;
}

.content-heading h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.content-heading > p:last-child {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.03rem;
}

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

.explain-grid article {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.step-number {
  color: var(--brand);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 800;
}

.explain-grid h3 {
  margin: 13px 0 7px;
  font-size: 1.08rem;
}

.explain-grid p {
  min-height: 72px;
  margin: 0 0 17px;
  color: var(--muted);
  font-size: 0.9rem;
}

.explain-grid code {
  display: block;
  padding: 11px;
  border-radius: 9px;
  overflow-wrap: anywhere;
  color: var(--brand-dark);
  background: var(--surface-blue);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.reference-section {
  padding-top: 20px;
}

.compact-heading {
  margin-bottom: 20px;
}

.reference-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 15px 17px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.77rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

td {
  font-size: 0.9rem;
}

tr:last-child td {
  border-bottom: 0;
}

footer {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 38px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 10px;
  color: #ffffff;
  background: var(--ink);
  box-shadow: 0 14px 34px rgba(19, 35, 63, 0.25);
  font-size: 0.84rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .calculator-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }

  .bit-map {
    grid-template-columns: 1fr 3fr;
  }

  .card-segment {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .odd-segment {
    grid-column: 1;
    grid-row: 3;
  }

  .explain-grid {
    grid-template-columns: 1fr;
  }

  .explain-grid p {
    min-height: 0;
  }
}

@media (max-width: 620px) {
  .header-inner,
  .hero,
  .content-section,
  footer {
    width: min(100% - 24px, 1180px);
  }

  .header-inner {
    height: 62px;
  }

  .brand > span:last-child {
    display: none;
  }

  .github-button {
    min-height: 38px;
    padding: 0 12px;
  }

  .hero {
    padding: 42px 0 42px;
  }

  .hero h1 {
    font-size: clamp(2.35rem, 14vw, 3.4rem);
  }

  .mode-tabs {
    width: 100%;
  }

  .mode-tab {
    flex: 1;
    padding: 0 10px;
  }

  .panel,
  .bit-panel {
    border-radius: 17px;
  }

  .panel {
    padding: 19px;
  }

  .field-row,
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .result-heading {
    align-items: center;
  }

  .result-label small {
    display: block;
    margin: 1px 0 0;
  }

  .bit-panel {
    padding: 19px;
  }

  .bit-map {
    display: grid;
    grid-template-columns: 1fr;
  }

  .card-segment,
  .odd-segment {
    grid-column: auto;
    grid-row: auto;
  }

  .content-section {
    padding: 56px 0;
  }
}

@media (max-width: 420px) {
  .field-row,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .button-row > button {
    flex: 1 1 auto;
  }

  .text-button {
    flex-basis: 100% !important;
  }

  .status-pill {
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
