:root {
  --ink: #10202f;
  --muted: #5a6874;
  --line: #d8dee4;
  --surface: #ffffff;
  --page: #eef4f6;
  --accent: #0f766e;
  --accent-dark: #0b4f4b;
  --warn: #fff4d7;
  --warn-line: #e1bd64;
  --danger: #a53b3b;
  --shadow: 0 18px 50px rgba(18, 35, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #f7fbfb 0%, var(--page) 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

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

.intro {
  max-width: 760px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 5vw, 4.3rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.intro p:not(.eyebrow) {
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.alert {
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn);
  color: #594019;
  line-height: 1.45;
}

.calculator-grid,
.explanation-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(360px, 1.2fr);
  gap: 18px;
}

.explanation-grid {
  margin-top: 18px;
}

.panel {
  border: 1px solid rgba(16, 32, 47, 0.12);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.controls {
  padding: 22px;
}

.field-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

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

.pen-reference-row {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 8px;
  background: #f4f8f8;
}

.pen-reference-row .field-group {
  margin-bottom: 0;
}

label {
  color: #2e3f4d;
  font-size: 0.86rem;
  font-weight: 750;
}

.label-line {
  display: flex;
  align-items: center;
  gap: 7px;
}

.info-tip {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  border: 1px solid rgba(15, 118, 110, 0.38);
  border-radius: 50%;
  background: #edf7f6;
  color: var(--accent-dark);
  cursor: help;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  padding: 0;
}

.info-tip::after {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 9px);
  z-index: 5;
  width: min(260px, 78vw);
  padding: 10px 12px;
  border: 1px solid rgba(16, 32, 47, 0.14);
  border-radius: 8px;
  background: #10202f;
  box-shadow: 0 10px 24px rgba(16, 32, 47, 0.2);
  color: #fff;
  content: attr(data-tip);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translate(-50%, 4px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.info-tip::before {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  z-index: 6;
  width: 10px;
  height: 10px;
  background: #10202f;
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px) rotate(45deg);
  transition: opacity 150ms ease, transform 150ms ease;
}

.info-tip:hover,
.info-tip:focus-visible {
  border-color: var(--accent);
  background: #dff0ef;
  outline: none;
}

.info-tip:hover::after,
.info-tip:hover::before,
.info-tip:focus-visible::after,
.info-tip:focus-visible::before {
  opacity: 1;
  transform: translate(-50%, 0);
}

.inline-tip {
  margin-left: 4px;
  vertical-align: -3px;
}

select,
input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
}

select:focus,
input:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--accent);
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  margin: 4px 0 18px;
  color: var(--muted);
  font-weight: 650;
  line-height: 1.4;
}

.check-row input {
  min-height: auto;
  margin-top: 3px;
}

.form-section {
  margin: 18px 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.form-section h2 {
  margin-bottom: 14px;
  color: var(--ink);
  font-size: 0.94rem;
}

.primary-action {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.results {
  display: grid;
  grid-template-rows: auto minmax(220px, auto) auto auto auto;
  gap: 18px;
  padding: 22px;
  overflow: hidden;
}

.result-topline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-topline span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: #e8f4f3;
  color: var(--accent-dark);
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

#confidence-badge.warning {
  background: #fde9e9;
  color: var(--danger);
}

.pen-figure {
  position: relative;
  display: grid;
  margin: 0;
  border-radius: 8px;
  background: #f6f8f9;
}

.pen-image {
  width: 100%;
  max-height: 270px;
  object-fit: contain;
  object-position: center;
  border-radius: 8px;
  background: transparent;
}

.image-zoom-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  min-height: 34px;
  border: 1px solid rgba(16, 32, 47, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent-dark);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 7px 11px;
}

.image-zoom-button:hover,
.image-zoom-button:focus-visible {
  background: #fff;
  outline: 3px solid rgba(15, 118, 110, 0.18);
}

.result-number {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.result-number p {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.result-number strong {
  font-size: clamp(3rem, 8vw, 6rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.result-detail,
.panel p {
  color: var(--muted);
  line-height: 1.55;
}

.result-detail {
  min-height: 74px;
  padding: 14px;
  border-radius: 8px;
  background: #f4f8f8;
}

.supply-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.metric {
  min-height: 86px;
  border: 1px solid rgba(16, 32, 47, 0.1);
  border-radius: 8px;
  background: #fbfdfd;
  padding: 13px;
}

.metric span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric strong {
  color: var(--ink);
  font-size: 1.32rem;
  line-height: 1.1;
}

#supply-suggestion {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.explanation-grid .panel {
  padding: 22px;
}

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

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

.faq-panel h2 {
  margin-bottom: 16px;
  font-size: clamp(1.3rem, 3vw, 2rem);
}

.faq-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 22px;
}

.faq-list article {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.faq-list h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.98rem;
}

.faq-list p {
  margin-bottom: 0;
}

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

.guide-heading {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

.guide-heading h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 2.15rem);
  line-height: 1.08;
}

.guide-heading p:last-child {
  margin-bottom: 0;
}

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

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

thead th {
  background: #f6faf9;
  color: #263b48;
  font-size: 0.84rem;
  font-weight: 850;
}

tbody th {
  width: 42%;
  color: var(--ink);
  font-weight: 780;
}

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

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

.guide-note {
  margin-top: 16px;
  padding: 16px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #f4f8f8;
}

.guide-note h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.guide-note p {
  margin-bottom: 0;
}

.resource-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 26px;
}

.resource-groups h3 {
  margin: 0 0 10px;
  color: #263b48;
  font-size: 0.94rem;
}

.source-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.source-list li {
  padding-left: 3px;
  line-height: 1.45;
}

.source-list a {
  color: var(--accent-dark);
  text-decoration-color: rgba(15, 118, 110, 0.32);
  text-underline-offset: 3px;
  font-size: 0.92rem;
  font-weight: 750;
}

.source-list a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 64px 24px 24px;
  background: rgba(16, 32, 47, 0.82);
}

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

.image-modal img {
  max-width: min(1100px, 96vw);
  max-height: 84vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

.modal-close {
  position: fixed;
  top: 18px;
  right: 18px;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 850;
  padding: 8px 13px;
}

.modal-close:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.42);
}

.error {
  color: var(--danger);
  font-weight: 750;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 18px;
  }

  .calculator-grid,
  .explanation-grid,
  .faq-list,
  .guide-heading,
  .resource-groups,
  .field-row {
    grid-template-columns: 1fr;
  }

  .results {
    grid-template-rows: auto auto auto auto auto;
  }

  .supply-summary {
    grid-template-columns: 1fr;
  }
}
