:root {
  /* canvas 内の DOM はグレースケールで描き、蛍光体の色はシェーダーで乗せる */
  --fg: #ededed;
  --fg-dim: #8c8c8c;
  --fg-hi: #ffffff;
  --bg: #000;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(120% 90% at 50% 0%, #24262b 0%, #101114 70%);
  color: #d4d4d8;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

.stage {
  box-sizing: border-box;
  min-height: 100vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

/* ---------- モニター筐体 ---------- */

.monitor {
  /* パネル分の高さを差し引いて、画面に収まる 4:3 にする */
  width: min(100%, 760px, calc((100vh - 170px) * 4 / 3 + 56px));
  padding: 22px 22px 0;
  box-sizing: border-box;
  border-radius: 22px 22px 16px 16px;
  background: linear-gradient(180deg, #d9d3c3 0%, #c7c0ae 55%, #b3ac9a 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18),
    0 24px 50px rgba(0, 0, 0, 0.55);
}

.bezel {
  position: relative;
  padding: 14px;
  border-radius: 18px;
  background: #1a1a18;
  box-shadow:
    inset 0 0 0 2px #0c0c0b,
    inset 0 6px 18px rgba(0, 0, 0, 0.9),
    0 1px 0 rgba(255, 255, 255, 0.5);
}

#crt {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 14px / 18px;
  background: #050605;
  cursor: text;
}

/* ガラス面の反射。canvas 上のクリック（ヒットテスト）を妨げないよう pointer-events を切る */
.glass {
  position: absolute;
  inset: 14px;
  border-radius: 14px / 18px;
  pointer-events: none;
  background: radial-gradient(90% 70% at 28% 12%, rgba(255, 255, 255, 0.07) 0%, transparent 45%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.85);
}

.chin {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px 14px;
  color: #5d584c;
  font: 700 12px/1 "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0.18em;
}

.chin .model {
  font-weight: 400;
  letter-spacing: 0.1em;
}

.power {
  margin-left: auto;
  width: 34px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: linear-gradient(180deg, #bdb6a3, #a39c89);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.power:active {
  transform: translateY(1px);
}

.led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3a3a34;
}

.power[aria-pressed="true"] .led {
  background: #5cff7a;
  box-shadow: 0 0 6px #5cff7a;
}

/* ---------- canvas に描かれる「画面」の DOM ---------- */

.screen {
  box-sizing: border-box;
  width: 640px;
  height: 480px;
  padding: 18px 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.38 "SF Mono", "SFMono-Regular", Menlo, Consolas, "Hiragino Kaku Gothic ProN", "Noto Sans Mono CJK JP", monospace;
  overflow: hidden;
}

.status {
  display: flex;
  justify-content: space-between;
  padding: 2px 8px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.log {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-all;
}

.log p {
  margin: 0;
}

.log .dim {
  color: var(--fg-dim);
}

.log .hi {
  color: var(--fg-hi);
  font-weight: 700;
}

.log .err {
  color: var(--fg-hi);
  text-decoration: underline;
}

.log .ja {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

.log figure {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 6px 0;
}

.log img {
  width: 224px;
  height: 168px;
  image-rendering: pixelated;
  border: 1px solid var(--fg-dim);
}

.log figcaption {
  white-space: pre;
}

.bar {
  display: inline-block;
  height: 0.8em;
  background: var(--fg);
  vertical-align: -0.05em;
}

.prompt {
  display: flex;
  gap: 0.6ch;
  align-items: baseline;
}

.prompt input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg-hi);
  font: inherit;
  caret-color: var(--fg-hi);
  caret-shape: block;
}

/* 狭い画面では描画元の DOM を小さくして、縮小後の文字を読みやすくする */
@media (max-width: 560px) {
  .screen {
    width: 480px;
    height: 360px;
    padding: 12px 14px;
    gap: 6px;
  }

  .log img {
    width: 160px;
    height: 120px;
  }
}

.screen ::selection {
  background: var(--fg);
  color: var(--bg);
}

/* ---------- コントロールパネル ---------- */

.panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  max-width: 760px;
  font-size: 13px;
}

.panel fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.panel legend {
  float: left;
  margin-right: 4px;
  color: #8b8d94;
}

.panel label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  white-space: nowrap;
}

.panel input {
  accent-color: #5cff7a;
  margin: 0;
}

.notice {
  max-width: 720px;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: #f3c76b;
  text-align: center;
}

.notice code {
  font-size: 0.95em;
}

/* ---------- 非対応ブラウザ向けフォールバック（CSS のみの簡易 CRT） ---------- */

.fallback-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 14px / 18px;
  overflow: hidden;
  background: #000;
}

.fallback-screen .screen {
  --fg: #3dff7a;
  --fg-dim: #1f9c48;
  --fg-hi: #b8ffcc;
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  /* 640px の画面をコンテナ幅に合わせて拡縮する（--k は JS が設定） */
  transform: scale(var(--k, 0.5));
  text-shadow: 0 0 6px currentColor;
}

.fallback-screen .screen img {
  filter: sepia(1) hue-rotate(70deg) saturate(4) brightness(0.9);
}

.fallback-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.9);
}

.fallback .panel {
  display: none;
}
