* {
  box-sizing: border-box;
}

:root {
  --black: #06080c;
  --black-soft: #12161d;
  --ink: #0c1710;
  --white: #ffffff;
  --paper: #eaf5ec;
  --paper-dim: #cfe6d6;
  /* 電気=黄色。回路キャンバス内の電気の流れだけに使う */
  --amber: #ffcf33;
  --amber-bright: #fff29a;
  --amber-deep: #b07d12;
  --amber-shadow: #8a5f10;
  /* 全体の基調カラー=緑 */
  --green: #2fbf71;
  --green-bright: #7ff0a8;
  --green-deep: #1c8f4e;
  --green-shadow: #0f5f37;
  --cyan: #38d1e0;
  --red: #ff3b57;
  --gray: #8b939b;
  --wire-off: #3b424b;
  --shadow: rgba(0, 0, 0, 0.45);

  --screen-w: 1366px;
  --screen-h: 768px;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--white);
  background: #000;
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

/* ===== 実画面（黒縁）と 1366x768 固定ステージ ===== */
.viewport {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, #0d1016 0%, #000 78%);
}

.screen {
  position: relative;
  flex: 0 0 auto;
  width: var(--screen-w);
  height: var(--screen-h);
  transform-origin: center center;
  /* JS が transform: scale() を付与して縦横比を保ったまま拡大縮小する */
  background:
    linear-gradient(0deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(135deg, #0d1119 0%, #06080c 58%, #131a12 100%);
  background-size: 44px 44px, 44px 44px, auto;
  overflow: hidden;
}

/* ===== ワークベンチ全体 ===== */
.workbench {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  height: 100%;
  padding: 16px 18px;
}

/* ===== ヘッダー ===== */
.task-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  height: 92px;
  padding: 12px 18px;
  color: var(--ink);
  background: var(--white);
  border: 5px solid var(--black);
  box-shadow: 8px 8px 0 var(--green-shadow);
  clip-path: polygon(0 0, 99.5% 3%, 100% 96%, 1% 100%);
}

.task-title-block {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.task-badge {
  flex: 0 0 auto;
  min-width: 84px;
  padding: 10px 12px;
  color: var(--black);
  background: var(--green);
  border: 3px solid var(--black);
  font-weight: 1000;
  text-align: center;
  transform: rotate(-4deg);
}

.task-heading {
  min-width: 0;
}

.task-header h2 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 1000;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.task-header p {
  margin: 4px 0 0;
  color: #2a2a2a;
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.header-side {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.step-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-position {
  padding: 3px 8px;
  color: var(--white);
  background: var(--black);
  font-size: 0.82rem;
  font-weight: 1000;
}

.progress-line {
  width: 150px;
  height: 14px;
  overflow: hidden;
  background: var(--paper-dim);
  border: 3px solid var(--black);
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green-deep), var(--green), var(--green-bright));
  transition: width 0.24s ease;
}

.progress-text {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 1000;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.icon-button,
.primary-action,
.home-exit-button,
.nav-button {
  height: 46px;
  border: 4px solid var(--black);
  box-shadow: 5px 5px 0 var(--shadow);
  font-weight: 1000;
  transition: transform 0.1s ease;
}

.icon-button:active,
.primary-action:active,
.home-exit-button:active,
.nav-button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--shadow);
}

.icon-button {
  width: 50px;
  color: var(--ink);
  background: var(--paper);
  font-size: 1.35rem;
}

.primary-action {
  min-width: 116px;
  padding: 8px 18px;
  color: var(--black);
  background: var(--green);
}

.home-exit-button {
  min-width: 326px;
  padding: 8px 14px;
  color: #0f172a;
  background: #ffcc33;
  border: 4px solid var(--black);
  border-radius: 8px;
  font-size: inherit;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.home-exit-button:hover,
.home-exit-button:focus-visible {
  background: #ffe28a;
  outline: none;
}

.home-exit-button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--shadow);
}

.nav-button {
  padding: 8px 14px;
  color: var(--white);
  background: var(--black-soft);
}

.nav-button.next {
  color: var(--black);
  background: var(--cyan);
}

.nav-button.next.next-ready:not(:disabled) {
  animation: next-ready-blink 0.72s ease-in-out infinite;
}

@keyframes next-ready-blink {
  0%, 100% {
    filter: brightness(1);
    box-shadow: 5px 5px 0 var(--shadow), 0 0 0 rgba(56, 209, 224, 0);
  }
  50% {
    filter: brightness(1.25);
    box-shadow: 5px 5px 0 var(--shadow), 0 0 20px rgba(56, 209, 224, 0.95);
  }
}

