:root {
  --bg: #f5f5f7;
  --bg-soft: #f0f2f5;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --line: #d8dce3;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --accent: #0a84ff;
  --accent-strong: #0066cc;
  --danger: #b3261e;
  --ok: #0f8b5f;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 18px 42px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "SF Pro Text", "SF Pro Display", "Manrope", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  padding: 1rem clamp(0.8rem, 2vw, 1.6rem) 1.1rem;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 14% 15%, rgba(10, 132, 255, 0.09), transparent 30%),
    radial-gradient(circle at 80% 14%, rgba(125, 128, 255, 0.06), transparent 32%),
    radial-gradient(circle at 74% 84%, rgba(0, 102, 204, 0.05), transparent 26%);
}

h1,
h2,
h3,
h4,
legend {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

code {
  background: #eef3fb;
  border: 1px solid #dce5f5;
  border-radius: 6px;
  padding: 0.08rem 0.34rem;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.78rem;
}

.site-header {
  max-width: 1160px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.65rem 0.8rem;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-soft);
  position: relative;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.56rem;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 5px 14px rgba(10, 132, 255, 0.22);
}

.brand-eyebrow {
  font-size: 0.66rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
}

.site-header h1 {
  margin-top: 0.15rem;
  font-size: clamp(0.86rem, 1.5vw, 1.05rem);
  white-space: nowrap;
}

.page-main {
  max-width: 1160px;
  margin: 0.75rem auto 0;
}

.calculator-layout {
  margin-top: 0.85rem;
  display: grid;
  grid-template-columns: minmax(310px, 1.08fr) minmax(290px, 0.92fr);
  gap: 0.8rem;
}

.card {
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.82);
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
}

.input-card,
.result-card,
.live-card,
.info-card {
  padding: 0.8rem;
}

.card-head h3 {
  font-size: 0.95rem;
}

.card-head p {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.77rem;
}

.shape-picker {
  margin-top: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  padding: 0.58rem;
}

.shape-picker legend {
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0 0.26rem;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
}

.shape-option {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #334155;
  font: inherit;
  font-weight: 600;
  font-size: 0.75rem;
  min-height: 34px;
  cursor: pointer;
  transition: all 140ms ease;
}

.shape-option:hover {
  border-color: #b9c7dc;
}

.shape-option.is-active {
  color: var(--accent-strong);
  border-color: rgba(10, 132, 255, 0.45);
  box-shadow: inset 0 0 0 2px rgba(10, 132, 255, 0.12);
}

.shape-preview {
  margin: 0.52rem 0 0;
  border-radius: 10px;
  border: 1px solid #e3e8ef;
  background: linear-gradient(165deg, #fbfdff, #f2f6fb);
  min-height: 112px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.shape-preview img {
  width: min(100%, 260px);
  max-height: 138px;
  object-fit: contain;
  transition: opacity 130ms ease;
}

.group {
  margin-top: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-strong);
}

.group h4 {
  font-size: 0.8rem;
  font-weight: 650;
  color: #3f4b5f;
  padding: 0.52rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #f6f9ff, #ffffff 75%);
}

.form-row {
  padding: 0.52rem 0.7rem;
  border-bottom: 1px solid #eaedf2;
  display: grid;
  gap: 0.36rem;
}

.form-row:last-child {
  border-bottom: none;
}

.form-row.compact {
  border-bottom: none;
}

label {
  font-size: 0.74rem;
  font-weight: 620;
  color: #4a5769;
}

input,
select,
.unit-chip {
  min-height: 36px;
  border-radius: 9px;
  border: 1px solid #cfd7e3;
  font: inherit;
  font-size: 0.84rem;
  color: var(--text);
  background: #fff;
}

input,
select {
  width: 100%;
  padding: 0.42rem 0.56rem;
}

input:focus,
select:focus {
  outline: 0;
  border-color: rgba(10, 132, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.11);
}

.field-inline,
.field-currency {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.38rem;
}

.field-inline select,
.field-inline .unit-chip {
  min-width: 68px;
  text-align: center;
}

.field-currency span,
.unit-chip {
  min-height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #cfd7e3;
  border-radius: 9px;
  background: #f8fbff;
  padding: 0 0.55rem;
  color: #5f6d82;
  font-size: 0.78rem;
  font-weight: 640;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.switch {
  appearance: none;
  width: 42px;
  min-height: 24px;
  border: none;
  border-radius: 999px;
  background: #d4dae3;
  position: relative;
  cursor: pointer;
  transition: background 140ms ease;
}

.switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.2);
  transition: transform 140ms ease;
}

