:root {
  --paper: #f6f0df;
  --paper-deep: #e8dec0;
  --ink: #162521;
  --accent: #d2693c;
  --accent-deep: #8d3f20;
  --pond: #2e6f78;
  --mist: #d8ebea;
  --card: rgba(255, 251, 242, 0.96);
  --shadow: 0 18px 40px rgba(22, 37, 33, 0.14);
  --radius: 20px;
  --mono: "Courier New", "SFMono-Regular", Consolas, monospace;
  --sans: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 100vw;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(210, 105, 60, 0.18), transparent 22%),
    radial-gradient(circle at 80% 10%, rgba(46, 111, 120, 0.18), transparent 24%),
    linear-gradient(180deg, #fbf8ee 0%, var(--paper) 60%, #f1ead8 100%);
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(0, calc(100vw - 404px)) 380px;
  gap: 12px;
  width: 100vw;
  max-width: 100vw;
  margin: 0;
  padding: 12px;
  align-items: start;
}

.page-shell:not(.decision-chat-active) {
  grid-template-columns: 1fr;
}

.hero {
  grid-column: 1;
  padding: 26px;
  width: 100%;
  max-width: none;
  justify-self: stretch;
  border-radius: calc(var(--radius) + 6px);
  background: linear-gradient(135deg, rgba(255, 248, 236, 0.94), rgba(246, 240, 223, 0.92));
  box-shadow: var(--shadow);
  border: 1px solid rgba(22, 37, 33, 0.09);
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  color: var(--pond);
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3.4rem);
  line-height: 1;
}

.hero-copy {
  max-width: none;
  margin: 16px 0 0;
  font-size: 1.05rem;
  line-height: 1.55;
}

.drag-tip,
.inline-toggle span {
  font-size: 0.92rem;
}

.week-label,
.week-pill {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.76rem;
  color: var(--pond);
}

.week-pill {
  display: inline-block;
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(46, 111, 120, 0.12);
}

.tab-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 14px;
  grid-column: 1;
  width: 100%;
  justify-self: stretch;
}

main {
  grid-column: 1;
  width: 100%;
  max-width: none;
  justify-self: stretch;
}

.page-shell:not(.decision-chat-active) .hero,
.page-shell:not(.decision-chat-active) .tab-bar,
.page-shell:not(.decision-chat-active) main {
  grid-column: 1 / -1;
}

.tab-button,
.mini-tab,
.soft-button {
  border: 0;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}

.tab-button {
  position: relative;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 8px 20px rgba(22, 37, 33, 0.08);
}

.tab-button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  transform: translateX(-50%) translateY(6px);
  width: min(260px, 70vw);
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 33, 31, 0.96);
  color: #f6f0df;
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 14px 28px rgba(22, 37, 33, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 10;
}

.tab-button::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%) translateY(6px);
  border: 8px solid transparent;
  border-top-color: rgba(20, 33, 31, 0.96);
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
}

.tab-button.is-active,
.mini-tab.is-active {
  background: var(--accent);
  color: #fff8f4;
}

.tab-button:hover,
.tab-button:focus-visible,
.mini-tab:hover,
.soft-button:hover {
  transform: translateY(-1px);
}

.tab-button:hover::after,
.tab-button:hover::before,
.tab-button:focus-visible::after,
.tab-button:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.panel-grid {
  display: grid;
  gap: 18px;
}

.panel-grid-binary {
  grid-template-columns: 1.5fr 1.5fr 1.5fr;
  align-items: stretch;
}

.panel-grid-algorithm {
  grid-template-columns: 1fr;
}

.panel-grid-objects {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
}

.panel-grid-objects .intro-card {
  grid-column: span 4;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid rgba(22, 37, 33, 0.08);
  box-shadow: var(--shadow);
  padding: 22px;
}

.is-hidden {
  display: none;
}

.text-card,
.builder-card {
  grid-column: span 2;
}

.intro-card-binary {
  grid-column: span 3;
}

