/* ─── Base ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #0a0a0a;
  color: #00ff41;
  font-family: 'Courier New', Courier, monospace;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

/* ─── Matrix Canvas ─── */
#matrix-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  transition: opacity 0.3s ease;
}

body.game-active #matrix-canvas,
body.title-active #matrix-canvas,
body.difficulty-active #matrix-canvas {
  opacity: 0.3;
}

/* ─── Game Container ─── */
#game-container {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100vh;
}

/* ─── Screen Base ─── */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 2rem;
}

.screen.active {
  display: flex;
}

/* ─── Title Screen ─── */
.title-glow {
  font-size: 4rem;
  color: #00ff41;
  text-shadow:
    0 0 10px #00ff41,
    0 0 20px #00ff41,
    0 0 40px #00cc33,
    0 0 80px #009922;
  letter-spacing: 0.3em;
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 1.2rem;
  color: #00cc33;
  margin-bottom: 3rem;
  letter-spacing: 0.15em;
}

/* ─── Buttons ─── */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.btn-matrix {
  background: transparent;
  color: #00ff41;
  border: 2px solid #00ff41;
  padding: 0.8rem 3rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all 0.3s ease;
  min-width: 200px;
}

.btn-matrix:hover {
  background: rgba(0, 255, 65, 0.15);
  box-shadow:
    0 0 10px #00ff41,
    0 0 20px rgba(0, 255, 65, 0.3);
  text-shadow: 0 0 10px #00ff41;
}

.btn-matrix:active {
  background: rgba(0, 255, 65, 0.3);
}

/* ─── HUD ─── */
#hud {
  position: absolute;
  top: 1.5rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  font-size: 1.2rem;
  color: #00cc33;
  text-shadow: 0 0 5px #00ff41;
}

/* ─── Question Area ─── */
#question-area {
  text-align: center;
}

.question-text {
  font-size: 2.5rem;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  margin-bottom: 1.5rem;
}

#question-romaji {
  font-size: 2rem;
  letter-spacing: 0.1em;
}

.typed {
  color: #00ff41;
  text-shadow: 0 0 10px #00ff41;
}

.remaining {
  color: #5a9a5a;
  text-shadow: none;
}

/* ─── Countdown ─── */
#countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10;
}

#countdown-overlay.hidden {
  display: none;
}

#countdown-number {
  font-size: 8rem;
  color: #00ff41;
  text-shadow:
    0 0 20px #00ff41,
    0 0 40px #00ff41,
    0 0 80px #00cc33;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.8; }
}

/* ─── Result Screen ─── */
.result-title {
  font-size: 3rem;
  color: #00ff41;
  text-shadow: 0 0 20px #00ff41;
  margin-bottom: 2rem;
  letter-spacing: 0.3em;
}

#result-stats {
  font-size: 1.3rem;
  line-height: 2.2;
  margin-bottom: 2rem;
  text-align: left;
}

#result-stats span {
  color: #ffffff;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

/* ─── Settings Screen ─── */
.settings-title {
  font-size: 2.5rem;
  color: #00ff41;
  text-shadow: 0 0 15px #00ff41;
  margin-bottom: 2rem;
  letter-spacing: 0.3em;
}

#settings-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 2rem;
  min-width: 300px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.setting-item label {
  font-size: 1.1rem;
  color: #00cc33;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 6px;
  background: #0a4a0a;
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #00ff41;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px #00ff41;
}

input[type="checkbox"] {
  accent-color: #00ff41;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ─── BEM Screen Components (UI classes) ─── */

/* Common text styles */
.matrix-glow {
  color: #00ff41;
  text-shadow:
    0 0 10px #00ff41,
    0 0 20px #00ff41,
    0 0 40px #00cc33;
}

.matrix-text {
  color: #00cc33;
  font-family: 'Courier New', Courier, monospace;
}

.matrix-btn {
  background: transparent;
  color: #00ff41;
  border: 2px solid #00ff41;
  padding: 0.8rem 3rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all 0.3s ease;
  min-width: 200px;
}

.matrix-btn:hover {
  background: rgba(0, 255, 65, 0.15);
  box-shadow:
    0 0 10px #00ff41,
    0 0 20px rgba(0, 255, 65, 0.3);
  text-shadow: 0 0 10px #00ff41;
}

.matrix-btn:active {
  background: rgba(0, 255, 65, 0.3);
}

/* Screen base (BEM) */
.screen__title {
  font-size: 3rem;
  margin-bottom: 1.5rem;
  letter-spacing: 0.3em;
}

.screen__subtitle {
  font-size: 1.2rem;
  margin-bottom: 3rem;
  letter-spacing: 0.15em;
}

.screen__buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  margin-top: 2rem;
}

.screen__button {
  background: transparent;
  color: #00ff41;
  border: 2px solid #00ff41;
  padding: 0.8rem 3rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all 0.3s ease;
  min-width: 200px;
}

.screen__button:hover {
  background: rgba(0, 255, 65, 0.15);
  box-shadow:
    0 0 10px #00ff41,
    0 0 20px rgba(0, 255, 65, 0.3);
  text-shadow: 0 0 10px #00ff41;
}

