:root {
  --bg:           hsl(185 20% 4%);
  --fg:           hsl(185 70% 75%);
  --card:         hsl(185 15% 7%);
  --border:       hsl(185 30% 18%);
  --primary:      hsl(185 100% 60%);
  --accent:       hsl(45 100% 55%);
  --muted:        hsl(185 15% 45%);
  --radius:       0.5rem;
  --font-mono:    'JetBrains Mono', monospace;
  --font-display: 'Space Grotesk', sans-serif;
  --red:          hsl(0 80% 70%);
  --true-color:   hsl(120 80% 55%);
  --false-color:  hsl(0 70% 60%);
  --glow-primary: 0 0 10px hsl(185 100% 60% / 0.4), 0 0 30px hsl(185 100% 60% / 0.15);
  --glow-accent:  0 0 10px hsl(45 100% 55% / 0.4),  0 0 30px hsl(45 100% 55% / 0.15);
  --glow-text:    0 0 8px  hsl(185 100% 60% / 0.6);
  --glow-true:    0 0 8px  hsl(120 80% 55% / 0.6);
  --glow-false:   0 0 8px  hsl(0 70% 60% / 0.6);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 18px;
  min-height: 100vh;
  padding: 2rem 1rem 3rem;
  overflow-x: hidden;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    hsl(0 0% 0% / 0.03) 2px,
    hsl(0 0% 0% / 0.03) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

header {
  text-align: center;
  animation: fadeInDown 0.5s ease both;
}

header h1 img {
  width: 135px;
  height: auto;
  display: block;
  transition: transform 0.2s, filter 0.2s;
}

header h1 .project-card {
  display: inline-block;
  line-height: 0;
}

header h1 .project-card:hover img {
  transform: scale(1.06);
  filter: drop-shadow(0 0 10px hsl(185 100% 60% / 0.9)) drop-shadow(0 0 25px hsl(185 100% 60% / 0.5));
}

header p {
  margin-top: 0.5rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 1.1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.proto-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

@media (min-width: 750px) {
  .proto-grid { grid-template-columns: repeat(4, 1fr); }
}

.proto-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.6rem 0.75rem;
  background: hsl(185 15% 5%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.proto-desc {
  font-style: italic;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.proto-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.proto-value {
  font-size: 0.9rem;
  color: var(--fg);
}

.proto-value--mono {
  font-family: var(--font-mono);
}

.proto-key {
  font-family: var(--font-mono);
  color: var(--primary);
}

.umask-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.umask-opt {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  letter-spacing: 0.05em;
  text-transform: none;
  transition: background 0.2s, color 0.2s;
}

.umask-opt + .umask-opt {
  border-left: 1px solid var(--border);
}

.umask-opt.active {
  color: var(--primary);
  text-shadow: var(--glow-text);
}

.umask-opt:not(.active):hover {
  color: var(--accent);
  text-shadow: var(--glow-accent);
}

.label-short { display: none; }

@media (max-width: 480px) {
  .label-long  { display: none; }
  .label-short { display: inline; }
}

.umask-opt--solo {
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.umask-opt--solo.active {
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.umask-opt--solo:not(.active):hover {
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

.card-title {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Presets */
.presets {
  animation: fadeIn 0.5s 0.2s ease both;
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

@media (min-width: 750px) {
  .presets-grid { grid-template-columns: repeat(6, 1fr); }
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.6rem 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}

.preset-btn:hover {
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

.preset-btn.active {
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.preset-btn:active { transform: scale(0.95); }

.preset-btn .preset-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: var(--glow-accent);
}

.preset-btn.active .preset-label {
  color: var(--primary);
  text-shadow: var(--glow-text);
}

.preset-btn .preset-emoji {
  font-size: 1.4rem;
  line-height: 1;
  font-style: normal;
  font-family: var(--font-mono);
  color: var(--fg);
}

.preset-btn .preset-desc {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.preset-tooltip {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.75rem;
  min-height: 1.2em;
  transition: opacity 0.2s;
  font-style: italic;
}

/* Bool section */
.bool-section {
  animation: fadeIn 0.5s 0.3s ease both;
}

.bool-grid {
  display: flex;
  gap: 2rem;
  justify-content: center;
  align-items: flex-end;
}

.circuit-svg { display: block; overflow: visible; width: 100%; height: auto; }
.c-gate { fill: var(--bg-card); stroke-width: 2; }
.c-gate-shape { stroke: var(--primary); }
.c-lbl { font-family: var(--font-mono); font-size: 0.75rem; fill: var(--fg); }
.c-lbl-var { font-size: 1rem; font-weight: 700; }
.c-lbl-val { font-size: 1rem; font-weight: 700; }
.c-term { cursor: pointer; transition: opacity 0.15s; }
.c-term:hover { opacity: 0.7; }

.bool-category {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.bool-equals {
  font-family: var(--font-mono);
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  color: var(--accent);
  text-shadow: var(--glow-accent);
  margin-bottom: 1.5rem;
}

.bool-category-label {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: var(--glow-accent);
  text-align: center;
}

#result-op-label {
  font-size: 0.8rem;
  color: var(--accent);
  text-shadow: var(--glow-accent);
  white-space: nowrap;
}

.bool-buttons {
  display: flex;
  justify-content: center;
}

.bool-toggle {
  width: 5rem;
  height: 5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: 1px solid var(--false-color);
  border-radius: var(--radius);
  color: var(--false-color);
  cursor: pointer;
  font-family: var(--font-mono);
  box-shadow: 0 0 10px hsl(0 70% 60% / 0.4), 0 0 30px hsl(0 70% 60% / 0.15);
  text-shadow: var(--glow-false);
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s, transform 0.1s;
}

.bool-toggle:hover {
  border-color: var(--false-color);
}

.bool-toggle:active { transform: scale(0.95); }

.bool-toggle.active {
  border-color: var(--true-color);
  color: var(--true-color);
  box-shadow: 0 0 10px hsl(120 80% 55% / 0.4), 0 0 30px hsl(120 80% 55% / 0.15);
  text-shadow: var(--glow-true);
}

.bool-toggle .bool-label {
  font-size: 1.3rem;
  font-weight: 700;
}

.bool-toggle--result {
  cursor: default;
  pointer-events: none;
}

.bool-toggle--result:hover {
  border-color: inherit;
  box-shadow: inherit;
}

.bool-toggle--result.active {
  border-color: var(--true-color);
  color: var(--true-color);
  box-shadow: 0 0 10px hsl(120 80% 55% / 0.4), 0 0 30px hsl(120 80% 55% / 0.15);
  text-shadow: var(--glow-true);
}

/* Explainer / truth table */
.explainer {
  animation: fadeIn 0.5s 0.4s ease both;
}

.expr-input-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.expr-input {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
  text-shadow: var(--glow-text);
  text-transform: none;
  letter-spacing: 0;
  outline: none;
  border-bottom: 2px dashed transparent;
  transition: border-color 0.2s;
  text-align: center;
  width: 100%;
}

.expr-input:hover,
.expr-input:focus {
  border-bottom-color: var(--primary);
}

.expr-display {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--primary);
  text-shadow: var(--glow-text);
  text-transform: none;
  letter-spacing: 0;
}

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

.truth-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-mono);
  font-size: 1rem;
}

.truth-table th {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: var(--glow-accent);
  text-align: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.col-sep { border-left: 1px solid var(--border); }

.truth-table th.th-result {
  color: var(--accent);
  text-shadow: var(--glow-accent);
}

.truth-table th.th-intermediate {
  color: var(--muted);
  font-style: italic;
}

.truth-table td {
  text-align: center;
  padding: 0.4rem 1rem;
  transition: color 0.15s;
  border-bottom: 1px solid hsl(185 20% 10%);
}

.truth-table tr:last-child td { border-bottom: none; }

.truth-table tr.active-row td {
  background: hsl(185 20% 9%);
}

.td-true {
  color: var(--true-color);
  text-shadow: var(--glow-true);
  font-weight: 700;
}

.td-false {
  color: var(--false-color);
  text-shadow: var(--glow-false);
}

.td-result-true {
  color: var(--true-color);
  text-shadow: var(--glow-true);
  font-weight: 700;
  font-size: 1.1rem;
}

.td-result-false {
  color: var(--false-color);
  text-shadow: var(--glow-false);
  font-size: 1.1rem;
}

.td-exercise {
  color: var(--muted);
  cursor: pointer;
}

.td-exercise:hover {
  color: var(--primary);
}

.td-locked {
  color: var(--muted);
  opacity: 0.3;
  cursor: default;
}

@keyframes verify-pop {
  0%   { background: transparent; }
  30%  { background: color-mix(in srgb, var(--true-color) 20%, transparent); }
  100% { background: transparent; }
}

.td-verified-final {
  animation: verify-pop 0.6s ease forwards;
}

.truth-table.col-hovering [data-col] {
  transition: opacity 0.1s;
}
.truth-table.col-hovering [data-col].col-dimmed {
  opacity: 0.15;
}
.truth-table.col-complete.col-hovering [data-col].col-dimmed {
  opacity: 1;
}


/* Terminal */
.terminal-section {
  animation: fadeIn 0.5s 0.5s ease both;
}

.terminal-window {
  background: hsl(185 20% 3%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: inset 0 0 60px hsl(185 100% 60% / 0.03),
              0 0 40px hsl(185 100% 60% / 0.05);
}

.terminal-titlebar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  background: hsl(185 15% 6%);
  border-bottom: 1px solid var(--border);
}

.terminal-title {
  flex: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent);
  text-shadow: var(--glow-accent);
}

.traffic-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.traffic-dot.red    { background: hsl(0  70% 55%); }
.traffic-dot.yellow { background: hsl(45 70% 55%); }
.traffic-dot.green  { background: hsl(120 60% 45%); }

.terminal-body {
  padding: 1.25rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: 1.8;
  font-variant-ligatures: none;
}

.t-prompt { color: var(--primary); text-shadow: var(--glow-text); }
.t-cmd    { color: var(--fg); }
.t-out    { color: var(--muted); }

.t-editable {
  cursor: text;
  outline: none;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.2s;
}

.t-editable:hover,
.t-editable:focus {
  border-bottom-color: var(--primary);
}

.t-sym  { color: var(--primary); text-shadow: var(--glow-text); }
.b-over { text-decoration: overline; }

.t-out-true  { color: var(--true-color);  text-shadow: var(--glow-true);  font-weight: 700; }
.t-out-false { color: var(--false-color); text-shadow: var(--glow-false); }

footer {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--muted);
}

footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.2s, opacity 0.2s;
}

footer a img {
  opacity: 0.5;
  transition: opacity 0.2s;
}

footer a:hover {
  color: var(--fg);
}

footer a:hover img {
  opacity: 1;
}

@media (max-width: 480px) {
  .card-title {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .bool-grid {
    gap: 1rem;
  }
  .bool-equals {
    margin-bottom: 1rem;
  }
  .bool-result-cat {
    margin-left: 0.5rem;
    padding-left: 0.75rem;
  }
  .bool-toggle {
    width: 4rem;
    height: 4rem;
  }
  .bool-toggle .bool-label {
    font-size: 1rem;
  }
  .terminal-body {
    overflow-x: auto;
    white-space: nowrap;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