.nav-button:disabled,
.primary-action:disabled,
.icon-button:disabled,
.home-exit-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  box-shadow: 5px 5px 0 var(--shadow);
  transform: none;
}

.primary-action:disabled {
  cursor: wait;
}

.primary-action[hidden] {
  display: none;
}

/* ===== ステージ + 情報パネル ===== */
.stage-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  gap: 14px;
  min-height: 0;
}

.circuit-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(0deg, rgba(47, 191, 113, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    #081410;
  background-size: 34px 34px;
  border: 5px solid var(--white);
  box-shadow: 10px 10px 0 var(--green-shadow);
}

.circuit-stage::before {
  content: "回路を組み立てよう";
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  padding: 6px 11px;
  color: var(--black);
  background: var(--green);
  border: 3px solid var(--black);
  font-size: 0.78rem;
  font-weight: 1000;
  transform: rotate(-2deg);
  pointer-events: none;
}

#circuitCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

/* クリア/ミス/「つぎへ」の大演出（画面全体を覆う） */
.stage-cutin {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.42);
}

.stage-cutin[hidden] {
  display: none;
}

.stage-cutin::before {
  content: "";
  position: absolute;
  left: -12%;
  right: -12%;
  top: 42%;
  height: 140px;
  background: var(--green);
  border-top: 7px solid var(--black);
  border-bottom: 7px solid var(--black);
  transform: rotate(-5deg);
}

.stage-cutin.fail::before {
  background: var(--red);
}

.stage-cutin.fail {
  place-items: start center;
  background: rgba(0, 0, 0, 0.18);
}

.stage-cutin.fail::before {
  top: 74px;
  height: 112px;
}

.stage-cutin.fail .cutin-word {
  margin-top: 88px;
  font-size: 4.4rem;
}

.stage-cutin.fail .cutin-detail {
  top: 190px;
}

.stage-cutin.checking {
  place-items: start center;
  background: rgba(0, 0, 0, 0.08);
}

.stage-cutin.checking::before {
  top: 20px;
  height: 70px;
}

.stage-cutin.checking .cutin-word {
  margin-top: 28px;
  font-size: 2.4rem;
  text-shadow: 4px 4px 0 var(--black);
}

.stage-cutin.checking .cutin-detail {
  top: 100px;
  max-width: min(92%, 1120px);
  padding: 7px 12px;
  font-size: 0.86rem;
}

.cutin-word {
  position: relative;
  z-index: 1;
  color: var(--white);
  font-size: 5.2rem;
  font-weight: 1000;
  line-height: 1;
  text-shadow: 7px 7px 0 var(--black);
  transform: rotate(-4deg);
}

.cutin-detail {
  position: absolute;
  top: calc(50% + 84px);
  z-index: 2;
  max-width: min(80%, 640px);
  padding: 10px 18px;
  color: var(--ink);
  background: var(--green-bright);
  border: 4px solid var(--black);
  font-weight: 1000;
  text-align: center;
}

.cutin-detail .check-detail {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 34px;
  flex-wrap: wrap;
}

.cutin-detail .check-pattern {
  white-space: nowrap;
}

.miss-expected,
.continue-note {
  display: inline-block;
  margin-left: 18px;
  white-space: nowrap;
}

/* ===== 情報パネル ===== */
.info-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.guide-box,
.truth-box,
.state-box {
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--black);
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 12px 14px;
  min-height: 0;
}

.panel-label {
  display: inline-block;
  margin-bottom: 10px;
  padding: 5px 10px;
  color: var(--white);
  background: var(--black);
  font-size: 0.78rem;
  font-weight: 1000;
  line-height: 1;
}

.guide-box ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 20px;
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1.4;
}

/* ===== 真理値表 ===== */
.truth-table-wrap {
  overflow: auto;
}

.truth-table {
  width: 100%;
  border-collapse: collapse;
  font-weight: 1000;
  text-align: center;
}

.truth-table th,
.truth-table td {
  padding: 6px 8px;
  border: 2px solid var(--black);
  font-size: 0.95rem;
}

.truth-table thead th {
  color: var(--white);
  background: var(--black);
  font-size: 0.85rem;
}

.truth-table thead th.col-out {
  color: var(--black);
  background: var(--green);
}

.truth-table td.col-out {
  background: rgba(47, 191, 113, 0.24);
}

.truth-table tbody tr.current {
  outline: 4px solid var(--cyan);
  outline-offset: -4px;
}

.truth-table tbody tr.current td {
  background: var(--cyan);
  color: var(--black);
}

.truth-table tbody tr.selectable {
  cursor: pointer;
}

