:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --panel: #eef3f1;
  --panel-strong: #dfe9e4;
  --ink: #18201f;
  --muted: #697571;
  --line: #d8dfdc;
  --primary: #195b55;
  --primary-dark: #0f3e3a;
  --accent: #c84f35;
  --focus: #2f7d73;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

.brand-header {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 10;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 10px 6px 6px;
  border: 1px solid rgba(216, 223, 220, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(24, 32, 31, 0.08);
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

button,
input,
select {
  font: inherit;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #bac6c1;
  background: repeating-linear-gradient(135deg, #ffffff, #ffffff 10px, #f0f3f1 10px, #f0f3f1 20px);
  color: #83908b;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.top-ad {
  width: min(672px, calc(100% - 32px));
  aspect-ratio: 16 / 9;
  max-height: 230px;
  margin: 48px auto 0;
}

.site-shell {
  display: flex;
  min-height: 100vh;
  margin-top: 0;
  border-top: 2px solid var(--line);
}

.rail-ad {
  display: none;
  width: 300px;
  min-height: 600px;
  border-top: 0;
  border-bottom: 0;
}

.main-panel {
  flex: 1;
  width: 100%;
  max-width: 896px;
  margin: 0 auto;
  padding: 16px;
}

.intro {
  width: min(100%, 640px);
  margin: 16px auto 32px;
  text-align: center;
}

.intro h1 {
  margin: 0 0 14px;
  font-size: 2.28rem;
  line-height: 1.1;
  font-weight: 800;
}

.intro p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.calculator-nav {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 32px 0;
}

.nav-button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 140ms ease, transform 140ms ease;
}

.nav-button:hover,
.button:hover,
.nav-button.active {
  background: var(--primary-dark);
}

.button:active,
.nav-button:active {
  transform: translateY(1px);
}

.calculator-root {
  margin-bottom: 192px;
}

.tool-card {
  width: min(100%, 576px);
  margin: 0 auto;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
}

.tool-card + .tool-card,
.result-card {
  margin-top: 32px;
}

.inline-form {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.field-label {
  font-weight: 600;
}

.input,
.select {
  width: 100%;
  height: 40px;
  border: 1px solid #c8d2cd;
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
}

.input.short {
  width: 96px;
}

.input.center {
  text-align: center;
}

.input:focus,
.select:focus,
.button:focus,
.nav-button:focus,
.tab-button:focus,
.check-input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.result-title {
  margin: 0 0 12px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
}

.score-box {
  margin: 0 24px 12px;
  padding: 8px;
  border: 2px solid #8c9894;
  border-radius: 4px;
  background: #f4f7f6;
  text-align: center;
  font-size: 1.85rem;
  font-weight: 700;
}

.checks {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.check-input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
}

th,
td {
  padding: 9px 8px;
}

thead th {
  font-weight: 800;
}

.grade-chart {
  width: 67%;
  min-width: 260px;
  margin: 0 auto;
}

.grade-chart tbody tr:nth-child(odd) {
  background: #9b2f2b;
  color: white;
}

.grade-chart tbody tr:nth-child(even) {
  background: #b43d31;
  color: white;
}

.tabs {
  width: min(100%, 576px);
  margin: 0 auto;
}

.tab-list {
  display: grid;
  gap: 4px;
  height: 40px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.tab-list.three {
  grid-template-columns: repeat(3, 1fr);
}

.tab-list.two {
  grid-template-columns: repeat(2, 1fr);
}

.tab-button {
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.tab-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(24, 32, 31, 0.08);
}

.tab-panel {
  margin-top: 8px;
}

.entry-table td:first-child {
  min-width: 48px;
  background: var(--panel);
  font-weight: 700;
}

.entry-table .input,
.entry-table .select {
  min-width: 130px;
}

.button-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.target-row {
  margin-top: 8px;
  text-align: center;
}

.target-row .input {
  width: 100px;
}

.output-grid {
  display: flex;
  gap: 4px;
  width: 100%;
}

.output-grid .input {
  background: white;
}

.form-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.wide-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(100%, 420px);
}

.scale-note {
  margin: 8px 0;
  text-align: center;
}

.site-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 2px solid #aeb9b4;
  border-bottom: 2px solid #e0e5e3;
  padding: 8px;
  background: white;
}

.site-footer a {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  padding: 8px 16px;
  color: var(--primary);
  font-weight: 700;
}

.footer-disclaimer {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: #7a8581;
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.footer-disclaimer:hover {
  color: var(--primary);
}

.modal-open {
  overflow: hidden;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 20, 18, 0.42);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-window {
  width: min(520px, 100%);
  max-height: min(80vh, 520px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(20, 28, 26, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
  color: var(--muted);
  font-size: 0.94rem;
}

.modal-body p {
  margin: 0 0 12px;
}

.modal-body p:last-child {
  margin-bottom: 0;
}

.policy-page {
  width: min(720px, calc(100% - 32px));
  margin: 64px auto;
  padding: 24px;
  background: white;
  border-radius: var(--radius);
}

.policy-page h2 {
  margin: 24px 0 8px;
  font-size: 1.1rem;
}

.policy-footer {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto 48px;
}

@media (min-width: 980px) {
  .rail-ad {
    display: flex;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 15px;
  }

  .brand-header {
    position: static;
    padding: 8px 12px 0;
  }

  .brand-link {
    min-height: 34px;
    padding: 4px 8px 4px 4px;
    font-size: 0.92rem;
  }

  .brand-logo {
    width: 26px;
    height: 26px;
  }

  .top-ad {
    width: calc(100% - 24px);
    height: 48px;
    aspect-ratio: auto;
    margin-top: 8px;
    font-size: 0.68rem;
  }

  .site-shell {
    min-height: auto;
  }

  .main-panel {
    padding: 8px 12px 16px;
  }

  .intro {
    margin: 6px auto 10px;
  }

  .intro h1 {
    margin-bottom: 6px;
    font-size: 1.42rem;
  }

  .intro p {
    display: none;
  }

  .calculator-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 10px 0;
  }

  .nav-button {
    flex: none;
    min-width: 0;
    min-height: 38px;
    padding: 5px 6px;
    font-size: 0.69rem;
    line-height: 1.15;
  }

  .inline-form,
  .checks {
    align-items: stretch;
    flex-direction: column;
  }

  .input.short,
  .wide-input-row,
  .target-row .input {
    width: 100%;
  }

  .tool-card {
    padding: 12px;
  }

  .tool-card + .tool-card,
  .result-card {
    margin-top: 16px;
  }

  .calculator-root {
    margin-bottom: 64px;
  }

  .score-box {
    margin-left: 0;
    margin-right: 0;
    font-size: 1.5rem;
  }

  .tab-list {
    height: auto;
  }

  .tab-button {
    min-height: 36px;
    padding: 6px;
    font-size: 0.78rem;
  }

  th,
  td {
    padding: 7px 6px;
  }

  .entry-table .input,
  .entry-table .select {
    min-width: 96px;
  }

  .output-grid {
    flex-direction: column;
  }

  .site-footer {
    flex-wrap: wrap;
  }
}

@media (max-width: 420px) {
  .calculator-nav {
    gap: 6px;
  }

  .nav-button {
    min-height: 40px;
    padding: 5px;
    font-size: 0.66rem;
  }

  .grade-chart {
    width: 100%;
    min-width: 0;
  }
}
