:root {
  color-scheme: light;
  font-family: "Segoe UI", Arial, sans-serif;
  --navy: #123b68;
  --navy-deep: #0d2d52;
  --teal: #008f91;
  --teal-dark: #007478;
  --teal-soft: #e5f7f5;
  --canvas: #edf2f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --text: #15223a;
  --muted: #637084;
  --border: #d3dce5;
  --border-strong: #bcc9d5;
  --danger: #b42318;
  --shadow: 0 12px 28px rgba(25, 46, 70, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--canvas);
  color: var(--text);
}

body {
  min-height: 100svh;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select,
input[type="radio"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(0, 143, 145, 0.22);
  outline-offset: 2px;
}

.topbar {
  min-height: 72px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #ffffff;
  background: var(--navy);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo-frame {
  width: 112px;
  height: 48px;
  padding: 5px 8px;
  display: grid;
  place-items: center;
  background: #ffffff;
  border-radius: 4px;
}

.logo-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-divider {
  width: 1px;
  height: 34px;
  background: rgba(255, 255, 255, 0.48);
}

.topbar h1 {
  margin: 0;
  overflow: hidden;
  font-size: 25px;
  font-weight: 650;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rules-button,
.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
}

.rules-button {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 15px;
  gap: 9px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 5px;
  font-size: 14px;
  font-weight: 650;
}

.rules-button:hover {
  background: rgba(255, 255, 255, 0.17);
}

.rules-button svg,
.primary-button svg,
.secondary-button svg,
.icon-button svg,
.status-line svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: calc(100svh - 72px);
  padding: 22px 24px;
  display: grid;
  grid-template-columns: minmax(420px, 1.04fr) minmax(390px, 0.96fr);
  gap: 18px;
  transition: padding-right 180ms ease;
}

body.rules-open .app-shell {
  padding-right: 388px;
}

.panel {
  min-width: 0;
  align-self: stretch;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.input-panel {
  background: #f7f9fb;
}

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

.panel-heading h2,
.drawer-header h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.25;
}

.panel-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

#calculatorForm {
  display: flex;
  flex-direction: column;
  gap: 17px;
}

.field-row {
  display: grid;
  gap: 14px;
}

.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.field small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 16px;
  font-weight: 500;
}

.field input:hover,
.field select:hover {
  border-color: #8ea2b4;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
}

.configuration-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.configuration-fieldset legend,
.size-section h3,
.formula-section h3,
.unequal-rule h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}

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

.radio-group label {
  min-height: 44px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 14px;
  line-height: 1.2;
}

.radio-group label:has(input:checked) {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: #075e61;
}

.radio-group input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--teal);
}

.conditional-field[hidden] {
  display: none;
}

.form-error {
  min-height: 18px;
  margin: -4px 0 -2px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.form-actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 12px;
}

.primary-button,
.secondary-button {
  min-height: 50px;
  gap: 10px;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 700;
}

.primary-button {
  color: #ffffff;
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  color: #3e4a5d;
  background: #ffffff;
  border: 1px solid var(--border-strong);
}

.secondary-button:hover {
  background: #f3f6f8;
}

.result-panel {
  display: flex;
  flex-direction: column;
}

.result-list {
  margin: 0;
  display: grid;
  gap: 9px;
}

.result-row {
  min-height: 66px;
  padding: 10px 0;
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(175px, 0.9fr);
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid #e4e9ee;
}

.result-row dt {
  font-size: 15px;
  font-weight: 700;
}

.result-row dd {
  min-width: 0;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 34px;
  align-items: center;
  gap: 9px;
}

.result-row strong {
  min-height: 46px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  color: #0d5c60;
  background: var(--teal-soft);
  border: 1px solid #bfe9e4;
  border-radius: 5px;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.result-row dd span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.formula-section {
  margin-top: 18px;
}

.formula-section pre {
  min-height: 138px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #26344a;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.status-line {
  min-height: 50px;
  margin-top: auto;
  padding: 12px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #45536a;
  background: #f2f5f7;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 14px;
  font-weight: 650;
}

.status-line[data-state="complete"] {
  color: #075e61;
  background: var(--teal-soft);
  border-color: #bfe9e4;
}

.status-complete-icon,
.status-line[data-state="complete"] .status-ready-icon {
  display: none;
}

.status-line[data-state="complete"] .status-complete-icon {
  display: block;
}

.drawer-overlay {
  position: fixed;
  inset: 72px 0 0;
  z-index: 20;
  background: rgba(10, 31, 54, 0.3);
}

.rules-drawer {
  position: fixed;
  top: 72px;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: 368px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 30px rgba(27, 48, 71, 0.14);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 180ms ease, visibility 180ms ease;
}

.rules-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.drawer-header {
  min-height: 70px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  color: #526074;
  background: transparent;
  border-radius: 4px;
}

.icon-button:hover {
  background: #eef2f5;
}

.drawer-content {
  min-height: 0;
  padding: 18px 20px 26px;
  overflow-y: auto;
}

.drawer-intro {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.rules-list {
  display: grid;
  gap: 12px;
}

.rule-item {
  padding-bottom: 12px;
  border-bottom: 1px solid #e4e9ee;
}

.rule-item h3 {
  margin: 0 0 7px;
  font-size: 14px;
}

.rule-item p,
.unequal-rule p {
  margin: 4px 0;
  color: #3f4d62;
  font-size: 12px;
  line-height: 1.45;
}

.rule-item code {
  color: #173c61;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
}

.unequal-rule {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
}

@media (min-width: 1181px) {
  .drawer-overlay {
    display: none;
  }
}

@media (max-width: 1180px) {
  body.rules-open .app-shell {
    padding-right: 24px;
  }

  .drawer-overlay:not([hidden]) {
    display: block;
  }
}

@media (max-width: 900px) {
  .topbar {
    padding: 10px 16px;
  }

  .logo-frame {
    width: 96px;
    height: 42px;
  }

  .brand-divider {
    display: none;
  }

  .topbar h1 {
    font-size: 19px;
  }

  .rules-button {
    width: 42px;
    padding: 0;
  }

  .rules-button span {
    display: none;
  }

  .app-shell {
    min-height: auto;
    padding: 16px;
    grid-template-columns: 1fr;
  }

  body.rules-open .app-shell {
    padding-right: 16px;
  }

  .panel {
    padding: 20px;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 64px;
  }

  .brand-block {
    gap: 10px;
  }

  .logo-frame {
    width: 82px;
    height: 38px;
  }

  .topbar h1 {
    font-size: 16px;
    white-space: normal;
  }

  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .panel {
    padding: 17px;
  }

  .two-column,
  .radio-group,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .radio-group {
    gap: 7px;
  }

  .result-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .result-row dd {
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .rules-drawer {
    top: 64px;
    width: min(92vw, 368px);
  }

  .drawer-overlay {
    inset: 64px 0 0;
  }
}

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