:root {
  color-scheme: dark;
  font-family: ui-monospace, "Hiragino Kaku Gothic ProN", "Hiragino Sans", monospace;
  background: #141112;
  color: #f4eedb;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 25%, #2b2324 0%, #110e0f 85%);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pv-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #040814;
  display: none;
  z-index: 4;
}

.pv-video.is-playing {
  display: block;
}

.console-room {
  max-width: 980px;
  min-height: 100dvh;
  margin: auto;
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* ブラウン管テレビ筐体 */
.crt-tv {
  width: 100%;
  max-width: clamp(320px, calc((100dvh - 265px) * 1.25), 760px);
  background: linear-gradient(180deg, #3c3735 0%, #272322 100%);
  border: 3px solid #57504c;
  border-radius: 18px;
  padding: 10px 14px 8px;
  box-shadow: 0 20px 45px #00000099, inset 0 2px 4px #ffffff24;
}

.crt-bezel {
  background: #101012;
  border-radius: 14px;
  padding: 8px;
  border: 3px solid #1e1c1b;
  box-shadow: inset 0 4px 14px #000000;
}

.crt-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: #143347;
  box-shadow: inset 0 0 24px #000000cc;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: grab;
  touch-action: none;
}

canvas:active {
  cursor: grabbing;
}

/* 走査線＆ブラウン管四隅ビネット */
.crt-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0) 0px,
      rgba(0, 0, 0, 0) 2px,
      rgba(0, 0, 0, 0.11) 3px,
      rgba(0, 0, 0, 0.11) 4px
    ),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 68%, rgba(0, 0, 0, 0.34) 100%);
}

.crt-screen.crt-off::after {
  display: none;
}

/* ファミコンRPG風ウィンドウ */
.fc-hud,
.fc-msgbox {
  position: absolute;
  background: #070b14eb;
  border: 2px solid #f4f2e8;
  box-shadow: inset 0 0 0 2px #070b14, 0 2px 8px #000000aa;
  pointer-events: none;
  z-index: 2;
}

.fc-hud {
  top: 8px;
  left: 8px;
  max-width: calc(100% - 172px);
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 7px;
  font-size: clamp(9.5px, 1.3vw, 11.5px);
  font-weight: 700;
  color: #fff6cf;
}

.fc-hud.is-visible {
  display: flex;
}

.fc-view-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  background: #070b14d9;
  border: 1px solid #8aa0bc;
  font-size: clamp(9px, 1.15vw, 10.5px);
  color: #b8d3ee;
  pointer-events: none;
  z-index: 2;
}

.fc-view-tag.is-visible {
  display: flex;
}

.fc-msgbox {
  display: none;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 6px 10px;
  font-size: clamp(11px, 1.5vw, 13.5px);
  line-height: 1.45;
  color: #ffffff;
}

.fc-msgbox.is-visible {
  display: block;
}

#msg-line1 {
  color: #ffe885;
  font-weight: 700;
}

.tv-panel {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.tv-brand {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: #bdb3aa;
  font-weight: 700;
}

.tv-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tv-buttons button {
  font: inherit;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #6b635e;
  background: #1d1a19;
  color: #ece4d0;
  cursor: pointer;
}

.tv-buttons .tv-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: 999px;
  border-color: #5c544f;
  background: #181514;
  color: #a89f96;
  transition: border-color 0.16s, background 0.16s, color 0.16s;
}

.tv-buttons .tv-toggle.is-on {
  border-color: #6bc47c;
  background: #14261a;
  color: #f6f1db;
}

.toggle-name {
  font-weight: 700;
  font-size: 10.5px;
}

.toggle-track {
  position: relative;
  width: 24px;
  height: 13px;
  border-radius: 999px;
  background: #2f2a28;
  border: 1px solid #645c56;
  transition: background 0.16s, border-color 0.16s;
}

.tv-toggle.is-on .toggle-track {
  background: #2fa659;
  border-color: #7ee89d;
}

.toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9f968d;
  transition: transform 0.16s, background 0.16s;
}

.tv-toggle.is-on .toggle-thumb {
  transform: translateX(11px);
  background: #fff9db;
}

.toggle-state {
  min-width: 22px;
  text-align: left;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #8f867d;
}