.truth-table tbody tr.selectable:hover:not(.current) td {
  background: rgba(56, 209, 224, 0.28);
}

.truth-table tbody tr.pass td {
  background: var(--green-bright);
}

.truth-table tbody tr.fail td {
  color: var(--white);
  background: var(--red);
}

.truth-table .bit-1 {
  color: var(--amber-deep);
}

.truth-hint {
  margin: 8px 0 0;
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1.35;
  color: #3a3a3a;
}

/* ===== 今の信号 ===== */
.state-box {
  overflow: hidden;
}

.signal-equation {
  margin-bottom: 0;
  padding: 9px 11px;
  color: var(--white);
  background: var(--black);
  border-left: 8px solid var(--amber);
  border-top: 3px solid var(--black);
  border-right: 3px solid var(--black);
  border-bottom: 3px solid var(--black);
  font-size: 0.92rem;
  font-weight: 1000;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.equation-line {
  display: inline-flex;
  align-items: baseline;
  gap: 28px;
  flex-wrap: wrap;
}

.equation-binary,
.equation-decimal {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.equation-op {
  display: inline-block;
  padding: 0 2px;
}

.radix-number {
  display: inline-block;
  white-space: nowrap;
}

.radix-number sub {
  position: relative;
  bottom: -0.15em;
  margin-left: 1px;
  font-size: 0.58em;
  line-height: 0;
  vertical-align: baseline;
}

.signal-equation.wrong {
  border-color: var(--red);
  border-left-color: var(--red);
  animation: signal-error-blink 0.72s steps(2, end) infinite;
}

@keyframes signal-error-blink {
  0%, 100% {
    box-shadow: 0 0 0 rgba(255, 59, 87, 0);
  }
  50% {
    box-shadow: 0 0 18px rgba(255, 59, 87, 0.9);
  }
}

.io-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

/* IN/OUT が多いときは3列にして縦を詰める（STEP7を1画面に収める） */
.io-grid.dense {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.io-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 8px;
  color: var(--white);
  background: var(--black-soft);
  border: 3px solid var(--black);
  font-size: 0.9rem;
  font-weight: 1000;
  white-space: nowrap;
  overflow: hidden;
}

.io-grid.dense .io-chip {
  min-height: 28px;
  padding: 3px 6px;
  font-size: 0.82rem;
}

.io-chip.on {
  color: var(--black);
  background: var(--amber);
}

/* IN/OUT ラベルは小さなバッジ。値は同じ行の横に置く */
.io-chip small {
  flex: 0 0 auto;
  padding: 1px 6px;
  color: var(--black);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 3px;
  font-size: 0.68rem;
  opacity: 0.9;
}

.io-chip.on small {
  background: rgba(0, 0, 0, 0.22);
}

/* ===== STAGE1〜6（縦長回路）用のコンパクト配置 =====
   回路エリアを細くし、ミッション/真理値表/今の信号を大きく見せる */
.screen.compact .stage-row {
  grid-template-columns: 440px minmax(0, 1fr);
}

/* 情報パネルは縦flexにして、3つのボックスが必ず画面内に収まるようにする */
.screen.compact .info-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen.compact.truth-rows-lg .info-panel {
  gap: 8px;
}

.screen.compact .guide-box {
  flex: 0 0 auto;
}

.screen.compact .truth-box {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 120px;
}

.screen.compact .truth-box .truth-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.screen.compact .state-box {
  flex: 0 1 auto;
  max-height: 40%;
  overflow: auto;
}

.screen.compact .panel-label {
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.screen.compact .guide-box ul {
  gap: 8px;
  font-size: 1.08rem;
  line-height: 1.4;
}

.screen.compact.truth-rows-lg .guide-box,
.screen.compact.truth-rows-lg .state-box {
  padding: 8px 10px;
}

.screen.compact.truth-rows-lg .guide-box .panel-label,
.screen.compact.truth-rows-lg .state-box .panel-label {
  margin-bottom: 6px;
  font-size: 0.78rem;
}

.screen.compact.truth-rows-lg .guide-box ul {
  gap: 4px;
  font-size: 0.9rem;
  line-height: 1.22;
}

.screen.compact .truth-table th,
.screen.compact .truth-table td {
  padding: 9px 12px;
  font-size: 1.14rem;
}

.screen.compact .truth-table thead th {
  font-size: 1rem;
}

.screen.compact .truth-hint {
  margin-top: 6px;
  font-size: 0.92rem;
}

.screen.compact .signal-equation {
  font-size: 1.02rem;
  padding: 10px 13px;
}

.screen.compact.truth-rows-lg .signal-equation {
  padding: 7px 9px;
  font-size: 0.88rem;
  line-height: 1.18;
}

.screen.compact .io-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.screen.compact .io-chip {
  min-height: 40px;
  font-size: 1.02rem;
}

/* 行数が多い真理値表はマス目を小さくして1画面に収める */
.screen.compact .truth-box.rows-md .truth-table th,
.screen.compact .truth-box.rows-md .truth-table td {
  padding: 4px 8px;
  font-size: 0.96rem;
  line-height: 1.08;
}

.screen.compact .truth-box.rows-md .truth-table-wrap {
  overflow: hidden;
}

.screen.compact .truth-box.rows-lg .truth-table th,
.screen.compact .truth-box.rows-lg .truth-table td {
  padding: 3px 5px;
  border-width: 1px;
  font-size: 0.81rem;
  line-height: 1.08;
}

.screen.compact .truth-box.rows-lg {
  padding: 8px 10px;
}

.screen.compact .truth-box.rows-lg .panel-label {
  margin-bottom: 5px;
  font-size: 0.78rem;
}

.screen.compact .truth-box.rows-lg .truth-table thead th {
  font-size: 0.77rem;
}

.screen.compact .truth-box.rows-lg .truth-table-wrap {
  overflow: hidden;
}

.screen.compact .truth-box.rows-lg .truth-hint {
  margin-top: 4px;
  font-size: 0.76rem;
  line-height: 1.15;
}

.truth-box.rows-lg .truth-table-wrap {
  max-height: none;
  overflow: visible;
}

/* 判定（OK）列 */
.status-cell {
  min-width: 42px;
  color: var(--green-deep);
  font-weight: 1000;
}

.screen.compact .truth-box.rows-lg .status-cell {
  min-width: 30px;
}

.status-cell.ok {
  color: var(--green-deep);
}

.status-cell.ng {
  color: var(--red);
}

.status-cell.status-pop {
  animation: status-pop 0.42s cubic-bezier(.2, 1.6, .35, 1);
}

@keyframes status-pop {
  0% {
    opacity: 0;
    transform: scale(0.2) translateY(7px);
  }
  58% {
    opacity: 1;
    transform: scale(1.32) translateY(-4px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.truth-table tbody tr.pass .status-cell.ok {
  color: var(--black);
}

.truth-table tbody tr.fail .status-cell.ng {
  color: var(--white);
}

/* ===== チェック演出：値を飛ばすアニメーション層 ===== */
.anim-layer {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  overflow: hidden;
}

.anim-chip {
  position: fixed;
  left: 0;
  top: 0;
  min-width: 28px;
  padding: 4px 9px;
  color: var(--black);
  background: #cfd6cd;
  border: 3px solid var(--black);
  border-radius: 999px;
  font-weight: 1000;
  font-size: 17px;
  line-height: 1;
  text-align: center;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
  will-change: transform;
}

/* 「1」は電気=黄色で光らせる */
.anim-chip.on {
  color: var(--black);
  background: var(--amber);
  box-shadow: 0 0 16px rgba(255, 207, 51, 0.85), 3px 3px 0 rgba(0, 0, 0, 0.4);
}

.confetti-piece {
  position: fixed;
  top: -24px;
  z-index: 1;
  width: 10px;
  height: 16px;
  border: 2px solid rgba(6, 8, 12, 0.32);
  opacity: 0.96;
  animation: confetti-fall 2600ms cubic-bezier(.2, .72, .34, 1) forwards;
  will-change: transform, opacity;
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, -30px, 0) rotate(0deg);
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0.9;
    transform: translate3d(var(--drift), calc(100vh + 60px), 0) rotate(760deg);
  }
}

.switch-bloom {
  position: fixed;
  left: 0;
  top: 0;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  color: var(--black);
  background: rgba(207, 214, 205, 0.78);
  border: 4px solid var(--black);
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 1000;
  line-height: 1;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.35);
  animation: switch-bloom 520ms ease-out forwards;
  will-change: transform, opacity, filter;
}

.switch-bloom.on {
  background: var(--amber);
  box-shadow:
    0 0 0 8px rgba(255, 207, 51, 0.16),
    0 0 28px rgba(255, 207, 51, 0.95);
}

.switch-bloom.output {
  animation-name: output-birth;
}

@keyframes switch-bloom {
  0% {
    opacity: 0;
    filter: blur(5px);
    transform: translate(-50%, -50%) scale(0.35);
  }
  38% {
    opacity: 1;
    filter: blur(0);
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    filter: blur(8px);
    transform: translate(-50%, -50%) scale(1.72);
  }
}

@keyframes output-birth {
  0% {
    opacity: 0;
    filter: blur(6px);
    transform: translate(-50%, -50%) scale(1.45);
  }
  42% {
    opacity: 1;
    filter: blur(0);
    transform: translate(-50%, -50%) scale(0.92);
  }
  100% {
    opacity: 0;
    filter: blur(4px);
    transform: translate(-50%, -50%) scale(0.58);
  }
}

/* ===== 全画面オーバーレイ ===== */
.fs-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(47, 191, 113, 0.14), transparent 60%),
    rgba(2, 3, 5, 0.94);
  cursor: pointer;
}

.fs-overlay.hidden {
  display: none;
}

.fs-overlay-inner {
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 40px 52px;
  text-align: center;
}

.fs-icon {
  font-size: 5rem;
  color: var(--green);
  text-shadow: 0 0 32px rgba(47, 191, 113, 0.7);
  animation: fs-pulse 1.5s ease-in-out infinite;
}

@keyframes fs-pulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

.fs-message {
  font-size: 1.9rem;
  font-weight: 1000;
  color: var(--white);
}

.fs-sub {
  font-size: 1rem;
  font-weight: 900;
  color: var(--green-bright);
}

/* ===== 縦向き注意（スマホ横向き前提） ===== */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  background: rgba(2, 3, 5, 0.96);
  text-align: center;
}