.screen__button:active {
  background: rgba(0, 255, 65, 0.3);
}

.result-screen .screen__buttons {
  background: rgba(0, 0, 0, 0.5);
  padding: 1.5rem 2rem;
  border-radius: 8px;
}

.result-screen .screen__button {
  text-shadow: 0 0 8px #00ff41;
  box-shadow: 0 0 5px rgba(0, 255, 65, 0.2);
}

.screen__footer {
  margin-top: 2rem;
  font-size: 0.9rem;
  opacity: 0.7;
}

/* ─── Title Screen (BEM) ─── */
.title-screen .screen__title {
  font-size: 4rem;
  text-shadow:
    0 0 10px #00ff41,
    0 0 20px #00ff41,
    0 0 40px #00cc33,
    0 0 80px #009922;
}

/* ─── Game Screen (BEM) ─── */
.game-screen {
  position: relative;
}

.game-screen__top {
  position: absolute;
  top: 1.5rem;
  left: 2rem;
  right: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
}

.game-screen__timer-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.game-screen__timer-label {
  font-size: 1rem;
}

.game-screen__timer-bar-outer {
  width: 200px;
  height: 8px;
  background: #0a4a0a;
  border-radius: 4px;
  overflow: hidden;
}

.game-screen__timer-bar {
  height: 100%;
  background: #00ff41;
  border-radius: 4px;
  transition: width 1s linear;
  box-shadow: 0 0 6px #00ff41;
}

.game-screen__timer-bar--danger {
  background: #ff4141;
  box-shadow: 0 0 6px #ff4141;
  animation: timer-danger-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-danger-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.game-screen__timer-text {
  font-size: 1.6rem;
  min-width: 2em;
  text-align: right;
  font-weight: bold;
  text-shadow:
    0 0 10px #00ff41,
    0 0 20px #00ff41;
}

/* ─── Difficulty Screen (BEM) ─── */
.difficulty-screen {
  justify-content: center;
  padding-top: 0;
  min-height: 100vh;
  gap: 1rem;
}

.difficulty-screen .screen__title {
  font-size: 3.5rem;
}

.difficulty-screen__subtitle {
  font-size: 1.05rem;
  color: #00cc33;
  letter-spacing: 0.12em;
  text-align: center;
  margin-bottom: 0.5rem;
}

.difficulty-screen__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  width: min(100%, 980px);
  align-items: stretch;
}

.difficulty-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 180px;
  padding: 1.25rem 1.15rem;
  border-radius: 12px;
  border: 1px solid rgba(0, 255, 65, 0.25);
  background: rgba(0, 0, 0, 0.72);
  cursor: pointer;
  text-align: left;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease;
}

.difficulty-card:hover,
.difficulty-card:focus-visible,
.difficulty-card.focused {
  transform: translateY(-2px);
  border-color: #00ff41;
  box-shadow:
    0 0 16px rgba(0, 255, 65, 0.25),
    inset 0 0 14px rgba(0, 255, 65, 0.06);
  outline: none;
}

.difficulty-card__id {
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  opacity: 0.75;
}

.difficulty-card__label {
  font-size: 1.55rem;
  line-height: 1.2;
}

.difficulty-card__description {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #b4f3bd;
}

.difficulty-screen__footer {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #5a9a5a;
  letter-spacing: 0.12em;
  text-align: center;
}

.game-screen__score {
  font-size: 2rem;
  font-weight: bold;
}

.game-screen__question {
  text-align: center;
  margin-bottom: 1.5rem;
  background: rgba(0, 0, 0, 0.75);
  padding: 1.5rem 2.5rem;
  border-radius: 8px;
}

.game-screen__question-image {
  max-width: 200px;
  max-height: 150px;
  margin-bottom: 1rem;
  border: 2px solid #00ff4140;
  border-radius: 8px;
  image-rendering: pixelated;
}

.game-screen__question-text {
  font-size: 3rem;
  color: #ffffff;
  font-weight: bold;
  text-shadow:
    0 0 10px rgba(255, 255, 255, 0.8),
    0 0 20px rgba(255, 255, 255, 0.4),
    0 0 40px rgba(0, 255, 65, 0.2);
}

.game-screen__typing {
  font-size: 2.2rem;
  letter-spacing: 0.15em;
  text-align: center;
  background: rgba(0, 0, 0, 0.75);
  padding: 1rem 2rem;
  border-radius: 8px;
}

.game-screen__typed {
  color: #00ff41;
  text-shadow:
    0 0 10px #00ff41,
    0 0 20px #00ff41;
}

.game-screen__remaining {
  color: #5a9a5a;
  text-shadow: none;
}

.game-screen__countdown {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10;
  font-size: 8rem;
  animation: pulse 1s ease-in-out infinite;
}

/* ─── Result Screen (BEM) ─── */
.result-screen__score {
  font-size: 5rem;
  margin-bottom: 2rem;
  text-shadow:
    0 0 10px #00ff41,
    0 0 20px #00ff41,
    0 0 40px #00cc33,
    0 0 80px #009922;
}

