:root {
  color: #f6fbff;
  background: #08111d;
  --screen-background: url("/game-typing2-assets/map.jpg");
  --battle-background: url("/game-typing2-assets/forest.jpg");
  font-family: Inter, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(4, 9, 16, .28), rgba(4, 9, 16, .78)),
    var(--screen-background) center / cover fixed no-repeat;
  transition: background-image .28s ease;
}

body[data-scene="map"] {
  --screen-background: url("/game-typing2-assets/map.jpg");
  --battle-background: url("/game-typing2-assets/ice.jpg");
}

body[data-scene="ice"] {
  --screen-background: url("/game-typing2-assets/ice.jpg");
  --battle-background: url("/game-typing2-assets/ice.jpg");
}

body[data-scene="forest"] {
  --screen-background: url("/game-typing2-assets/forest.jpg");
  --battle-background: url("/game-typing2-assets/forest.jpg");
}

body[data-scene="desert"] {
  --screen-background: url("/game-typing2-assets/desert.jpg");
  --battle-background: url("/game-typing2-assets/desert.jpg");
}

body[data-scene="volcano"] {
  --screen-background: url("/game-typing2-assets/volcano.jpg");
  --battle-background: url("/game-typing2-assets/volcano.jpg");
}

body[data-scene="castle"] {
  --screen-background: url("/game-typing2-assets/castle.jpg");
  --battle-background: url("/game-typing2-assets/castle.jpg");
}

body::before {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 64px 64px;
  mix-blend-mode: screen;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.quest-shell {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 32px;
}

.map-screen,
.settings-screen,
.play-screen {
  min-height: calc(100vh - 54px);
}

.map-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 8px 0 18px;
}

.map-header p,
h1,
p {
  margin: 0;
  letter-spacing: 0;
}

.map-header p {
  color: #ffe08a;
  font-weight: 900;
}

h1 {
  margin-top: 4px;
  font-size: clamp(2rem, 5.4vw, 5rem);
  line-height: 1.02;
  text-shadow: 0 12px 28px rgba(0, 0, 0, .48);
}

.nav-link,
.map-header button,
.actions button,
#backToMapButton,
.settings-header button,
#applySettingsButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid rgba(255, 224, 138, .34);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffe08a, #f2a833);
  box-shadow: 0 16px 30px rgba(0, 0, 0, .28), inset 0 -3px 0 rgba(101, 55, 8, .3);
  color: #17202a;
  font-weight: 1000;
  text-decoration: none;
}

.nav-link,
#backToMapButton,
.actions button + button {
  background: rgba(8, 17, 29, .72);
  color: #f6fbff;
  backdrop-filter: blur(12px);
}

.map-board {
  position: relative;
  aspect-ratio: 1676 / 939;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .04), rgba(0, 0, 0, .34)),
    url("/game-typing2-assets/map.jpg") center / 100% 100% no-repeat;
  box-shadow: 0 26px 80px rgba(0, 0, 0, .34);
}

.route-line {
  display: none;
}

.map-nodes {
  position: absolute;
  inset: 0;
}

.stage-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(48px, 7vw, 74px);
  aspect-ratio: 1;
  border: 4px solid #ffc857;
  border-radius: 50%;
  background: radial-gradient(circle, #24313c 0 54%, #0c131b 55%);
  box-shadow: 0 0 0 4px rgba(68, 40, 6, .8), 0 0 24px rgba(255, 199, 87, .74);
  color: #ffe08a;
  font-weight: 1000;
  transform: translate(-50%, -50%);
}

.stage-node span {
  display: grid;
  place-items: center;
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
}

.stage-node img {
  position: absolute;
  left: 50%;
  bottom: 54%;
  z-index: 1;
  width: clamp(66px, 10vw, 128px);
  max-height: 132px;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 12px 12px rgba(0, 0, 0, .58));
  transform: translateX(-50%);
  pointer-events: none;
}