.text-card-binary,
.image-card-binary,
.code-card-binary {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.decision-stack {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
}

.decision-lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.decision-lower-grid > .builder-card,
.decision-lower-grid > .algorithm-placeholder-card,
.decision-lower-grid > .code-card {
  grid-column: span 1;
}

.decision-stack > .card {
  display: flex;
  flex-direction: column;
}

.decision-lower-grid > .card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.decision-stack > .card.is-hidden {
  display: none;
}

.decision-lower-grid > .card.is-hidden {
  display: none;
}

.panel-grid-algorithm .scenario-card,
.panel-grid-algorithm .builder-card,
.panel-grid-algorithm .code-card,
.panel-grid-algorithm .algorithm-placeholder-card {
  grid-column: span 1;
}

.algorithm-placeholder-panel {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(216, 235, 234, 0.38);
  border: 1px dashed rgba(46, 111, 120, 0.28);
}

.placeholder-kicker {
  margin: 0;
  font-weight: 700;
  color: rgba(22, 37, 33, 0.82);
}

.chat-card {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 16px;
  background: linear-gradient(180deg, #101b31 0%, #0d172a 100%);
  color: #eef4ff;
  border: 1px solid rgba(109, 145, 255, 0.14);
  overflow: hidden;
}

.page-shell:not(.decision-chat-active) .chat-card {
  display: none;
}

.chat-heading {
  align-items: center;
  margin-bottom: 8px;
}

.chat-card h3 {
  color: #eef4ff;
}

.chat-config-button {
  border: 1px solid rgba(109, 145, 255, 0.24);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #eef4ff;
  font: inherit;
  cursor: pointer;
}

.chat-history {
  flex: 1;
  min-height: 320px;
  margin: 0;
  padding: 0;
  color: #eef4ff;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  align-content: flex-start;
  gap: 12px;
}

.chat-message {
  padding: 14px 16px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-message.user {
  align-self: flex-end;
  max-width: 84%;
  background: rgba(52, 90, 212, 0.92);
}

.chat-message.ai {
  max-width: 92%;
  background: rgba(255, 255, 255, 0.12);
}

.chat-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(109, 145, 255, 0.12);
  margin-top: 16px;
}

.chat-status {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: rgba(238, 244, 255, 0.76);
}

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

.chat-card textarea {
  min-height: 74px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.08);
  color: #eef4ff;
  border-color: rgba(109, 145, 255, 0.18);
}

.chat-card textarea::placeholder {
  color: rgba(238, 244, 255, 0.58);
}

.chat-download-button,
.chat-send-button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
}

.chat-download-button {
  width: 100%;
  padding: 12px 14px;
  background: linear-gradient(135deg, #ff9d2f, #ff7f1d);
  color: #fff9ef;
  font-weight: 700;
  flex: 0 0 auto;
}

.chat-send-button {
  padding: 10px 14px;
  background: #3c63ff;
  color: #eef4ff;
}

.api-key-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 16, 30, 0.62);
}

.api-key-modal.is-hidden {
  display: none;
}

.api-key-card {
  width: min(460px, 100%);
  padding: 22px;
  border-radius: 24px;
  background: rgba(255, 251, 242, 0.98);
  box-shadow: 0 24px 48px rgba(9, 16, 30, 0.28);
}

.api-key-card h2 {
  margin: 0 0 10px;
}

.api-key-card .helper-copy {
  margin-bottom: 14px;
}

.api-key-card input[type="password"] {
  width: 100%;
}

.api-key-message {
  min-height: 1.2rem;
  margin: 10px 0 0;
  font-size: 0.92rem;
  color: rgba(22, 37, 33, 0.72);
}

.api-key-actions {
  margin-top: 14px;
}

.chat-actions {
  margin-top: 2px;
}

.object-blueprint-card,
.object-instance-card {
  grid-column: span 1;
}

.card-heading,
.control-row,
.compact-row,
.mini-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-heading {
  justify-content: space-between;
  margin-bottom: 12px;
}

.card h2,
.card h3 {
  margin: 0;
}

.feature-list {
  margin: 14px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}

.subtle-label,
.helper-copy,
.code-note {
  color: rgba(22, 37, 33, 0.76);
}

.subtle-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.92rem;
}

.helper-copy,
.code-note {
  margin: 0;
  line-height: 1.55;
}

textarea,
select,
input[type="text"] {
  width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(22, 37, 33, 0.15);
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
}

textarea:focus,
select:focus,
input[type="text"]:focus {
  outline: 2px solid rgba(210, 105, 60, 0.2);
  border-color: rgba(210, 105, 60, 0.4);
}

.binary-horizontal-display {
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.6;
  background: rgba(216, 235, 234, 0.3);
  cursor: default;
  resize: none;
}

.binary-horizontal-display:focus {
  outline: none;
  border-color: rgba(22, 37, 33, 0.15);
}

