:root {
  --bg: #fafaf2;
  --ink: #0a0a0a;
  --muted: #444444;
  --brand: #0f6e72;
  --accent: #ffe030;
  --card: #ffffff;
  --border-color: #0a0a0a;
  --border: 2px solid #0a0a0a;
  --shadow: 4px 4px 0 #0a0a0a;
  --shadow-lg: 6px 6px 0 #0a0a0a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: linear-gradient(160deg, #fafaf2 0%, #f0f6f6 65%, #fff5cc 100%);
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 0.7rem;
}

.sim-card {
  width: min(1200px, 100%);
  height: min(480px, calc(100vh - 1.4rem));
  max-height: 480px;
  background: var(--card);
  border: var(--border);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.sim-header {
  background: var(--accent);
  border-bottom: var(--border);
  padding: 0.3rem 0.7rem;
}

.sim-header h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(0.95rem, 1.5vw, 1.2rem);
  line-height: 1.1;
}

.sim-header p {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.sim-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
}

.controls {
  border-right: var(--border);
  padding: 0.6rem;
  overflow: auto;
  display: grid;
  gap: 0.55rem;
  align-content: start;
  background: #fffef8;
}

.control-group {
  display: grid;
  gap: 0.22rem;
}

.control-group p {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.control-group.compact label {
  font-size: 0.75rem;
}

.control-row {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: 1fr 1fr;
}

.control-row.trio {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.corner-btn {
  min-width: 2rem;
  min-height: 2rem;
  padding: 0.25rem 0.45rem;
  font-size: 0.8rem;
  line-height: 1;
}

.toggle-text {
  font-size: 0.78rem;
  font-weight: 700;
}

label {
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: var(--border);
  background: #fff;
  color: var(--ink);
  padding: 0.38rem 0.48rem;
}

hr {
  width: 100%;
  border: 0;
  border-top: 2px solid var(--ink);
  margin: 0.15rem 0;
}

.pill-btn {
  border: var(--border);
  background: #fff;
  color: var(--ink);
  padding: 0.42rem 0.5rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--border-color);
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.pill-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--border-color);
  background: #fff8cc;
}

.pill-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border-color);
}

.pill-btn.accent {
  background: var(--accent);
}

.icon-btn {
  font-size: 0.92rem;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  min-width: 2.22rem;
  min-height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 0 var(--border-color);
}

.icon-btn svg {
  width: 14px;
  height: 14px;
  display: block;
  pointer-events: none;
}

.lozenge-toggle {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.lozenge-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.lozenge-track {
  width: 40px;
  height: 20px;
  border-radius: 999px;
  border: var(--border);
  background: #fff;
  box-shadow: 2px 2px 0 var(--border-color);
  position: relative;
  transition: background 120ms ease;
}

.lozenge-track::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 120ms ease;
}

.lozenge-toggle input:checked + .lozenge-track {
  background: #d7f5f2;
}

.lozenge-toggle input:checked + .lozenge-track::after {
  transform: translateX(20px);
}

.status {
  border: var(--border);
  background: #f2fbfb;
  padding: 0.38rem 0.48rem;
  font-size: 0.78rem;
  min-height: 2.15rem;
}

.calc-box {
  border: var(--border);
  background: #fffaf0;
  padding: 0.45rem 0.5rem;
  display: grid;
  gap: 0.18rem;
}

.calc-box.hidden {
  display: none;
}

.calc-box h2 {
  margin: 0 0 0.08rem;
  font-family: "Fraunces", serif;
  font-size: 0.88rem;
}

.calc-box p {
  margin: 0;
  font-size: 0.74rem;
}

.calc-box .calc-formula {
  color: var(--muted);
}

.calc-box .calc-value {
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.viewport {
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, #ffffff 0%, #e9f8f6 100%);
  position: relative;
}

#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

@media (max-width: 920px) {
  .sim-card {
    height: auto;
    max-height: none;
  }
  
  .sim-layout {
    grid-template-columns: 1fr;
  }
  
  .controls {
    border-right: none;
    border-bottom: var(--border);
  }
}
    grid-template-columns: 280px 1fr;
  }
}

@media (max-width: 760px) {
  .sim-card {
    height: min(480px, calc(100vh - 0.8rem));
  }

  .sim-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .controls {
    border-right: 0;
    border-bottom: var(--border);
    max-height: 180px;
  }
}
