:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --surface: #fffefa;
  --surface-2: #ece8dc;
  --ink: #171a1f;
  --muted: #686f78;
  --line: #d8d2c4;
  --green: #0f8f67;
  --green-soft: #d9f2e8;
  --amber: #a86f00;
  --amber-soft: #fff1cd;
  --red: #c7433e;
  --red-soft: #ffe1df;
  --blue: #3167a8;
  --shadow: 0 18px 48px rgba(39, 38, 34, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 50% 0%, rgba(15, 143, 103, 0.16), transparent 32rem),
    linear-gradient(180deg, #f8f6ef 0%, var(--bg) 46%, #efeadf 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(27px, 9vw, 44px);
  line-height: 1.03;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.icon-button,
.text-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.04);
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-size: 22px;
  font-weight: 800;
}

.icon-button.small {
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
}

.text-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
}

.text-button.subtle {
  color: var(--muted);
}

.status-strip,
.risk-hero,
.relative-panel,
.input-panel,
.params-panel,
.oracle-panel,
.positions-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.92);
  box-shadow: var(--shadow);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  box-shadow: none;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
}

.status-strip[data-state="healthy"] .status-dot {
  background: var(--green);
}

.status-strip[data-state="critical"] .status-dot,
.status-strip[data-state="liquidatable"] .status-dot {
  background: var(--red);
}

.risk-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
  padding: 18px;
  overflow: hidden;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.hf-value {
  margin-top: 4px;
  font-size: clamp(58px, 22vw, 104px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0;
}

.metric-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

#riskCanvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #f5f0e5;
}

.relative-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 12px;
  margin-bottom: 12px;
  padding: 16px;
}

.relative-price-box {
  display: grid;
  align-content: start;
  min-width: 0;
}

.relative-direction-button,
.relative-price-button {
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.relative-direction-button {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 6px;
}

.direction-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.relative-price-button {
  justify-self: start;
}

.relative-direction-button:focus-visible,
.relative-price-button:focus-visible {
  outline: 3px solid rgba(15, 143, 103, 0.24);
  outline-offset: 5px;
}

.relative-direction-button:disabled,
.relative-price-button:disabled {
  cursor: default;
}

.relative-direction-button:not(:disabled):hover .metric-label,
.relative-price-button:not(:disabled):hover .relative-price {
  color: var(--green);
}

.relative-price-button .relative-price {
  display: block;
}

.relative-price {
  margin-top: 6px;
  font-size: clamp(26px, 8vw, 44px);
  font-weight: 900;
  line-height: 1;
}

.relative-grid,
.params-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.relative-grid div,
.params-grid div,
.metric-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f0;
  padding: 11px;
}

.relative-grid span,
.params-grid span,
.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.relative-grid strong,
.params-grid strong,
.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.input-panel,
.params-panel,
.oracle-panel,
.positions-panel {
  margin-bottom: 12px;
  padding: 14px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading.compact {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.section-heading > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-align: right;
}

.address-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.address-field {
  margin-bottom: 0;
}

.account-summary {
  margin: 8px 0 12px;
}

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

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  min-width: 0;
}

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

.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 143, 103, 0.16);
}

.metric-grid {
  margin-bottom: 12px;
}

.metric-card {
  background: rgba(255, 254, 250, 0.92);
  box-shadow: 0 8px 24px rgba(39, 38, 34, 0.08);
}

.metric-card strong {
  font-size: 20px;
}

.positions-list {
  display: grid;
  gap: 8px;
}

.calculation-dialog {
  width: min(calc(100% - 28px), 620px);
  max-height: min(86vh, 760px);
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  overflow: auto;
  padding: 0;
}

.calculation-dialog::backdrop {
  background: rgba(23, 26, 31, 0.42);
  backdrop-filter: blur(6px);
}

.dialog-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(23, 26, 31, 0.28);
  padding: 16px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.calculation-detail {
  display: grid;
  gap: 10px;
}

.formula-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f0;
  padding: 12px;
}

.formula-box span,
.calculation-rows span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.formula-box strong {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.calculation-rows {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.calculation-rows div {
  display: grid;
  grid-template-columns: minmax(96px, 0.38fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 11px 12px;
  background: #fffefa;
}

.calculation-rows div + div {
  border-top: 1px solid var(--line);
}

.calculation-rows strong {
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.dialog-note {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

.dialog-note.muted {
  color: var(--muted);
}

.position-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f0;
  padding: 11px;
  color: var(--ink);
  text-align: left;
}

.position-row strong {
  display: block;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.position-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

body[data-risk="healthy"] .risk-hero {
  border-color: rgba(15, 143, 103, 0.42);
}

body[data-risk="warning"] .risk-hero {
  border-color: rgba(168, 111, 0, 0.5);
}

body[data-risk="critical"] .risk-hero,
body[data-risk="liquidatable"] .risk-hero {
  border-color: rgba(199, 67, 62, 0.55);
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 26px;
  }

  .risk-hero {
    grid-template-columns: minmax(0, 0.88fr) minmax(320px, 1fr);
    align-items: center;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .relative-panel,
  .address-row,
  .form-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

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

  .hf-value {
    font-size: clamp(50px, 24vw, 74px);
  }

  .dialog-card {
    padding: 14px;
  }

  .calculation-rows div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
