:root {
  color-scheme: dark;
  --bg: #07111d;
  --panel: rgba(12, 27, 43, 0.94);
  --panel-2: rgba(18, 40, 61, 0.96);
  --line: rgba(160, 205, 235, 0.18);
  --text: #eef8ff;
  --muted: #9db5c7;
  --accent: #61e6b2;
  --accent-2: #72b7ff;
  --danger: #ff6b7a;
  --warning: #ffd166;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(57, 129, 173, 0.25), transparent 34rem),
    radial-gradient(circle at 90% 80%, rgba(38, 155, 112, 0.18), transparent 30rem),
    linear-gradient(135deg, #06101b, #0a1c2b 58%, #07131f);
}

button,
input {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(43, 76, 100, 0.9), rgba(23, 48, 67, 0.95));
  transition: transform 120ms ease, border-color 120ms ease, filter 120ms ease;
}

button:hover,
.file-button:hover {
  border-color: rgba(97, 230, 178, 0.7);
  filter: brightness(1.1);
  transform: translateY(-1px);
}

button:active,
.file-button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 18px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  letter-spacing: 0.04em;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

h2 {
  margin-bottom: 14px;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.secondary-button,
.primary-button,
.file-button {
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  min-width: 160px;
  background: linear-gradient(135deg, #16a66f, #287e8f);
  border-color: rgba(97, 230, 178, 0.55);
}

.file-button input {
  display: none;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(260px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.game-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #06101a;
  box-shadow: var(--shadow);
  aspect-ratio: 4 / 3;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.sidebar {
  display: grid;
  gap: 12px;
}

.panel {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}

.compact-panel p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.compact-panel p:last-child {
  margin-bottom: 0;
}

.panel-title-row,
.status-line,
.typing-meta,
.battle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.level-badge,
.enemy-level {
  padding: 5px 10px;
  border: 1px solid rgba(97, 230, 178, 0.4);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(97, 230, 178, 0.08);
  font-weight: 800;
}

.status-block {
  margin-top: 13px;
}

.status-line {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.status-line strong {
  color: var(--text);
}

.gauge,
.timer-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
}

.gauge-fill,
.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transition: width 180ms ease;
}

.hp-gauge {
  background: linear-gradient(90deg, #2ecb8d, #7df0bc);
}

.mp-gauge {
  background: linear-gradient(90deg, #3d81ff, #7ac5ff);
}

.exp-gauge {
  background: linear-gradient(90deg, #c776ff, #ffd166);
}

.enemy-gauge {
  background: linear-gradient(90deg, #ff4d68, #ff9a66);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 15px;
}

.stats-grid div {
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.stats-grid span,
.stats-grid strong {
  display: block;
}

.stats-grid span {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.stats-grid strong {
  font-size: 1.05rem;
}

.controls-list {
  display: grid;
  gap: 9px;
  margin: 0;
}

.controls-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.controls-list dt {
  color: var(--muted);
}

.controls-list dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.location-text {
  margin-bottom: 4px;
  font-family: Consolas, monospace;
}

.terrain-text {
  margin-bottom: 0;
  color: var(--accent);
  font-weight: 800;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 8, 14, 0.78);
  backdrop-filter: blur(6px);
}

.hidden {
  display: none !important;
}

.battle-card,
.result-card {
  width: min(540px, 100%);
  padding: 22px;
  border: 1px solid rgba(125, 203, 255, 0.25);
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(18, 42, 63, 0.98), rgba(8, 22, 35, 0.98));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
}

.result-card {
  text-align: center;
}

.result-card p {
  color: var(--muted);
  line-height: 1.7;
}

.enemy-status {
  margin: 15px 0;
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.element-info {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.battle-log {
  min-height: 58px;
  margin-bottom: 14px;
  padding: 12px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  color: #dceaf3;
  background: rgba(0, 0, 0, 0.18);
  line-height: 1.55;
}

.command-grid,
.magic-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.command-grid button,
.magic-grid button {
  min-height: 54px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 800;
}

.command-grid kbd {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.25);
}

.magic-grid small {
  display: block;
  color: var(--muted);
  font-weight: 600;
}

.wide-button {
  grid-column: 1 / -1;
}


.magic-grid button {
  position: relative;
}

.magic-grid button > kbd {
  position: absolute;
  top: 8px;
  left: 9px;
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.25);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.76rem;
  line-height: 1;
}

.magic-grid button:not(.wide-button) {
  padding-left: 38px;
}

.magic-grid .wide-button > kbd {
  position: static;
  display: inline-grid;
  margin-right: 6px;
  vertical-align: middle;
}

.typing-panel {
  padding-top: 2px;
}

.typing-meta {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.85rem;
}

.timer-track {
  height: 8px;
}

.timer-fill {
  background: linear-gradient(90deg, #ff6b7a, #ffd166, #61e6b2);
}

.typing-romaji {
  min-height: 30px;
  margin: -3px 0 10px;
  padding: 0 8px;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.055em;
  line-height: 1.55;
  overflow-wrap: anywhere;
  text-align: center;
}

.romaji-correct {
  color: #ff4f64;
}

.romaji-current {
  text-decoration: underline;
  text-decoration-color: rgba(255, 79, 100, 0.55);
  text-underline-offset: 3px;
}

.typing-phrase {
  min-height: 52px;
  margin: 16px 0 10px;
  padding: 12px;
  border-radius: 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: clamp(1.05rem, 3vw, 1.45rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
}

#typingInput {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(114, 183, 255, 0.45);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: rgba(3, 13, 22, 0.9);
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.08rem;
}

#typingInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(97, 230, 178, 0.12);
}

.typing-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px 26px;
  padding: 16px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}


/* ------------------------------
   スタート画面：タイピング言語選択
------------------------------ */
.language-card {
  width: min(660px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid rgba(125, 203, 255, 0.28);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(18, 42, 63, 0.99), rgba(8, 22, 35, 0.99));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.language-card h2 {
  margin-bottom: 10px;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
}

.language-description {
  max-width: 580px;
  margin: 0 auto 22px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.75;
}

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

.language-option {
  position: relative;
  min-height: 142px;
  padding: 22px 44px 22px 20px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  border: 2px solid rgba(125, 203, 255, 0.28);
  border-radius: 16px;
  cursor: pointer;
  text-align: left;
  background:
    linear-gradient(145deg, rgba(43, 76, 100, 0.98), rgba(20, 45, 65, 0.98));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.language-option:hover {
  border-color: var(--accent);
  background:
    linear-gradient(145deg, rgba(44, 94, 102, 0.98), rgba(22, 59, 70, 0.98));
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.3);
  transform: translateY(-3px);
}

.language-option:focus-visible {
  border-color: var(--accent);
  outline: 3px solid rgba(97, 230, 178, 0.32);
  outline-offset: 3px;
}

.language-option:active {
  transform: translateY(0);
}

.language-option-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(97, 230, 178, 0.5);
  border-radius: 50%;
  color: var(--accent);
  background: rgba(97, 230, 178, 0.1);
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1;
}

.language-option-content {
  display: block;
  min-width: 0;
}

.language-option-content strong,
.language-option-content small {
  display: block;
}

.language-option-content strong {
  margin-bottom: 7px;
  color: var(--text);
  font-size: clamp(1.2rem, 3vw, 1.45rem);
  line-height: 1.2;
}

.language-option-content small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.45;
}

.language-shortcut {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 7px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.85rem;
}

.language-key-help {
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.language-key-help kbd {
  display: inline-grid;
  place-items: center;
  min-width: 23px;
  height: 23px;
  margin: 0 2px;
  padding: 0 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.22);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.78rem;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  .game-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .back-button {
    position: static;
    margin: 0 0 10px;
  }

  .back-button a {
    align-items: center;
    gap: 7px;
    font-size: 2.5rem;
  }
  
  .back-button > * {
    flex: 1;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions > * {
    flex: 1;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .overlay {
    padding: 10px;
  }

  .language-card {
    padding: 20px 16px;
  }

  .language-grid {
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .language-option {
    min-height: 100px;
    padding: 15px 42px 15px 15px;
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 13px;
  }

  .language-option-icon {
    width: 50px;
    height: 50px;
    font-size: 1.45rem;
  }

  .language-option-content strong {
    margin-bottom: 4px;
  }

  .language-key-help {
    margin-top: 13px;
  }

  .battle-card,
  .result-card {
    padding: 16px;
  }
}