.switch:checked {
  background: linear-gradient(120deg, var(--accent), #5ac8fa);
}

.switch:checked::before {
  transform: translateX(18px);
}

.forging-grid {
  border-top: 1px solid #eaedf2;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.actions {
  margin-top: 0.72rem;
  display: flex;
  gap: 0.46rem;
}

.btn {
  border: none;
  border-radius: 10px;
  min-height: 35px;
  padding: 0.36rem 0.76rem;
  font: inherit;
  font-size: 0.79rem;
  font-weight: 650;
  cursor: pointer;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(125deg, #0a84ff, #0066cc);
  box-shadow: 0 10px 22px rgba(10, 132, 255, 0.27);
}

.btn-soft {
  color: #334155;
  border: 1px solid #d6dde9;
  background: #ffffff;
}

.btn-ghost {
  color: #2f3d53;
  border: 1px solid #d9e0eb;
  background: rgba(255, 255, 255, 0.75);
}

.right-stack {
  display: grid;
  gap: 0.8rem;
  align-content: start;
}

.metrics {
  margin: 0.6rem 0 0;
  display: grid;
  gap: 0.34rem;
}

.metric {
  background: var(--surface-strong);
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.44rem 0.56rem;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.35rem;
}

.metric dt {
  font-size: 0.74rem;
  color: #4a5769;
  font-weight: 620;
}

.metric dd {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 680;
  color: #16243a;
}

.metric-profit {
  border-color: #bfd9f7;
  background: linear-gradient(90deg, #f3f9ff, #ffffff);
}

.metric-profit .positive {
  color: var(--ok);
}

.metric-profit .negative {
  color: var(--danger);
}

.live-card {
  display: grid;
  gap: 0.5rem;
}

.live-path {
  font-size: 0.77rem;
  color: #4c5b70;
}

.sync-line {
  font-size: 0.75rem;
  color: #5b6779;
}

.status {
  min-height: 1.05rem;
  font-size: 0.74rem;
  color: #445166;
}

.status-error {
  color: var(--danger);
}

.site-footer {
  max-width: 1160px;
  margin: 0.8rem auto 0;
  color: var(--text-muted);
  font-size: 0.72rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.settings-dialog {
  display: none;
  pointer-events: none;
  width: min(680px, 94vw);
  border: none;
  border-radius: 20px;
  padding: 0;
  background: transparent;
}

.settings-dialog[open] {
  display: block;
  position: fixed;
  inset: 0;
  margin: auto;
  z-index: 100;
  pointer-events: auto;
}

.settings-dialog::backdrop {
  background: rgba(10, 18, 32, 0.35);
}

.settings-shell {
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.84);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.2);
  padding: 0.76rem;
}

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.56rem;
}

.settings-head h3 {
  font-size: 0.94rem;
}

.settings-form {
  display: grid;
  gap: 0.56rem;
}

.settings-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
}

.settings-group h4 {
  font-size: 0.78rem;
  color: #4a5769;
  background: #f8fafc;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.settings-note {
  margin: 0;
  padding: 0.44rem 0.7rem 0;
  color: #5a667a;
  font-size: 0.72rem;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.42rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.is-hidden {
  display: none !important;
}

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

@media (max-width: 760px) {
  body {
    padding: 0.6rem;
  }

  .site-header h1 {
    white-space: normal;
  }

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

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

  .actions,
  .settings-actions,
  .site-footer {
    flex-direction: column;
    align-items: stretch;
  }
}
