:root {
  color-scheme: light;
  --bg: #181715;
  --panel: #f3ead8;
  --panel-dark: #24211c;
  --panel-warm: #fbf4e6;
  --ink: #1c1711;
  --muted: #6b6254;
  --line: #c1a46f;
  --line-dark: #6e5330;
  --accent: #9d241f;
  --accent-strong: #651715;
  --gold: #c69a3b;
  --gold-soft: #e4c982;
  --danger: #8f1e1a;
  --danger-bg: #fae1d5;
  --ok: #1f6a43;
  --warn: #9f6419;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(198, 154, 59, 0.08) 0 1px, transparent 1px 22px),
    radial-gradient(circle at 22% 0%, rgba(157, 36, 31, 0.32), transparent 34%),
    radial-gradient(circle at 80% 12%, rgba(198, 154, 59, 0.16), transparent 28%),
    linear-gradient(180deg, #2d2922 0%, var(--bg) 42%, #0f0e0c 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

body::before {
  background:
    linear-gradient(90deg, transparent 0 47%, rgba(198, 154, 59, 0.08) 47% 53%, transparent 53%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.03), transparent 45%);
  content: "";
  inset: 0;
  opacity: 0.42;
  pointer-events: none;
  position: fixed;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 56px;
  position: relative;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 18px 0 4px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold-soft);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 1px 1px #000;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #f8edd7;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.55);
}

h2 {
  font-size: 1.1rem;
  color: var(--ink);
}

.panel,
.metric {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.18)),
    var(--panel);
  border: 1px solid rgba(198, 154, 59, 0.62);
  border-radius: 8px;
  box-shadow:
    0 18px 34px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.panel {
  padding: 20px;
  margin-bottom: 18px;
  position: relative;
}

.panel::before {
  background: linear-gradient(90deg, var(--accent), var(--gold), transparent);
  border-radius: 8px 8px 0 0;
  content: "";
  height: 3px;
  left: -1px;
  position: absolute;
  right: -1px;
  top: -1px;
}

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

.section-heading p {
  color: var(--muted);
  font-size: 0.95rem;
}

.tier-grid,
.settings-grid,
.ratio-grid {
  display: grid;
  gap: 12px;
}

.tier-grid {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.settings-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.ratio-grid {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #5d5548;
  font-size: 0.86rem;
  font-weight: 700;
}

.field-help {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.3;
}

fieldset {
  background: rgba(255, 249, 235, 0.56);
  border: 1px solid rgba(110, 83, 48, 0.34);
  border-radius: 8px;
  margin: 0;
  padding: 10px 12px;
}

legend {
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 800;
  padding: 0 4px;
}

.mode-control {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mode-control label {
  display: flex;
  align-items: center;
  color: var(--ink);
  gap: 8px;
}

.mode-control input,
.checkbox-control input {
  min-height: auto;
  width: auto;
}

.checkbox-control {
  align-items: center;
  background: rgba(255, 249, 235, 0.56);
  border: 1px solid rgba(110, 83, 48, 0.34);
  border-radius: 8px;
  color: var(--ink);
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  position: relative;
}

.tooltip-trigger {
  align-items: center;
  background: #fff7e6;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--accent-strong);
  cursor: help;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 900;
  height: 20px;
  justify-content: center;
  line-height: 1;
  width: 20px;
}

.tooltip {
  background: #241b15;
  border: 1px solid var(--gold);
  border-radius: 6px;
  bottom: calc(100% + 10px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.42);
  color: #f8edd7;
  font-size: 0.82rem;
  font-weight: 650;
  left: 12px;
  line-height: 1.35;
  max-width: 280px;
  opacity: 0;
  padding: 10px 12px;
  pointer-events: none;
  position: absolute;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
  width: max-content;
  z-index: 10;
}

.tooltip::after {
  border: 7px solid transparent;
  border-top-color: var(--gold);
  content: "";
  left: 18px;
  position: absolute;
  top: 100%;
}

.checkbox-control:hover .tooltip,
.checkbox-control:focus-within .tooltip {
  opacity: 1;
  transform: translateY(0);
}

input,
select,
button {
  min-height: 42px;
  border-radius: 5px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(82, 62, 36, 0.45);
  background: linear-gradient(180deg, #fffaf0, #f6ead4);
  color: var(--ink);
  padding: 8px 10px;
  box-shadow: inset 0 1px 2px rgba(57, 39, 20, 0.1);
}

input:disabled,
select:disabled {
  background: linear-gradient(180deg, #d9cdb6, #c8b998);
  color: #716650;
  cursor: not-allowed;
  opacity: 0.82;
}

.fraction-input,
.unit-input {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.fraction-input > span,
.unit-input > span {
  color: var(--ink);
  font-weight: 850;
}

input:focus,
select:focus,
button:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(198, 154, 59, 0.35);
  outline-offset: 2px;
}

.secondary-button {
  border: 1px solid #e0bd67;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent),
    linear-gradient(135deg, #8a211e, #461412);
  color: #fff4dd;
  cursor: pointer;
  font-weight: 800;
  padding: 8px 14px;
  text-shadow: 0 1px 1px #000;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

.secondary-button:hover {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent),
    linear-gradient(135deg, #a52b25, #561816);
}

.compact-button {
  min-height: 36px;
}

.advanced-panel summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 850;
}

.advanced-heading {
  margin-top: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  display: grid;
  gap: 6px;
  padding: 16px;
  overflow: hidden;
  position: relative;
}

.metric::after {
  background: linear-gradient(180deg, var(--accent), transparent);
  content: "";
  inset: 0 auto 0 0;
  opacity: 0.8;
  position: absolute;
  width: 4px;
}

.metric span {
  color: #6a5741;
  font-size: 0.82rem;
  font-weight: 800;
}

.metric strong {
  color: #21160f;
  font-size: 1.35rem;
  line-height: 1.1;
}

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

.metric .warn {
  color: var(--warn);
}

.alert {
  border: 1px solid #c97455;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 700;
  margin-bottom: 18px;
  padding: 12px 14px;
}

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

table {
  background: rgba(255, 249, 235, 0.36);
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid rgba(110, 83, 48, 0.28);
  padding: 11px 8px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  background: rgba(36, 33, 28, 0.08);
  color: #5d4c38;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

tbody tr:hover {
  background: rgba(198, 154, 59, 0.12);
}

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

.empty-row {
  color: var(--muted);
  text-align: left;
}

@media (max-width: 820px) {
  .page-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .tier-grid,
  .settings-grid,
  .ratio-grid,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 540px) {
  .page {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .tier-grid,
  .settings-grid,
  .ratio-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }
}