.stage-node.active {
  border-color: #7cffb9;
  box-shadow: 0 0 0 5px rgba(23, 76, 49, .8), 0 0 34px rgba(124, 255, 185, .9);
  animation: pulse 1.6s ease-in-out infinite;
}

.stage-node.active img {
  animation: map-enemy-float 1.8s ease-in-out infinite;
}

.stage-node.done {
  border-color: #a7f3d0;
  color: #a7f3d0;
}

.stage-node.locked {
  filter: grayscale(.65) brightness(.75);
}

.map-card,
.hero-panel,
.battle-panel,
.settings-panel {
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(8, 17, 29, .84), rgba(23, 36, 45, .72));
  box-shadow: 0 22px 70px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .09);
  backdrop-filter: blur(14px);
}

.map-card {
  position: absolute;
  right: 22px;
  bottom: 22px;
  width: min(360px, calc(100% - 44px));
  padding: 18px;
}

.map-card strong,
.quest-status strong {
  display: block;
  color: #ffe08a;
  font-size: 1.2rem;
}

.map-card span,
.quest-status p,
.typing-hint {
  display: block;
  margin-top: 8px;
  color: #cce4f1;
  line-height: 1.7;
}

.settings-screen[hidden],
.play-screen[hidden] {
  display: none;
}

.settings-screen {
  display: grid;
  align-content: center;
  gap: 18px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.settings-header p {
  margin: 0 0 6px;
  color: #ffe08a;
  font-weight: 900;
}

.settings-header h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 1.05;
}

.settings-panel {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 4vw, 32px);
}

.quest-count-field {
  display: grid;
  gap: 8px;
  color: #ffe08a;
  font-weight: 900;
}

.quest-count-field select {
  min-height: 52px;
  border: 1px solid rgba(255, 224, 138, .42);
  border-radius: 8px;
  background: rgba(8, 17, 29, .72);
  color: #f6fbff;
  padding: 0 14px;
  font: inherit;
  font-weight: 900;
}

.play-screen {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.hero-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.character-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 330px;
  border: 2px solid rgba(255, 224, 138, .5);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 36%, rgba(124, 255, 185, .32), transparent 36%),
    linear-gradient(180deg, rgba(255, 224, 138, .14), rgba(8, 17, 29, .78)),
    rgba(8, 17, 29, .45);
  overflow: hidden;
}

.ally-frame {
  min-height: 222px;
}

.character-frame::before {
  position: absolute;
  inset: 14px;
  content: "";
  border: 1px solid rgba(255, 224, 138, .28);
  border-radius: 8px;
  pointer-events: none;
}

.character-frame img {
  width: min(108%, 250px);
  height: auto;
  max-height: 94%;
  object-fit: contain;
  filter: drop-shadow(0 18px 22px rgba(0, 0, 0, .42));
  transform-origin: 50% 80%;
  animation: dragon-breathe 2.4s ease-in-out infinite;
}

.character-frame strong {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 1;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .46);
  color: #7cffb9;
  font-size: .95rem;
  text-align: center;
}

.quest-status {
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
}

.battle-panel {
  padding: clamp(16px, 3vw, 28px);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.hud div {
  min-height: 82px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  background: rgba(0, 0, 0, .28);
}

.hud span {
  display: block;
  color: #a9c4d1;
  font-size: .78rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.25rem, 3vw, 2.2rem);
}

.course-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.course {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  color: #f6fbff;
  font-weight: 900;
}

.course.active {
  border-color: #ffe08a;
  color: #17202a;
  background: #ffe08a;
}

.typing-card {
  margin-top: 18px;
  padding: clamp(16px, 3vw, 24px);
  border: 1px solid rgba(255, 224, 138, .26);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(8, 17, 29, .72), rgba(28, 45, 55, .56)),
    var(--battle-background) center / cover no-repeat;
  box-shadow: inset 0 0 0 999px rgba(4, 9, 16, .52);
}

.battle-row {
  display: grid;
  grid-template-columns: minmax(132px, 190px) minmax(0, 1fr) minmax(132px, 220px);
  gap: 16px;
  align-items: stretch;
}

