:root {
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-2: #f6faf9;
  --ink: #13201f;
  --ink-2: #30413f;
  --muted: #6d7c7a;
  --border: #d9e4e2;
  --border-strong: #b8c8c5;
  --accent: #ffb000;
  --accent-dark: #0d7c75;
  --green: #15803d;
  --red: #c62828;
  --shadow: 0 22px 55px rgba(23, 43, 41, .11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 10%, rgba(13, 124, 117, .16), transparent 30%),
    linear-gradient(135deg, #f7faf9 0%, var(--bg) 54%, #fff5dc 100%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.public-hidden {
  display: none;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  background: #0c1817;
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .08), 0 8px 24px rgba(0, 0, 0, .14);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #34d399);
  color: #0c1817;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  letter-spacing: .04em;
}

.brand small {
  color: rgba(255, 255, 255, .58);
  font-size: 11px;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.header-actions span,
.header-actions a {
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 999px;
  padding: 7px 12px;
  color: rgba(255, 255, 255, .86);
  text-decoration: none;
  background: rgba(255, 255, 255, .08);
}

.page {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(32px, 4vw, 54px);
  line-height: 1;
}

h2 {
  font-size: 22px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.calculator-panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 0;
}

.compact-head {
  padding-top: 6px;
}

.panel-head h2 {
  font-size: 20px;
}

.step-pill {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #0d7c75;
  color: #fff;
  font-weight: 900;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.form-grid.compact {
  padding: 0;
}

.full {
  grid-column: 1 / -1;
}

.form-group {
  min-width: 0;
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192, 124, 42, .18);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.material-field {
  position: relative;
}

.dropdown {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  display: none;
  max-height: 320px;
  overflow: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, .14);
}

.dropdown.open {
  display: grid;
  gap: 4px;
}

.dropdown-item {
  width: 100%;
  display: grid;
  gap: 3px;
  border: 0;
  border-radius: 6px;
  padding: 9px 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.dropdown-item:hover {
  background: var(--surface-2);
}

.dropdown-item span {
  color: var(--muted);
  font-size: 12px;
}

.dropdown-item.muted {
  color: var(--muted);
}

.align-right {
  text-align: right;
}

.new-material {
  display: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
}

.new-material.open,
.summary.open,
.result-grid.open,
.overlay.open {
  display: block;
}

.subhead {
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 800;
}

.summary {
  display: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface-2);
}

.summary strong,
.summary span {
  display: block;
}

.summary span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 14px;
  font-weight: 800;
  cursor: pointer;
}

.btn-calculate {
  width: 100%;
  min-height: 58px;
  font-size: 17px;
}

.btn-small {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 13px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #34d399);
  color: #0c1817;
  box-shadow: 0 12px 24px rgba(13, 124, 117, .18);
}

.btn-dark {
  background: #18150f;
  color: #fff;
}

.btn-ghost {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--ink);
}

.side-panel {
  padding: 18px;
}

.diagram {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.diagram img {
  width: 100%;
  height: auto;
  display: block;
}

.result-grid {
  display: none;
  grid-template-columns: 1.2fr .8fr;
  gap: 10px;
  margin-top: 14px;
}

.result-grid.open {
  display: grid;
}

.result-box {
  min-height: 106px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  background: var(--surface-2);
}

.hero-result {
  background: #0c1817;
  color: #fff;
}

.hero-result span {
  color: rgba(255, 255, 255, .68);
}

.result-box span,
.result-box strong {
  display: block;
}

.result-box span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.result-box strong {
  margin-top: 8px;
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.1;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  padding: 24px;
  background: rgba(24, 21, 15, .62);
  overflow: auto;
}

.guide-modal {
  width: min(940px, 100%);
  margin: 4vh auto;
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .24);
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.guide-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, .7fr);
  gap: 16px;
  align-items: start;
}

.guide-list {
  margin: 0;
  padding-left: 20px;
  color: var(--ink-2);
  line-height: 1.75;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: none;
  max-width: 360px;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .18);
  font-weight: 700;
}

.toast.open {
  display: block;
}

.toast.error {
  background: var(--red);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 26px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 34px;
}

.login-card p {
  color: var(--muted);
}

.login-card form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.login-card button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #18150f;
  font-weight: 900;
  cursor: pointer;
}

.brand-kicker {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
}

.flash {
  margin-top: 14px;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
}

.flash.error {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
}

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

  .hero {
    align-items: start;
    flex-direction: column;
  }

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

@media (max-width: 560px) {
  .app-header {
    height: auto;
    min-height: 64px;
    align-items: start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .page {
    width: min(100% - 20px, 1320px);
    padding-top: 18px;
  }

  h1 {
    font-size: 32px;
  }

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