.rotate-hint-icon {
  font-size: 4rem;
  color: var(--green);
  animation: fs-pulse 1.5s ease-in-out infinite;
}

.rotate-hint-message {
  margin-top: 14px;
  font-size: 1.5rem;
  font-weight: 1000;
  color: var(--white);
}

/* 縦向き かつ 触覚ポインタ（スマホ/タブレット）のときだけ表示 */
@media (orientation: portrait) and (pointer: coarse) {
  .rotate-hint {
    display: grid;
  }
}

/* ============================================================
   iPhone 縦画面レイアウト (body.is-phone)
   - js/app.js が iPhone 判定時に body へ付与する
   - 1366x768 固定デザインの縮小をやめ、縦積み(ヘッダー/回路/情報)にする
   - 回路キャンバスは JS 側が実サイズへ自動フィットする
   - PC / iPad には影響しない
   ============================================================ */
body.is-phone .rotate-hint { display: none !important; }

body.is-phone .screen {
  width: 100vw;
  height: 100dvh;
  transform: none !important;
  background-size: 28px 28px, 28px 28px, auto;
}

body.is-phone .workbench {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  padding: 8px;
}

/* ヘッダー: 縦積み・コンパクト化 */
body.is-phone .task-header {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  height: auto;
  padding: 8px 10px;
  clip-path: none;
  border-width: 3px;
  box-shadow: 4px 4px 0 var(--green-shadow);
}
body.is-phone .task-header h2 { font-size: 1.05rem; }
body.is-phone .task-header p { font-size: 0.72rem; }
body.is-phone .header-side { align-items: stretch; gap: 6px; }
body.is-phone .step-progress { gap: 6px; }
body.is-phone .progress-line { flex: 1 1 auto; width: auto; }
body.is-phone .header-actions { flex-wrap: wrap; gap: 6px; }
body.is-phone .header-actions .icon-button,
body.is-phone .header-actions .primary-action,
body.is-phone .header-actions .nav-button {
  height: 40px;
  border-width: 3px;
  box-shadow: 3px 3px 0 var(--shadow);
}
body.is-phone .home-exit-button {
  order: 9;
  width: 100%;
  height: 38px;
  border-width: 3px;
  box-shadow: 3px 3px 0 var(--shadow);
  font-size: 0.8rem;
}

/* 本体: 回路(上・可変) + 情報パネル(下・スクロール) の縦積み */
body.is-phone .stage-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
}
body.is-phone .circuit-stage {
  flex: 1 1 auto;
  min-height: 42dvh;
  border-width: 3px;
  box-shadow: 5px 5px 0 var(--green-shadow);
}
body.is-phone .info-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
  max-height: 32dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
body.is-phone .guide-box,
body.is-phone .truth-box,
body.is-phone .state-box {
  padding: 8px 10px;
  border-width: 3px;
  box-shadow: 3px 3px 0 var(--shadow);
}
body.is-phone .guide-box ul { font-size: 0.8rem; }
body.is-phone .signal-equation { font-size: 0.85rem; }
body.is-phone .truth-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 演出の文字サイズを画面に収める */
body.is-phone .cutin-word { font-size: 3rem; text-shadow: 4px 4px 0 var(--black); }