.result-screen__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem 2.5rem;
  margin-bottom: 2rem;
  background: rgba(0, 0, 0, 0.7);
  padding: 1.5rem 2rem;
  border-radius: 8px;
}

.result-screen__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.result-screen__stat-label {
  font-size: 0.95rem;
  opacity: 1;
  color: #00cc33;
  text-shadow: 0 0 5px rgba(0, 255, 65, 0.3);
}

.result-screen__stat-value {
  font-size: 1.8rem;
  color: #ffffff;
  text-shadow:
    0 0 8px rgba(255, 255, 255, 0.7),
    0 0 16px rgba(0, 255, 65, 0.3);
}

/* ─── Settings Screen (BEM) ─── */
.settings-screen__list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 300px;
  margin-bottom: 2rem;
}

.settings-screen__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.settings-screen__label {
  font-size: 1.1rem;
}

.settings-screen__slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.settings-screen__slider {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 6px;
  background: #0a4a0a;
  border-radius: 3px;
  outline: none;
}

.settings-screen__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #00ff41;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px #00ff41;
}

.settings-screen__value {
  min-width: 3em;
  text-align: right;
}

.settings-screen__mute-btn {
  min-width: 80px;
  padding: 0.4rem 1rem;
  font-size: 1rem;
}

.settings-screen__mute-btn--active {
  background: rgba(255, 65, 65, 0.2);
  border-color: #ff4141;
  color: #ff4141;
}

/* ─── Game Menu ─── */
.game-menu__btn {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 5;
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  min-width: auto;
  opacity: 0.7;
  transition: opacity 0.3s ease, box-shadow 0.3s ease;
}

.game-menu__btn:hover {
  opacity: 1;
}

.game-menu__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-menu__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  background: rgba(0, 20, 0, 0.9);
  border: 2px solid #00ff41;
  border-radius: 12px;
  padding: 2rem 3rem;
  box-shadow:
    0 0 20px rgba(0, 255, 65, 0.3),
    0 0 40px rgba(0, 255, 65, 0.1);
  min-width: 320px;
}

.game-menu__title {
  font-size: 2.5rem;
  letter-spacing: 0.3em;
  margin-bottom: 0.5rem;
}

.game-menu__settings {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.game-menu__section-label {
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.8;
  letter-spacing: 0.2em;
  margin-bottom: 0.3rem;
}

.game-menu__setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.game-menu__label {
  font-size: 1rem;
}

.game-menu__slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.game-menu__slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  background: #0a4a0a;
  border-radius: 3px;
  outline: none;
}

.game-menu__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #00ff41;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px #00ff41;
}

.game-menu__value {
  min-width: 3em;
  text-align: right;
  font-size: 0.95rem;
}

.game-menu__mute-btn {
  min-width: 70px;
  padding: 0.3rem 0.8rem;
  font-size: 0.9rem;
}

.game-menu__mute-btn--active {
  background: rgba(255, 65, 65, 0.2);
  border-color: #ff4141;
  color: #ff4141;
}

.game-menu__actions {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
  align-items: center;
  margin-top: 0.5rem;
}

.game-menu__action-btn {
  min-width: 200px;
  padding: 0.6rem 2rem;
  font-size: 1rem;
}

.game-menu__confirm {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  z-index: 25;
  border-radius: 12px;
}

.game-menu__confirm-text {
  font-size: 1.4rem;
  text-align: center;
  text-shadow: 0 0 10px #00ff41;
}

.game-menu__confirm-btns {
  display: flex;
  gap: 1.5rem;
}

.game-menu__confirm-ok,
.game-menu__confirm-cancel {
  min-width: 100px;
  padding: 0.6rem 2rem;
  font-size: 1rem;
}

.game-menu__confirm-cancel {
  border-color: #666;
  color: #999;
}

.game-menu__confirm-cancel:hover {
  border-color: #999;
  color: #ccc;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: none;
  text-shadow: none;
}

/* ─── Utility ─── */
.hidden {
  display: none !important;
}

/* cmd_440 Phase A: お題コンテナを画面幅 90% まで拡大（画像:テキスト 50:50 維持） */
.game-screen__question {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: 90vw;
  max-width: none;
  margin-left: auto;
  margin-right: auto;
}

.game-screen__question-image {
  flex: 0 0 50%;
  max-width: 50%;
  max-height: min(70vh, 500px);
  width: auto;
  height: auto;
  object-fit: contain;
}

.game-screen__question-text {
  flex: 0 0 50%;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-align: left;
}

@media (max-width: 768px) {
  .game-screen__question {
    flex-direction: column;
    gap: 16px;
    width: 100%;
  }

  .game-screen__question-image {
    flex: 0 0 auto;
    max-width: 60vw;
    max-height: 30vh;
  }

  .game-screen__question-text {
    flex: 0 0 auto;
    text-align: center;
    font-size: 2rem;
  }
}

@media (max-width: 480px) {
  .game-screen__question-image {
    max-width: 70vw;
    max-height: 28vh;
  }
}