.binary-output,
.pixel-output,
.feedback-panel {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.binary-row,
.feedback-message {
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(216, 235, 234, 0.52);
}

.pixel-row-output {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(216, 235, 234, 0.4);
}

.pixel-output-header {
  font-weight: 700;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pond);
  background: transparent;
  padding: 4px 12px 8px;
}

.pixel-output-header span {
  cursor: help;
}

.pixel-row-header {
  margin-bottom: 4px;
}

.pixel-decimal,
.pixel-hex {
  font-family: var(--mono);
  min-width: 60px;
}

.pixel-row-output strong {
  font-size: 0.85rem;
  min-width: auto;
}

.binary-row strong {
  display: inline-block;
  min-width: 48px;
}

.blueprint-subheading {
  margin: 18px 0 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--pond);
}

.binary-bits,
.pixel-bits,
.code-display {
  font-family: var(--mono);
}

.code-display {
  min-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  margin: 0;
  border-radius: 18px;
  padding: 18px;
  background: #14211f;
  color: #f6f0df;
  line-height: 1.55;
}

.pixel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 14px;
}

.pixel-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.pixel-row-cells {
  display: grid;
  grid-template-columns: repeat(8, 50px);
  gap: 5px;
}

.pixel-cell {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  border: 1px solid rgba(22, 37, 33, 0.12);
  background: rgba(255, 255, 255, 0.86);
  cursor: pointer;
}

.pixel-cell.is-on {
  background: var(--accent);
  border-color: var(--accent-deep);
}

.mini-tabs {
  flex-wrap: wrap;
}

.mini-tab,
.soft-button {
  padding: 9px 14px;
  background: rgba(46, 111, 120, 0.12);
  color: var(--ink);
}

.mini-tab.is-locked {
  opacity: 0.45;
}

.algorithm-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.algorithm-actions {
  margin-top: 14px;
}

.object-blueprint,
.object-form {
  display: grid;
  gap: 12px;
}

.blueprint-block,
.state-block {
  border-radius: 16px;
  padding: 14px;
  background: rgba(216, 235, 234, 0.52);
}

.blueprint-block h4,
.state-block h4 {
  margin: 0 0 8px;
}

.attribute-grid {
  display: grid;
  gap: 10px;
}

.attribute-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.method-list {
  margin: 0;
  padding-left: 18px;
  line-height: 1.5;
}

.algorithm-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 246, 228, 0.98), rgba(232, 222, 192, 0.98));
  border: 1px solid rgba(141, 63, 32, 0.14);
  box-shadow: 0 10px 26px rgba(141, 63, 32, 0.12);
}

.stick-handle {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(141, 63, 32, 0.12);
  color: var(--accent-deep);
  font-weight: 700;
}

.stick-body {
  flex: 1;
  min-width: 0;
}

.stick-body input[type="text"] {
  padding: 10px 12px;
  border-radius: 12px;
}

.stick-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

.move-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(46, 111, 120, 0.14);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
}

.move-button:hover {
  transform: translateY(-1px);
  background: rgba(46, 111, 120, 0.22);
}

.move-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.editable-stick {
  border-style: dashed;
  background: rgba(255, 251, 242, 0.88);
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inline-toggle input {
  accent-color: var(--accent);
}

.feedback-good {
  background: rgba(117, 182, 130, 0.2);
}

.feedback-warn {
  background: rgba(210, 105, 60, 0.18);
}

@media (max-width: 980px) {
  .page-shell,
  .page-shell:not(.decision-chat-active) {
    grid-template-columns: 1fr;
  }

  .decision-lower-grid {
    grid-template-columns: 1fr;
  }

  .panel-grid-binary,
  .panel-grid-objects {
    grid-template-columns: 1fr;
  }

  .intro-card,
  .text-card,
  .builder-card {
    grid-column: span 1;
  }

  .panel-grid-algorithm .scenario-card,
  .panel-grid-algorithm .builder-card,
  .panel-grid-algorithm .code-card,
  .chat-card {
    grid-column: span 1;
    grid-row: auto;
    min-height: 0;
  }

  .chat-history {
    min-height: 240px;
  }

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

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1220px);
  }

  .hero,
  .card {
    padding: 18px;
  }

  .tab-bar {
    flex-direction: column;
  }

  .tab-button::after,
  .tab-button::before {
    display: none;
  }

  .control-row,
  .compact-row {
    flex-wrap: wrap;
  }

  .chat-input-row {
    grid-template-columns: 1fr;
  }
}