.enemy-frame {
  position: relative;
  display: grid;
  min-height: 222px;
  padding: 16px;
  place-items: center;
  overflow: hidden;
  border: 2px solid rgba(255, 104, 104, .52);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 104, 104, .44), transparent 42%),
    linear-gradient(180deg, rgba(42, 10, 18, .86), rgba(5, 9, 18, .78));
  box-shadow: inset 0 0 24px rgba(255, 104, 104, .18), 0 18px 40px rgba(0, 0, 0, .28);
}

.enemy-frame::before,
.enemy-frame::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.enemy-frame::before {
  width: 96px;
  aspect-ratio: 1;
  border-radius: 50% 50% 42% 42%;
  background: linear-gradient(145deg, #ff6868, #5b1020);
  box-shadow: 0 16px 0 -6px rgba(255, 224, 138, .8), 0 22px 28px rgba(0, 0, 0, .34);
  animation: enemy-float 1.8s ease-in-out infinite;
}

.enemy-frame::after {
  top: 55px;
  width: 130px;
  height: 38px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 33% 50%, #ffe08a 0 7px, transparent 8px),
    radial-gradient(circle at 67% 50%, #ffe08a 0 7px, transparent 8px);
  animation: enemy-float 1.8s ease-in-out infinite;
}

.enemy-frame[data-enemy="ice"] {
  border-color: rgba(142, 216, 255, .62);
  background:
    radial-gradient(circle at 50% 34%, rgba(142, 216, 255, .5), transparent 42%),
    linear-gradient(180deg, rgba(9, 32, 56, .86), rgba(5, 9, 18, .78));
}

.enemy-frame[data-enemy="desert"] {
  border-color: rgba(255, 207, 112, .62);
}

.enemy-frame[data-enemy="volcano"],
.enemy-frame[data-enemy="castle"] {
  border-color: rgba(255, 138, 61, .7);
}

.enemy-frame.has-image::before,
.enemy-frame.has-image::after {
  display: none;
}

.enemy-frame img {
  position: relative;
  z-index: 1;
  display: block;
  width: min(112%, 260px);
  max-height: 178px;
  object-fit: contain;
  filter: drop-shadow(0 18px 20px rgba(0, 0, 0, .44));
  animation: enemy-float 1.8s ease-in-out infinite;
}

.enemy-frame img[hidden] {
  display: none;
}

.enemy-frame span {
  position: relative;
  z-index: 1;
  display: grid;
  width: 62px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  background: rgba(8, 17, 29, .64);
  color: #ffffff;
  font-size: 1.8rem;
  font-weight: 1000;
}

.enemy-frame.has-image span {
  display: none;
}

.enemy-frame strong {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 1;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .46);
  color: #ffe08a;
  font-size: .95rem;
  text-align: center;
}

.target-area {
  min-width: 0;
}

body[data-scene="forest"] .typing-card {
  box-shadow: inset 0 0 0 999px rgba(4, 24, 20, .48);
}

body[data-scene="desert"] .typing-card {
  box-shadow: inset 0 0 0 999px rgba(55, 26, 6, .42);
}

body[data-scene="ice"] .typing-card {
  box-shadow: inset 0 0 0 999px rgba(4, 20, 42, .44);
}

body[data-scene="volcano"] .typing-card {
  box-shadow: inset 0 0 0 999px rgba(36, 10, 10, .5);
}

body[data-scene="castle"] .typing-card {
  box-shadow: inset 0 0 0 999px rgba(18, 8, 34, .52);
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7cffb9, #ffe08a, #ff8a3d);
  transition: width .22s ease;
}

.target-label {
  color: #7cffb9;
  font-weight: 1000;
}

.target-text {
  min-height: 104px;
  margin-top: 12px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  background: rgba(0, 0, 0, .44);
  color: #ffffff;
  font-size: clamp(1.4rem, 4vw, 2.75rem);
  font-weight: 1000;
  line-height: 1.34;
  overflow-wrap: anywhere;
  text-shadow: 0 8px 18px rgba(0, 0, 0, .45);
}

.typing-focus {
  display: grid;
  grid-template-columns: auto 76px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 224, 138, .36);
  border-radius: 8px;
  background: rgba(0, 0, 0, .5);
}

