/*
 * Küçük işlemci (BT Atölyesi) — yalnızca bu simülasyona özgü stiller.
 * Düzen, kontroller, anlatım kutusu, sayaç kutuları ve kod paneli çekirdekte (core/theme.css).
 * Burada: sahne (bellek + çip), çip şeması, bellek ↔ çip hattı, 7 parçalı gösterge, görev şeridi,
 * program düzenleyicisi, "Nasıl çalışır?" kutusu ve akıllı tahta ölçekleri. Renkler yalnız `--lab-*` değişkenlerinden.
 */

.cpu [hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------- sahne */

.cpu-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 0.75fr) minmax(0, 1.6fr);
  align-items: start;
  gap: 28px;
  padding: 20px 22px 22px;
  border-radius: var(--lab-radius-lg);
  background: var(--lab-bg-sunken);
}

.cpu-part__title {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--lab-text-2);
}

.cpu-part__note {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--lab-text-2);
}

/* Telefonda sahne yapışık değil (uzun), çip üstte, bellek altta; hat çizilmez */
@container lab (max-width: 700px) {
  .cpu .lab-visual {
    position: static;
  }

  .cpu-stage {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    padding: 16px;
  }

  .cpu-chipcol {
    order: -1;
    min-width: 0;
  }
}

/* Telefonda şema ekran genişliğine küçülünce yazıları ~5 px'e iniyordu: okunur boyda kalır, yana kayar. */
@container lab (max-width: 480px) {
  .cpu .cpu-chipcol {
    margin-inline: -16px;
    padding-inline: 16px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .cpu .cpu-chip {
    width: 440px;
    max-height: none;
  }
}

/* ---------------------------------------------------------------- bellek */

.cpu-cells {
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--lab-font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.cpu-cell {
  display: grid;
  grid-template-columns: 1em 2em 6.6em 2.4em minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 27px;
  padding: 0 6px;
  border-bottom: 1px solid var(--lab-separator);
  border-radius: 6px;
  transition: background-color var(--lab-dur) var(--lab-ease);
}

.cpu-cell__pc {
  color: var(--lab-accent);
  font-weight: 700;
  opacity: 0;
}

.cpu-cell.is-pc .cpu-cell__pc {
  opacity: 1;
}

.cpu-cell__addr,
.cpu-cell__ad,
.cpu-cell__meaning {
  color: var(--lab-text-2);
}

.cpu-cell__dec {
  text-align: right;
}

.cpu-cell__meaning {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cpu-cell.is-code .cpu-cell__meaning {
  color: var(--lab-text);
  font-weight: 600;
}

.cpu-cell.is-empty .cpu-cell__bits,
.cpu-cell.is-empty .cpu-cell__dec,
.cpu-cell.is-empty .cpu-cell__meaning {
  color: var(--lab-text-2); /* soluk ama AA: saydamlık kontrastı 2:1'e düşürüyordu */
}

.cpu-cell.is-hit {
  background: var(--lab-accent-soft);
}

.cpu-cell.is-changed .cpu-cell__dec,
.cpu-cell.is-changed .cpu-cell__bits {
  color: var(--lab-accent);
}

/* ---------------------------------------------------------------- çip */

.cpu-chip {
  display: block;
  width: 100%;
  height: auto;
  max-height: 480px; /* kısa ekranda sahne bir ekrana sığsın */
  overflow: visible;
  font-family: var(--lab-font);
}

.cpu-chip text {
  fill: var(--lab-text);
}

.cpu-chip__body {
  fill: var(--lab-bg);
  stroke: var(--lab-track);
  stroke-width: 1.5;
}

.cpu-chip__deco line {
  stroke: var(--lab-track);
  stroke-width: 2;
  stroke-linecap: round;
}

.cpu-wire {
  fill: none;
  stroke: var(--lab-track-soft);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cpu-wire--lit {
  stroke: var(--lab-accent);
  stroke-width: 2.5;
  opacity: 0;
  transition: opacity var(--lab-dur) var(--lab-ease);
}

.cpu-wire--lit.is-on {
  opacity: 1;
}

.cpu-block rect,
.cpu-block polygon {
  fill: var(--lab-bg-sunken);
  stroke: var(--lab-track);
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: stroke var(--lab-dur) var(--lab-ease), fill var(--lab-dur) var(--lab-ease);
}

.cpu-block.is-on rect,
.cpu-block.is-on polygon {
  fill: var(--lab-accent-soft);
  stroke: var(--lab-accent);
  stroke-width: 2.5;
}

.cpu-chip .cpu-chip__small {
  fill: var(--lab-text-2);
  font-size: 11px;
}

.cpu-chip .cpu-chip__strong {
  fill: var(--lab-text);
  font-weight: 600;
}

.cpu-chip .cpu-chip__val {
  font-family: var(--lab-font-mono);
  font-size: 17px;
  font-weight: 600;
}

.cpu-chip .cpu-chip__val--small {
  font-size: 15px;
}

.cpu-chip .cpu-chip__end {
  text-anchor: end;
}

.cpu-chip .cpu-chip__op {
  fill: var(--lab-accent);
  font-size: 16px;
  font-weight: 700;
}

.cpu-phase circle {
  fill: none;
  stroke: var(--lab-track);
  stroke-width: 1.5;
}

.cpu-chip .cpu-phase text {
  fill: var(--lab-text-2);
  font-size: 13px;
}

.cpu-phase.is-on circle {
  fill: var(--lab-accent);
  stroke: var(--lab-accent);
}

.cpu-chip .cpu-phase.is-on text {
  fill: var(--lab-text);
  font-weight: 600;
}

.cpu-pin line {
  stroke: var(--lab-track);
  stroke-width: 1.5;
}

.cpu-pin circle {
  fill: var(--lab-bg);
  stroke: var(--lab-track);
  stroke-width: 1.5;
}

.cpu-pulse {
  fill: var(--lab-accent);
}

.cpu-chip .cpu-pulse-text {
  fill: var(--lab-accent);
  font-family: var(--lab-font-mono);
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--lab-bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* -------------------------------------------------- bellek ↔ çip hattı */

.cpu-bus {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.cpu-bus path {
  fill: none;
  stroke: var(--lab-accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cpu-token {
  position: absolute;
  top: 0;
  left: 0;
  padding: 2px 7px;
  border-radius: var(--lab-radius-pill);
  background: var(--lab-accent-fill);
  color: var(--lab-accent-text);
  font-family: var(--lab-font-mono);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------ durum alanı */

.cpu-stats {
  align-items: stretch;
}

.cpu-display {
  flex: 1.4 1 220px;
}

.cpu-seg {
  display: block;
  width: auto;
  height: 52px;
  margin-bottom: 6px;
  overflow: visible;
}

.cpu-seg line {
  stroke: var(--lab-text-2);
  stroke-opacity: 0.14;
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke var(--lab-dur) var(--lab-ease), stroke-opacity var(--lab-dur) var(--lab-ease);
}

.cpu-seg line.is-on {
  stroke: var(--lab-accent);
  stroke-opacity: 1;
}

.cpu-history {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  min-height: 1.3em;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--lab-font-mono);
  font-size: 13px;
  color: var(--lab-text-2);
}

/* Görev şeridi */
.cpu-task {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px 14px;
  border-radius: var(--lab-radius);
  background: var(--lab-bg-sunken);
  box-shadow: inset 0 0 0 2px var(--lab-separator);
}

.cpu-task.is-met {
  box-shadow: inset 0 0 0 2px var(--lab-accent);
}

.cpu-task__info {
  flex: 1 1 260px;
  min-width: 0;
}

.cpu-task__eyebrow {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--lab-text-2);
}

.cpu-task__title {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 600;
}

.cpu-task__desc {
  margin: 2px 0 0;
  font-size: 16px;
  color: var(--lab-text-2);
}

.cpu-task__result {
  margin: 6px 0 0;
  font-size: 16px;
}

.cpu-task__result:empty {
  display: none;
}

.cpu-task.is-met .cpu-task__result {
  color: var(--lab-accent);
  font-weight: 600;
}

.cpu-task__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ------------------------------------------------------ program paneli */

.cpu-program__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.cpu-program__edit {
  flex: none;
}

.cpu-program__editor {
  display: block;
  width: 100%;
  min-height: 300px;
  margin: 0;
  border: 0;
  resize: vertical;
  font-family: var(--lab-font-mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--lab-text);
  tab-size: 8;
  white-space: pre;
}

.cpu-program__editor:focus-visible {
  outline: 2px solid var(--lab-focus);
  outline-offset: -2px;
}

.cpu-errors {
  margin: 0;
  padding: 0 4px;
  list-style: none;
  font-size: 14px;
}

.cpu-errors:empty {
  display: none;
}

.cpu-errors li {
  margin-bottom: 4px;
}

.cpu-errors__line {
  color: var(--lab-text-2);
  font-weight: 600;
}

/* --------------------------------------------------- nasıl çalışır? */

.cpu-how {
  flex: none;
  padding: 8px 18px;
  border-radius: var(--lab-radius);
  background: var(--lab-bg-sunken);
}

.cpu-how > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

.cpu-how p {
  margin: 0 0 12px;
  max-width: 72ch;
  font-size: 16px;
  line-height: 1.55;
}

.cpu-how__sub {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--lab-text-2);
}

.cpu-ops {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 6px 14px;
  margin: 0 0 12px;
  font-size: 14px;
}

.cpu-ops dt {
  font-family: var(--lab-font-mono);
  font-weight: 700;
}

.cpu-ops dd {
  margin: 0;
  color: var(--lab-text-2);
}

.cpu-ops .cpu-ops__code {
  font-family: var(--lab-font-mono);
}

.cpu-how .cpu-how__syntax {
  font-size: 14px;
  color: var(--lab-text-2);
}

/* Geniş ekranda program paneli ve "Nasıl çalışır?" yan yana */
@container lab (min-width: 900px) {
  .cpu-codes {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    align-items: start;
    gap: 16px;
  }

  .cpu-program .lab-code__pre {
    max-height: 420px;
  }
}

/* ============================================ akıllı tahta (tam ekran) */

.cpu-board:not(.lab--app) .cpu-how,
.cpu-board:not(.lab--app) .lab-settings {
  display: none;
}

.cpu-board:not(.lab--app) .lab-narration {
  font-size: 22px;
}

.cpu-board:not(.lab--app) .cpu-cells {
  font-size: 17px;
}

.cpu-board:not(.lab--app) .cpu-cell {
  min-height: 34px;
}

/* ----------------------------------------------- ortak şablon (core/app-layout.js) */
/* Geniş ekranda sahne çerçeveyi doldurur: 16 bellek satırı ve çip şeması sahnenin yüksekliğine sığar.
   Telefonda sahne içeriği kadar uzar (sayfa kayar). */
.lab--app .cpu-stage {
  padding: 0;
  border-radius: 0;
  background: none;
}

@container lab (min-width: 701px) {
  .lab--app .cpu-stage {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    container: cpustage / size;
  }

  .lab--app .cpu-memory,
  .lab--app .cpu-chipcol {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100cqh;
  }

  .lab--app .cpu-cells {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-rows: repeat(16, minmax(0, 1fr));
    font-size: clamp(11px, calc((100cqh - 48px) / 16 * 0.52), 14px);
  }

  .lab--app .cpu-cell {
    min-height: 0;
  }

  .lab--app .cpu-chip {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    max-height: none;
  }
}

.lab--app .cpu-seg {
  height: 36px;
  margin-bottom: 2px;
}

/* Telefonda şema yana kaymaz: çerçevenin genişliğine sığar (iç kaydırma yok). Küçülünce okunur kalsın diye
   küçük yazılar şema biriminde büyür. */
@container lab (max-width: 480px) {
  .lab--app .cpu-chipcol {
    margin-inline: -12px;
    padding-inline: 0;
    overflow: visible;
  }

  .lab--app .cpu-chip {
    width: 100%;
  }

  .lab--app .cpu-chip .cpu-chip__small {
    font-size: 15px;
  }
}