.tv-toggle.is-on .toggle-state {
  color: #8cf2a7;
}

.tv-buttons button[aria-pressed="true"] {
  border-color: #d6c57a;
  color: #ffe98a;
}

.tv-buttons button:disabled {
  opacity: 0.45;
  cursor: default;
}

.tv-led {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 9px;
  color: #a69c93;
}

.led-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff3b30;
  box-shadow: 0 0 8px #ff3b30;
}

/* ファミコン風 I コントローラー */
.fc-controller {
  width: 100%;
  max-width: clamp(320px, calc((100dvh - 265px) * 1.25), 760px);
  background: linear-gradient(180deg, #ede5d1 0%, #dcd1b8 100%);
  border: 4px solid #721d24;
  box-shadow: inset 0 0 0 8px #86212a, 0 12px 26px #00000088;
  border-radius: 10px;
  padding: 10px 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  color: #2b1d1c;
}

.pad-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 36px);
}

.dpad-btn {
  border: 2px solid #090a0d;
  background: #23262e;
  color: #c8ced8;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn:active {
  background: #3b404d;
  transform: scale(0.95);
}

.dpad-btn:disabled,
.cam-strip button:disabled {
  opacity: 0.45;
  cursor: default;
}

.d-up { grid-column: 2; grid-row: 1; border-radius: 5px 5px 0 0; }
.d-left { grid-column: 1; grid-row: 2; border-radius: 5px 0 0 5px; }
.dpad-center { grid-column: 2; grid-row: 2; background: #1d2027; border: 1px solid #090a0d; }
.d-right { grid-column: 3; grid-row: 2; border-radius: 0 5px 5px 0; }
.d-down { grid-column: 2; grid-row: 3; border-radius: 0 0 5px 5px; }

.cam-strip {
  display: flex;
  gap: 5px;
}

.cam-strip button {
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border: 2px solid #2b2321;
  background: #cbbd9f;
  color: #1f1918;
  border-radius: 4px;
  cursor: pointer;
}

.cam-strip button[aria-pressed="true"] {
  background: #86212a;
  color: #fff3cf;
}

.pad-center {
  text-align: center;
  padding: 0 6px;
}

.pad-plate {
  display: inline-block;
  padding: 4px 12px;
  background: #86212a;
  color: #f6e7c1;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  border: 2px solid #c9a75c;
  border-radius: 3px;
}

.pad-hint {
  margin: 7px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: #4b2323;
  font-weight: 700;
}

.ab-group {
  display: flex;
  gap: 16px;
  align-items: center;
}

.ab-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.fc-round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #2a1414;
  background: radial-gradient(circle at 35% 30%, #ef4b42 0%, #b31b1b 75%);
  color: #fff6e0;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 4px 0 #1f0d0d, inset 0 2px 4px #ffffff55;
  cursor: pointer;
}

.fc-round:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #1f0d0d;
}

.ab-label {
  font-size: 11px;
  font-weight: 800;
  color: #721d24;
}

@media (max-width: 600px) {
  .console-room {
    padding: 8px 6px calc(14px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  .crt-tv {
    padding: 8px 8px 8px;
    border-radius: 12px;
  }
  .crt-bezel {
    padding: 6px;
  }
  .fc-hud {
    top: 6px;
    left: 6px;
    max-width: calc(100% - 12px);
    padding: 3px 6px;
    gap: 5px;
    font-size: 9px;
  }
  .fc-view-tag {
    top: 38px;
    right: 6px;
    padding: 2px 5px;
    font-size: 8.5px;
  }
  .fc-msgbox {
    left: 6px;
    right: 6px;
    bottom: 6px;
    padding: 4px 8px;
    font-size: 10px;
  }
  .fc-controller {
    grid-template-columns: 1fr 1fr;
    padding: 12px 12px;
    gap: 8px;
  }
  .pad-center {
    grid-column: 1 / -1;
    order: -1;
    padding: 0;
  }
  .pad-hint {
    display: none;
  }
  .dpad {
    grid-template-columns: repeat(3, 34px);
    grid-template-rows: repeat(3, 34px);
  }
  .fc-round {
    width: 52px;
    height: 52px;
    font-size: 18px;
  }
  .ab-group {
    gap: 12px;
  }
}