.typing-focus span,
.typing-focus em {
  color: #d8ecf5;
  font-style: normal;
  font-weight: 900;
}

.typing-focus strong {
  display: grid;
  min-height: 56px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffe08a, #f2a833);
  color: #17202a;
  font-size: 2rem;
  font-weight: 1000;
  box-shadow: 0 0 24px rgba(255, 224, 138, .5), inset 0 -4px 0 rgba(101, 55, 8, .22);
}

.romaji-guide {
  display: flex;
  min-height: 68px;
  margin-top: 12px;
  padding: 12px 14px;
  flex-wrap: wrap;
  gap: 4px;
  border: 1px solid rgba(124, 255, 185, .26);
  border-radius: 8px;
  background: rgba(0, 0, 0, .42);
  color: #d8ecf5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1rem, 2.6vw, 1.45rem);
  font-weight: 900;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.romaji-guide span {
  display: inline-grid;
  min-width: 1.16em;
  min-height: 1.55em;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, .08);
}

.romaji-guide .typed {
  background: rgba(124, 255, 185, .18);
  color: #7cffb9;
}

.romaji-guide .current {
  background: #ffe08a;
  color: #17202a;
  transform: translateY(-4px);
  box-shadow: 0 0 18px rgba(255, 224, 138, .62);
}

.romaji-guide .expected {
  border: 2px solid #ffe08a;
  background: rgba(255, 224, 138, .18);
  color: #ffe08a;
}

.romaji-guide .wrong {
  border: 2px solid #ff6868;
  background: rgba(255, 104, 104, .22);
  color: #ffd7d7;
  text-decoration: line-through;
}

#typingInput {
  width: 100%;
  min-height: 58px;
  margin-top: 16px;
  padding: 0 16px;
  border: 2px solid rgba(124, 255, 185, .48);
  border-radius: 8px;
  outline: none;
  background: rgba(255, 255, 255, .96);
  color: #17202a;
  font-size: 1.08rem;
  font-weight: 900;
  text-transform: lowercase;
}

#typingInput:focus {
  border-color: #ffe08a;
}

#typingInput.mistake {
  border-color: #ff6868;
  animation: shake .16s linear;
}

.keyboard {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  background: rgba(0, 0, 0, .34);
}

.key-row {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1vw, 9px);
}

.key {
  display: grid;
  width: clamp(26px, 5.8vw, 48px);
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .06));
  color: #eaf7ff;
  font-weight: 1000;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .24);
}

.key.active {
  border-color: #ffe08a;
  background: linear-gradient(180deg, #ffe08a, #f2a833);
  color: #17202a;
  transform: translateY(-4px);
  box-shadow: 0 0 22px rgba(255, 224, 138, .65), inset 0 -4px 0 rgba(101, 55, 8, .24);
}

.key.fix {
  border-color: #ff6868;
  background: linear-gradient(180deg, #ff9b9b, #ff6868);
  box-shadow: 0 0 22px rgba(255, 104, 104, .7), inset 0 -4px 0 rgba(101, 8, 8, .24);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

#resultText {
  color: #ffe08a;
  font-weight: 900;
}

@keyframes pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.08); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(7px); }
}

@keyframes dragon-breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.025); }
}

@keyframes enemy-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes map-enemy-float {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -8px); }
}

@media (max-width: 900px) {
  .map-header,
  .play-screen,
  .hud,
  .course-row,
  .battle-row {
    grid-template-columns: 1fr;
  }

  .map-header button,
  .nav-link {
    width: fit-content;
  }

  .map-board {
    min-height: 430px;
  }

  .hero-panel {
    min-height: auto;
  }

  .character-frame {
    min-height: 220px;
  }

  .typing-focus {
    grid-template-columns: 1fr;
  }

  .typing-focus strong {
    width: 76px;
  }
}
