:root {
  --paper: #eaffea;
  --ink: #151515;
  --mint: #99f06b;
  --mint-dark: #5ec337;
  --blue: #4d88f5;
  --blue-dark: #2a57b3;
  --panel: #ffffff;
  --line: #111111;
  --soft-shadow: 8px 8px 0 #111111;
  --radius: 20px;
  --font-ui: "Trebuchet MS", "Verdana", sans-serif;
  --font-ko: "Gaegu", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  min-height: 100%;
}

body.lang-ko {
  font-family: var(--font-ko);
}

body.lang-ko .topbar h1 {
  font-family: var(--font-ko);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-shadow: 2px 2px 0 #b6ff9d;
}

/* Force Korean mode typography across UI controls/cards/titles. */
body.lang-ko,
body.lang-ko *:not(.flag):not(.flag *) {
  font-family: var(--font-ko) !important;
}

body {
  position: relative;
  padding: 28px 16px 40px;
  overflow-x: hidden;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.5) 0,
      rgba(255, 255, 255, 0.5) 2px,
      rgba(165, 255, 165, 0.2) 2px,
      rgba(165, 255, 165, 0.2) 10px
    ),
    linear-gradient(180deg, #8fff8d 0%, #dafcd6 16%, #f7fff8 38%, #c9ecff 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  pointer-events: none;
  z-index: -1;
  border-radius: 50%;
}

body::before {
  width: 170px;
  height: 170px;
  top: -36px;
  right: -30px;
  background: radial-gradient(circle at 36% 35%, #fffde8 0%, #ffe6a5 68%, #f7cb7a 100%);
  border: 3px solid var(--line);
  animation: float-bob 5.8s ease-in-out infinite;
}

body::after {
  width: 90px;
  height: 90px;
  left: 2%;
  top: 22%;
  background: radial-gradient(circle at 40% 35%, #ffffff 0%, #c0f3ff 65%, #8fd9fb 100%);
  border: 2px solid var(--line);
  animation: float-bob 4.4s ease-in-out infinite reverse;
}

.bg-shape {
  position: fixed;
  z-index: -2;
  border: 3px solid var(--line);
  border-radius: 32px;
}

.shape-a {
  width: min(1100px, 92vw);
  height: 200px;
  left: 50%;
  transform: translateX(-50%);
  top: 110px;
  background: linear-gradient(180deg, #8fc0ff 0%, #5f97ff 100%);
  animation: card-drift 8s ease-in-out infinite;
}

.shape-b {
  width: min(1200px, 96vw);
  height: 210px;
  left: 50%;
  transform: translateX(-50%);
  bottom: -48px;
  background: linear-gradient(180deg, #8fc0ff 0%, #4f87f4 100%);
  animation: card-drift 9.5s ease-in-out infinite reverse;
}

.lang-toggle {
  width: fit-content;
  margin: 0 auto 10px;
  margin-left: max(2vw, calc((100vw - min(1120px, 96vw)) / 2));
  border: 4px solid var(--line);
  border-radius: 24px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #dff0ff 0%, #d1e4ff 100%);
  box-shadow: 5px 5px 0 #1e2f59;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.lang-pill {
  width: 54px;
  height: 44px;
  border: 3px solid #233761;
  border-radius: 16px;
  background: #f2f7ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 2px 2px 0 #22395f;
  transition: transform 0.18s ease, background 0.18s ease;
}

.lang-pill.active {
  background: linear-gradient(180deg, #b9f589 0%, #8de661 100%);
}

.lang-pill:hover {
  transform: translateY(-1px);
}

.lang-pill .flag {
  font-size: 1.2rem;
}

.lang-swap {
  font-size: 1.8rem;
  line-height: 1;
  color: #365ba1;
  text-shadow: 1px 1px 0 #fff;
}

.topbar {
  width: min(1120px, 96vw);
  margin: 0 auto 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.topbar-main {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-family: "Cooper Black", "Palatino", serif;
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  letter-spacing: 0.02em;
  text-shadow: 2px 2px 0 #b6ff9d;
}

.topbar p {
  margin: 6px 0 0;
  font-size: 1rem;
}

.api-indicator {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #eef3ff;
  color: #1e2f57;
  font-size: 0.82rem;
  font-weight: 700;
}

.api-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #f3bf4f;
  box-shadow: 0 0 0 2px rgba(243, 191, 79, 0.35);
}

.api-indicator.api-connected .api-dot {
  background: #43bf57;
  box-shadow: 0 0 0 2px rgba(67, 191, 87, 0.35);
}

.api-indicator.api-disconnected .api-dot {
  background: #e54848;
  box-shadow: 0 0 0 2px rgba(229, 72, 72, 0.35);
}

.user-panel {
  min-width: 260px;
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #ecfff2 100%);
  box-shadow: 4px 4px 0 #20365f;
}

.user-label {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: 0.9rem;
  color: #1c2d54;
}

.user-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.user-chip-wrap {
  position: relative;
  display: inline-flex;
}

.user-chip {
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: #e6ebf4;
  color: #17284b;
  font-size: 0.85rem;
}

.user-chip.active {
  background: linear-gradient(180deg, #adf082 0%, #88de5f 100%);
  color: #102305;
  font-weight: 700;
}

.user-chip-delete {
  position: absolute;
  top: -4px;
  right: -3px;
  width: 14px;
  height: 14px;
  border: 1.5px solid #5b1010;
  border-radius: 999px;
  padding: 0;
  background: #e83a3a;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 1px 1px 0 #3e0b0b;
}

.user-chip-delete:hover {
  background: #ff4d4d;
  transform: translateY(-1px);
}

.user-create-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.user-create-form input {
  padding: 7px 8px;
  border-width: 2px;
}

.user-create-form button {
  padding: 7px 10px;
  border-width: 2px;
}

.desktop-shell {
  width: min(1120px, 96vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
}

.dock {
  padding: 14px;
  border: 4px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(230, 252, 214, 0.95) 100%);
  box-shadow: var(--soft-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: start;
}

.icon-btn {
  border: 4px solid var(--line);
  border-radius: 20px;
  background: #bff2a2;
  padding: 10px 10px;
  text-align: left;
  cursor: pointer;
  color: #12320a;
  box-shadow: 4px 4px 0 #0c1b39;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.egg-btn {
  border-radius: 999px 999px 820px 820px;
  padding: 8px 6px 6px;
  min-height: 52px;
  transform: rotate(-1.3deg);
  box-shadow: 3px 3px 0 #0c1b39;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn span {
  display: block;
  font-family: "Georgia", serif;
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.1;
}

.icon-btn small {
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.95;
}

.icon-btn:hover {
  transform: translate(-2px, -2px) rotate(-0.8deg);
  background: linear-gradient(180deg, #88e8ff 0%, #6fbdff 100%);
  color: #13213f;
}

.icon-btn.active {
  background: linear-gradient(180deg, #9ce67d 0%, #7dd85d 100%);
  color: #102c07;
  transform: translate(-1px, -1px);
}

.icon-btn.egg-btn span {
  font-size: 1.55rem;
  line-height: 1;
}

.icon-btn.egg-btn:hover {
  transform: translate(-2px, -2px) rotate(1.2deg);
}

.icon-btn.egg-btn {
  border: none;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  min-height: auto;
  padding: 2px 0;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.egg-btn:hover,
.icon-btn.egg-btn.active {
  background: transparent;
  color: inherit;
  box-shadow: none;
  transform: scale(1.08);
}

.window {
  border: 4px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(245, 255, 250, 0.96) 100%);
  box-shadow: var(--soft-shadow);
  padding: 16px;
  min-height: 620px;
  position: relative;
}

.window-title {
  display: inline-block;
  background: linear-gradient(180deg, #b9f995 0%, #8ce861 100%);
  border: 4px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  font-family: "Georgia", serif;
  font-size: 1.15rem;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
}

.window-title::after {
  content: "";
  position: absolute;
  top: -1px;
  left: -35%;
  width: 28%;
  height: calc(100% + 2px);
  background: rgba(255, 255, 255, 0.45);
  transform: skewX(-18deg);
  animation: title-gloss 2.8s ease-in-out infinite;
}

.window-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.window-title-row .window-title {
  margin-bottom: 0;
}

.fortress-top-start {
  border-width: 3px;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.92rem;
  font-weight: 800;
  background: linear-gradient(180deg, #8ee96b 0%, #79d85e 100%);
  color: #0f2a10;
  box-shadow: 2px 2px 0 #1f2d53;
}

.fortress-top-start:disabled {
  opacity: 0.65;
}

.view {
  display: none;
  animation: pop-in 0.18s ease-out;
}

.view.active {
  display: block;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.search-row {
  display: flex;
  gap: 8px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 3px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px;
  background: #fff;
}

#search-input::placeholder {
  color: #8c939d;
  opacity: 1;
}

button {
  border: 3px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  background: var(--blue);
  color: white;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.05);
}

.hint {
  margin: 10px 0 12px;
  font-size: 0.95rem;
}

.status {
  min-height: 1.35rem;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.status.error {
  color: #b00020;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.word-card {
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 3px 3px 0 #1c305f;
  animation: fade-rise 0.32s ease both;
}

.word-card h3 {
  margin: 0;
  font-size: 1.25rem;
}

.word-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.word-audio-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-width: 2px;
  border-radius: 10px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.word-audio-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.word-card p {
  margin: 0;
  line-height: 1.35;
}

.word-card .furigana {
  color: #234f98;
  font-weight: 600;
}

.word-card .meaning {
  color: #132;
}

.meaning-choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.meaning-choice-btn {
  border-width: 2px;
  border-radius: 10px;
  padding: 6px 7px;
  min-height: 36px;
  background: #eef5ff;
  color: #1e3563;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: left;
  white-space: normal;
}

.meaning-choice-btn.active {
  background: linear-gradient(180deg, #b4f68f 0%, #8ce763 100%);
  color: #102a08;
}

.word-card .example {
  color: #444;
  font-size: 0.92rem;
}

.example-stack {
  border: 2px dashed #1e273f;
  border-radius: 10px;
  padding: 8px;
  background: #f7fbff;
}

.example-jp {
  margin: 0;
  font-size: 1.07rem;
  line-height: 1.55;
  color: #1b2342;
}

.example-jp.has-ruby {
  line-height: 1.9;
}

.ruby-token {
  display: inline-flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  vertical-align: baseline;
  margin: 0 0.03em;
  line-height: 1;
}

.ruby-top {
  display: block;
  font-size: 0.46em;
  line-height: 0.95;
  color: #d14b7f;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  margin-bottom: 0.05em;
}

.ruby-base {
  display: block;
  line-height: 1.05;
  font-weight: 700;
  color: #19274b;
  white-space: nowrap;
}

.example-ko {
  margin: 6px 0 0;
  color: #28334a;
  font-size: 0.92rem;
  font-weight: 600;
}

.action-row {
  margin-top: auto;
  display: flex;
  gap: 6px;
}

.action-row .list-select {
  flex: 1;
}

.lists-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 2px 0 10px;
}

.lists-tools button {
  border-width: 2px;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  background: #e7f0ff;
  color: #163462;
}

.list-box {
  border: 3px solid var(--line);
  border-radius: 16px;
  padding: 10px 10px 12px;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f2faff 100%);
  box-shadow: 4px 4px 0 #1f2d53;
  animation: fade-rise 0.35s ease both;
}

.list-head {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.list-head-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-flex;
  gap: 4px;
}

.list-head h3 {
  margin: 0;
  padding-right: 56px;
}

.list-words {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.mini-word {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  padding-top: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f4fff1 100%);
  animation: fade-rise 0.22s ease both;
}

.mini-word p {
  margin: 2px 0;
  font-size: 0.9rem;
}

.mini-word .word {
  font-weight: 700;
  font-size: 1.03rem;
}

.mini-word .word-top {
  margin-bottom: 2px;
  display: block;
}

.mini-word .word-audio-btn {
  width: 28px;
  height: 28px;
  min-width: 28px;
  font-size: 0.9rem;
  border-radius: 8px;
  position: absolute;
  top: 32px;
  right: 4px;
  margin: 0;
}

.mini-word .word {
  display: block;
  padding-right: 34px;
}

.mini-badge {
  display: inline-block;
  margin-top: 4px;
  margin-bottom: 6px;
  padding: 2px 8px;
  border: 2px solid #1f3a6a;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #1f3a6a;
  background: #dce9ff;
}

.mini-badge.pinned {
  color: #513300;
  border-color: #7b5300;
  background: #ffe8a9;
}

.mini-example-stack {
  margin-top: 4px;
  margin-bottom: 6px;
  padding: 6px;
}

.mini-example-jp {
  font-size: 0.95rem;
}

.mini-example-ko {
  font-size: 0.82rem;
}

.mini-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.mini-action-btn {
  border-width: 2px;
  border-radius: 9px;
  padding: 4px 7px;
  font-size: 0.74rem;
  font-weight: 700;
  background: #e7f0ff;
  color: #183467;
}

.tiny-x-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 2px solid #8c0016;
  border-radius: 999px;
  background: #ff6a84;
  color: #fff;
  padding: 0;
  line-height: 1;
  font-size: 1rem;
  box-shadow: 1px 1px 0 #3b0712;
}

.tiny-edit-btn {
  width: 22px;
  height: 22px;
  border: 2px solid #1d3f7a;
  border-radius: 999px;
  background: #6ca2ff;
  color: #fff;
  padding: 0;
  line-height: 1;
  font-size: 0.8rem;
  box-shadow: 1px 1px 0 #11284f;
}

.tiny-edit-btn:hover {
  background: #4b8cff;
  transform: scale(1.03);
}

.list-head .tiny-x-btn,
.list-head .tiny-edit-btn {
  position: static;
}

.tiny-x-btn:hover {
  background: #ff2e54;
  transform: scale(1.03);
}

.history-card {
  position: relative;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #e0f1ff 0%, #cbe4ff 100%);
  padding: 12px;
  box-shadow: 4px 4px 0 #1a2e54;
  animation: fade-rise 0.3s ease both;
}

.history-card h3 {
  margin: 0;
  font-size: 1.2rem;
  padding-right: 30px;
}

.history-card p {
  margin: 6px 0 10px;
  font-size: 0.88rem;
  color: #18305c;
}

.history-search-btn {
  background: linear-gradient(180deg, #aef08b 0%, #90e067 100%);
  color: #102107;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar #flashcard-meta {
  font-size: 0.92rem;
  opacity: 0.8;
}

.flash-random-btn {
  min-width: 128px;
  font-weight: 700;
}

.flashcard-wrap {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  gap: 12px;
  align-items: center;
}

.flashcard-scene {
  perspective: 1200px;
  height: min(460px, 60vh);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.flashcard-scene.slide-out-left {
  animation: flash-slide-out-left 0.24s cubic-bezier(0.22, 0.68, 0.2, 1) forwards;
}

.flashcard-scene.slide-out-right {
  animation: flash-slide-out-right 0.24s cubic-bezier(0.22, 0.68, 0.2, 1) forwards;
}

.flashcard-scene.slide-in-left {
  animation: flash-slide-in-left 0.28s cubic-bezier(0.2, 0.78, 0.18, 1) forwards;
}

.flashcard-scene.slide-in-right {
  animation: flash-slide-in-right 0.28s cubic-bezier(0.2, 0.78, 0.18, 1) forwards;
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.2, 0.7, 0, 1);
  cursor: pointer;
}

.flashcard.is-flipped {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  border-radius: 30px;
  border: 3px solid var(--line);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px;
}

.face-front {
  background: #2d2f33;
  color: #fff;
  box-shadow: inset 0 -20px 50px rgba(255, 255, 255, 0.07);
}

.face-front h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
}

.face-front p {
  margin-top: 18px;
  font-size: 1.1rem;
  opacity: 0.75;
}

.face-back {
  transform: rotateY(180deg);
  background: linear-gradient(140deg, #d9f8e6 0%, #f8f9ff 60%);
  box-shadow: inset 0 -26px 50px rgba(135, 184, 255, 0.12);
}

.face-back h3 {
  margin: 0 0 12px;
  font-size: 1.6rem;
  color: #2151a1;
}

.face-back p {
  margin: 8px 0;
  font-size: 1.05rem;
}

.nav-btn {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: #f2f2f2;
  color: #2a59d5;
  font-size: 1.7rem;
}

.progress-row {
  margin-top: 12px;
}

.progress-track {
  height: 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #e8edf3;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #385fff 0%, #76d861 100%);
  transition: width 0.2s ease;
}

.quiz-area {
  border: 3px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: linear-gradient(180deg, #fff 0%, #f4faff 100%);
  min-height: 380px;
}

.fortress-root {
  border: 3px solid var(--line);
  border-radius: 18px;
  padding: 10px;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.55) 0,
      rgba(255, 255, 255, 0.55) 2px,
      rgba(185, 242, 255, 0.18) 2px,
      rgba(185, 242, 255, 0.18) 8px
    ),
    linear-gradient(180deg, #f8fcff 0%, #edf7ff 46%, #f7fff5 100%);
  box-shadow: 5px 5px 0 #1f335f;
}

.fortress-shell {
  display: grid;
  gap: 10px;
}

.fortress-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border: 2px solid #1c325b;
  border-radius: 11px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 0.87rem;
  font-weight: 700;
  color: #1e335d;
}

.fortress-bars {
  display: grid;
  gap: 6px;
}

.fortress-canvas-wrap {
  border: 3px solid #1d335d;
  border-radius: 14px;
  overflow: hidden;
  background: #d5e9ff;
  min-height: 230px;
}

.fortress-canvas {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 1240 / 430;
}

.fortress-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
  border: 2px solid #1d325a;
  border-radius: 10px;
  padding: 6px 8px;
  background: #ffffffd6;
}

.fortress-angle-text {
  margin: 0;
  flex: 1;
  min-width: 240px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #223763;
}

.fortress-actions {
  display: flex;
  gap: 6px;
}

.fortress-stats {
  border: 2px dashed #22345f;
  border-radius: 10px;
  padding: 6px 8px;
  background: #f8fbff;
}

.fortress-stats p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.35;
  color: #1f3460;
}

.fortress-msg {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: #1c3159;
}

.fortress-win {
  margin: 0;
  color: #0b5f26;
}

.quiz-question {
  font-size: clamp(1.2rem, 3.4vw, 1.85rem);
  margin: 0 0 14px;
}

.quiz-meta {
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.quiz-options {
  display: grid;
  gap: 10px;
}

.quiz-option {
  text-align: left;
  border-radius: 14px;
  border: 2px solid #ddd;
  background: #f7f7f8;
  color: #222;
  padding: 14px 14px;
}

.quiz-option.correct {
  border-color: #2fa943;
  background: #e7ffe9;
}

.quiz-option.wrong {
  border-color: #c62828;
  background: #ffebeb;
}

.score-box {
  margin-top: 14px;
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #f4f9ff;
}

.artillery-wrap {
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: linear-gradient(180deg, #f7fbff 0%, #ecf5ff 48%, #f3f9ff 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.artillery-wrap .quiz-meta {
  margin: 0 0 4px;
  font-size: 0.92rem;
}

.artillery-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: start;
}

.battle-stage {
  position: relative;
  border: 3px solid #1b2d54;
  border-radius: 14px;
  padding: 8px 8px 6px;
  margin-bottom: 0;
  overflow: hidden;
  width: 100%;
  min-height: 212px;
  background:
    radial-gradient(circle at 16% 26%, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0) 34%),
    linear-gradient(180deg, #d8ebff 0%, #b2d7ff 50%, #8fbb85 51%, #719b66 100%);
}

.stage-hp {
  position: absolute;
  top: 6px;
  width: min(34%, 250px);
  z-index: 4;
  border: 2px solid #142447;
  border-radius: 10px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.92);
}

.stage-hp p {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: #1a2f5b;
}

.stage-hp-enemy {
  right: 8px;
}

.stage-hp-player {
  left: 8px;
}

.battle-ground {
  margin-top: 46px;
  display: flex;
  justify-content: space-between;
  align-items: end;
  min-height: 138px;
  padding: 0 16px;
}

.battery {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 86px;
  flex: 0 0 auto;
}

.reload-meter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 80px;
  height: 18px;
  border: 2px solid #1a2f57;
  border-radius: 8px;
  background: rgba(9, 24, 54, 0.18);
  overflow: hidden;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.reload-meter span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #9fff9f 0%, #47d24f 100%);
}

.reload-meter em {
  position: absolute;
  inset: 0;
  font-style: normal;
  font-size: 0.65rem;
  font-weight: 800;
  color: #0c223f;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
}

.battery-player {
  justify-content: flex-start;
}

.battery-enemy {
  justify-content: flex-end;
  padding-right: 16px;
}

.crew {
  position: relative;
  width: 24px;
  height: 70px;
  filter: drop-shadow(0 2px 0 rgba(8, 25, 53, 0.45));
  animation: crew-idle 1.4s ease-in-out infinite;
}

.soldier > span {
  position: absolute;
  display: block;
}

.soldier .hat {
  left: 5px;
  top: 0;
  width: 16px;
  height: 8px;
  border: 2px solid #0f1b38;
  border-radius: 2px;
  background: linear-gradient(180deg, #1b2745 0%, #11182d 100%);
}

.soldier .plume {
  left: 16px;
  top: -5px;
  width: 4px;
  height: 8px;
  border-radius: 2px;
  background: #c9242f;
}

.soldier .head {
  left: 8px;
  top: 7px;
  width: 10px;
  height: 10px;
  border: 1px solid #3d2f27;
  border-radius: 50%;
  background: #f3ceb5;
}

.soldier .torso {
  left: 6px;
  top: 16px;
  width: 14px;
  height: 26px;
  border: 2px solid #0e1e42;
  border-radius: 4px;
  background: linear-gradient(180deg, #334f93 0%, #243b71 100%);
}

.soldier .strap {
  left: 11px;
  top: 17px;
  width: 3px;
  height: 26px;
  border-radius: 2px;
  background: #e8edf8;
  transform: rotate(16deg);
  transform-origin: top center;
}

.soldier .leg {
  top: 40px;
  width: 5px;
  height: 23px;
  border-radius: 2px;
  background: #1b2438;
}

.soldier .leg-left {
  left: 8px;
}

.soldier .leg-right {
  left: 14px;
}

.soldier .tool {
  border-radius: 1px;
}

.soldier .tool.sabre {
  left: 3px;
  top: 28px;
  width: 2px;
  height: 25px;
  background: #a9b8d1;
}

.soldier .tool.ramrod {
  left: 20px;
  top: 22px;
  width: 2px;
  height: 36px;
  background: #d7bf8a;
}

.soldier .tool.sponge {
  left: 19px;
  top: 24px;
  width: 2px;
  height: 33px;
  background: #c6b077;
}

.soldier .tool.sponge::after {
  content: "";
  position: absolute;
  top: -4px;
  left: -2px;
  width: 6px;
  height: 5px;
  border-radius: 3px;
  background: #ad8f51;
}

.crew-officer {
  animation-delay: 0.08s;
}

.crew-gunner {
  animation-delay: 0.2s;
}

.crew-loader {
  animation-delay: 0.34s;
}

.crew-loader .torso {
  transform: skewX(-6deg);
}

.cannon {
  position: relative;
  width: 84px;
  height: 58px;
  margin: 0 4px;
}

.cannon > span {
  position: absolute;
  display: block;
}

.cannon .barrel {
  left: 10px;
  top: 16px;
  width: 60px;
  height: 13px;
  border: 3px solid #101f42;
  border-radius: 8px;
  background: linear-gradient(180deg, #4e576a 0%, #263148 100%);
}

.cannon .muzzle {
  left: 68px;
  top: 18px;
  width: 9px;
  height: 10px;
  border-radius: 50%;
  background: #0f1626;
}

.cannon .carriage {
  left: 20px;
  top: 30px;
  width: 34px;
  height: 11px;
  border: 2px solid #44331d;
  border-radius: 3px;
  background: #805f34;
}

.cannon .trail {
  left: 4px;
  top: 36px;
  width: 36px;
  height: 8px;
  border: 2px solid #45331a;
  border-radius: 3px;
  background: #7b5a2d;
  transform: rotate(-8deg);
}

.cannon .wheel {
  width: 26px;
  height: 26px;
  border: 3px solid #1a2237;
  border-radius: 50%;
  background: radial-gradient(circle, #485874 0%, #2e3953 62%, #1f293e 100%);
}

.cannon .wheel::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 2px solid rgba(230, 238, 255, 0.35);
}

.cannon .wheel-a {
  left: 20px;
  top: 38px;
}

.cannon .wheel-b {
  left: 46px;
  top: 39px;
}

.cannon-player {
  transform-origin: 38px 34px;
}

.cannon-enemy {
  transform: scaleX(-1);
  transform-origin: 68px 34px;
}

.shot-lane {
  position: absolute;
  left: 7%;
  right: 7%;
  bottom: 20px;
  height: 114px;
  z-index: 3;
  pointer-events: none;
}

.battle-stage.distance-mid .shot-lane {
  height: 102px;
}

.battle-stage.distance-close .shot-lane {
  height: 88px;
}

.proj,
.impact-blast,
.enemy-proj,
.enemy-impact-blast {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.muzzle,
.smoke {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.muzzle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}

.muzzle-player {
  left: 2%;
  top: 62%;
}

.muzzle-enemy {
  right: 2%;
  top: 62%;
}

.smoke {
  width: 30px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 45% 45%, rgba(245, 248, 255, 0.92) 0%, rgba(144, 160, 186, 0.58) 60%, rgba(102, 116, 145, 0) 100%);
}

.smoke-player {
  left: 1%;
  top: 56%;
}

.smoke-enemy {
  right: 1%;
  top: 56%;
}

.proj-round {
  width: 12px;
  height: 12px;
  top: 62%;
  left: 3%;
  border-radius: 999px;
  background: #121212;
}

.proj-shell {
  width: 14px;
  height: 14px;
  left: 3%;
  top: 66%;
  border-radius: 999px;
  background: radial-gradient(circle at 40% 40%, #c1cad6 0%, #394150 80%);
}

.proj-canister {
  width: 7px;
  height: 7px;
  left: 3%;
  top: 65%;
  border-radius: 999px;
  background: #2c313d;
}

.proj-canister.c2 {
  top: 58%;
}

.proj-canister.c3 {
  top: 70%;
}

.impact-blast {
  right: 4%;
  top: 53%;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff6a4 0%, #ffb243 55%, rgba(255, 98, 71, 0.12) 100%);
}

.enemy-proj-round {
  width: 12px;
  height: 12px;
  top: 62%;
  right: 3%;
  border-radius: 999px;
  background: #161616;
}

.enemy-proj-shell {
  width: 14px;
  height: 14px;
  right: 3%;
  top: 64%;
  border-radius: 999px;
  background: radial-gradient(circle at 40% 40%, #ced6e0 0%, #444c5f 80%);
}

.enemy-proj-canister {
  width: 7px;
  height: 7px;
  right: 3%;
  top: 65%;
  border-radius: 999px;
  background: #373d4c;
}

.enemy-proj-canister.c2 {
  top: 58%;
}

.enemy-proj-canister.c3 {
  top: 70%;
}

.enemy-impact-blast {
  left: 4%;
  top: 53%;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff8be 0%, #ffcf7a 50%, rgba(255, 109, 79, 0.16) 100%);
}

.battle-stage.player-loading .battery-player .crew-loader,
.battle-stage.player-loading .battery-player .crew-gunner {
  animation: crew-load-left 0.42s ease-in-out infinite alternate;
}

.battle-stage.player-loading .reload-player {
  opacity: 1;
  transform: translateY(0);
}

.battle-stage.player-loading .reload-player span {
  animation: reload-fill 1.1s linear infinite;
}

.battle-stage.player-loading .battery-player .crew-gunner .tool,
.battle-stage.player-loading .battery-player .crew-loader .tool {
  animation: tool-thrust 0.36s ease-in-out infinite alternate;
}

.battle-stage.enemy-loading .battery-enemy .crew-loader,
.battle-stage.enemy-loading .battery-enemy .crew-gunner {
  animation: crew-load-right 0.42s ease-in-out infinite alternate;
}

.battle-stage.enemy-loading .reload-enemy {
  opacity: 1;
  transform: translateY(0);
}

.battle-stage.enemy-loading .reload-enemy span {
  animation: reload-fill 1.1s linear infinite;
}

.battle-stage.enemy-loading .battery-enemy .crew-gunner .tool,
.battle-stage.enemy-loading .battery-enemy .crew-loader .tool {
  animation: tool-thrust-rev 0.36s ease-in-out infinite alternate;
}

.battle-stage.player-firing .battery-player .cannon-player {
  animation: cannon-recoil-left 0.35s ease-out;
}

.battle-stage.enemy-firing .battery-enemy .cannon-enemy {
  animation: cannon-recoil-right 0.35s ease-out;
}

.battle-stage.player-firing-round .battery-player .cannon-player {
  animation: cannon-round-recoil-left 0.34s cubic-bezier(0.2, 0.8, 0.05, 1);
}

.battle-stage.player-firing-shell .battery-player .cannon-player {
  animation: cannon-shell-kick-left 0.44s cubic-bezier(0.2, 0.8, 0.05, 1);
}

.battle-stage.player-firing-canister .battery-player .cannon-player {
  animation: cannon-canister-recoil-left 0.3s ease-out;
}

.battle-stage.enemy-firing-round .battery-enemy .cannon-enemy {
  animation: cannon-round-recoil-right 0.34s cubic-bezier(0.2, 0.8, 0.05, 1);
}

.battle-stage.enemy-firing-shell .battery-enemy .cannon-enemy {
  animation: cannon-shell-kick-right 0.44s cubic-bezier(0.2, 0.8, 0.05, 1);
}

.battle-stage.enemy-firing-canister .battery-enemy .cannon-enemy {
  animation: cannon-canister-recoil-right 0.3s ease-out;
}

.battle-stage.shot-round .proj-round {
  opacity: 1;
  animation: round-flight 0.5s linear forwards;
}

.battle-stage.shot-shell .proj-shell {
  opacity: 1;
  animation: shell-arc 0.52s ease-out forwards;
}

.battle-stage.shot-canister .proj-canister.c1 {
  opacity: 1;
  animation: canister-flight-a 0.36s linear forwards;
}

.battle-stage.shot-canister .proj-canister.c2 {
  opacity: 1;
  animation: canister-flight-b 0.36s linear forwards;
}

.battle-stage.shot-canister .proj-canister.c3 {
  opacity: 1;
  animation: canister-flight-c 0.36s linear forwards;
}

.battle-stage.shot-round .muzzle-player {
  opacity: 1;
  animation: muzzle-round 0.26s ease-out forwards;
}

.battle-stage.shot-shell .muzzle-player {
  opacity: 1;
  animation: muzzle-shell 0.34s ease-out forwards;
}

.battle-stage.enemy-shot-round .muzzle-enemy {
  opacity: 1;
  animation: muzzle-round 0.26s ease-out forwards;
}

.battle-stage.enemy-shot-shell .muzzle-enemy {
  opacity: 1;
  animation: muzzle-shell 0.34s ease-out forwards;
}

.battle-stage.shot-round .smoke-player {
  opacity: 1;
  animation: smoke-round-left 0.56s ease-out forwards;
}

.battle-stage.shot-shell .smoke-player {
  opacity: 1;
  animation: smoke-shell-left 0.72s ease-out forwards;
}

.battle-stage.enemy-shot-round .smoke-enemy {
  opacity: 1;
  animation: smoke-round-right 0.56s ease-out forwards;
}

.battle-stage.enemy-shot-shell .smoke-enemy {
  opacity: 1;
  animation: smoke-shell-right 0.72s ease-out forwards;
}

.battle-stage.impact-round .impact-blast {
  opacity: 1;
  animation: impact-burst-round 0.4s ease-out forwards;
}

.battle-stage.impact-shell .impact-blast {
  opacity: 1;
  animation: impact-burst-shell 0.52s ease-out forwards;
}

.battle-stage.impact-canister .impact-blast {
  opacity: 1;
  animation: impact-burst-canister 0.3s ease-out forwards;
}

.battle-stage.enemy-shot-round .enemy-proj-round {
  opacity: 1;
  animation: enemy-round-flight 0.5s linear forwards;
}

.battle-stage.enemy-shot-shell .enemy-proj-shell {
  opacity: 1;
  animation: enemy-shell-arc 0.52s ease-out forwards;
}

.battle-stage.enemy-shot-canister .enemy-proj-canister.c1 {
  opacity: 1;
  animation: enemy-canister-flight-a 0.36s linear forwards;
}

.battle-stage.enemy-shot-canister .enemy-proj-canister.c2 {
  opacity: 1;
  animation: enemy-canister-flight-b 0.36s linear forwards;
}

.battle-stage.enemy-shot-canister .enemy-proj-canister.c3 {
  opacity: 1;
  animation: enemy-canister-flight-c 0.36s linear forwards;
}

.battle-stage.enemy-impact-round .enemy-impact-blast {
  opacity: 1;
  animation: impact-burst-round 0.4s ease-out forwards;
}

.battle-stage.enemy-impact-shell .enemy-impact-blast {
  opacity: 1;
  animation: impact-burst-shell 0.52s ease-out forwards;
}

.battle-stage.enemy-impact-canister .enemy-impact-blast {
  opacity: 1;
  animation: impact-burst-canister 0.3s ease-out forwards;
}

.battle-stage.enemy-hit .battery-enemy {
  animation: battery-hit-right 0.3s ease-out;
}

.battle-stage.enemy-hit-round .battery-enemy {
  animation: battery-hit-right 0.32s ease-out;
}

.battle-stage.enemy-hit-shell .battery-enemy {
  animation: battery-hit-shell-right 0.48s ease-out;
}

.battle-stage.enemy-hit .battery-enemy .crew {
  animation: crew-stagger-right 0.34s ease-out;
}

.battle-stage.player-hit .battery-player {
  animation: battery-hit-left 0.3s ease-out;
}

.battle-stage.player-hit-round .battery-player {
  animation: battery-hit-left 0.32s ease-out;
}

.battle-stage.player-hit-shell .battery-player {
  animation: battery-hit-shell-left 0.48s ease-out;
}

.battle-stage.player-hit .battery-player .crew {
  animation: crew-stagger-left 0.34s ease-out;
}

.stat-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}

.stat-label {
  font-size: 0.78rem;
  opacity: 0.8;
}

.meter {
  margin-top: 6px;
  height: 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #e6edf8;
}

.meter > span {
  display: block;
  height: 100%;
}

.meter.enemy > span {
  background: linear-gradient(90deg, #ff6262 0%, #d32222 100%);
}

.meter.player > span {
  background: linear-gradient(90deg, #85e978 0%, #46be3d 100%);
}

.meter.cohesion {
  margin-top: 4px;
  height: 9px;
}

.meter.cohesion > span {
  background: linear-gradient(90deg, #8fd3ff 0%, #3d74d8 100%);
}

.artillery-range {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  color: #1b2f59;
}

.tactics-panel {
  border: 2px solid #22365f;
  border-radius: 12px;
  padding: 6px;
  margin-bottom: 6px;
  background: linear-gradient(180deg, #f7fbff 0%, #eaf4ff 100%);
}

.artillery-control-panel {
  border: 2px solid #25365f;
  border-radius: 12px;
  padding: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(236, 245, 255, 0.95) 100%);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.status-chip {
  margin: 0;
  border: 2px solid #213661;
  border-radius: 999px;
  background: #fff;
  padding: 2px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #1d325f;
}

.tactics-title {
  margin: 0 0 4px;
  font-size: 0.76rem;
  font-weight: 800;
  color: #1a2f56;
}

.tactics-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  margin-bottom: 0;
}

.tactic-btn,
.tactic-cmd-btn {
  border: 2px solid #1f2f56;
  border-radius: 10px;
  background: #fff;
  color: #182745;
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 700;
}

.tactic-btn.active {
  background: linear-gradient(180deg, #9df084 0%, #73d757 100%);
  color: #0d2d07;
}

.tactic-cmd-btn {
  background: linear-gradient(180deg, #d9e8ff 0%, #c3dcff 100%);
}

.tactics-note {
  margin: 5px 0 0;
  font-size: 0.74rem;
  line-height: 1.2;
  color: #203861;
}

.objective-row {
  margin: 5px 0 0;
  border: 2px solid #213861;
  border-radius: 9px;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #1b3158;
  background: #f1f8ff;
}

.objective-row.ok {
  background: #e6ffe9;
  border-color: #2d7f42;
  color: #16592b;
}

.objective-row.failed {
  background: #ffeded;
  border-color: #a53434;
  color: #7a2222;
}

.artillery-prompt {
  border: 2px dashed #20325f;
  border-radius: 12px;
  padding: 8px;
  background: #fff;
  margin-bottom: 6px;
}

.artillery-prompt .quiz-question {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.5rem);
}

.artillery-options {
  margin-top: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.artillery-option {
  padding: 9px 10px;
  min-height: 56px;
  font-size: 0.95rem;
  line-height: 1.22;
}

.artillery-shot-row {
  margin-top: 6px;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.shot-btn {
  background: linear-gradient(180deg, #ffdd85 0%, #ffbf48 100%);
  color: #332100;
  border-color: #5f4300;
  flex: 1 1 0;
  padding: 8px 6px;
  font-size: 0.92rem;
}

.shot-btn[data-shot="round"] {
  background: linear-gradient(180deg, #e5edf5 0%, #bcc8d8 100%);
  color: #1a263d;
}

.shot-btn[data-shot="shell"] {
  background: linear-gradient(180deg, #ffd7a8 0%, #ffb45f 100%);
  color: #3a2300;
}

.shot-btn[data-shot="canister"] {
  background: linear-gradient(180deg, #fff3a8 0%, #f7d84d 100%);
  color: #483803;
}

.artillery-log {
  margin-top: 0;
  border: 2px solid #22345a;
  border-radius: 10px;
  padding: 6px;
  background: #10182b;
  color: #d7e6ff;
  font-size: 0.8rem;
  max-height: 72px;
  overflow-y: auto;
}

.artillery-log p {
  margin: 2px 0;
}

.artillery-control-panel .hint {
  margin: 4px 0 2px;
  font-size: 0.86rem;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.game-tile {
  position: relative;
  height: 128px;
  border: 0;
  padding: 0;
  background: transparent;
  perspective: 900px;
}

.game-tile-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.28s ease;
}

.game-tile.is-flipped .game-tile-inner {
  transform: rotateY(180deg);
}

.game-tile-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  border: 3px solid var(--line);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
}

.game-front {
  background: linear-gradient(180deg, #8ed7ff 0%, #6caaf8 100%);
  color: #fff;
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 3px 3px 0 #203b74;
}

.game-back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #fff8ff 0%, #eef5ff 100%);
  color: #1c2244;
  box-shadow: 3px 3px 0 #203b74;
}

.game-tile.is-matched .game-back {
  background: linear-gradient(180deg, #d9ffd9 0%, #b5f8b5 100%);
}

.game-label {
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.25;
}

.game-detail {
  margin-top: 4px;
  font-size: 0.84rem;
  color: #244d9f;
  font-weight: 700;
}

@keyframes fade-rise {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@keyframes card-drift {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-5px);
  }
}

@keyframes title-gloss {
  0% {
    left: -35%;
  }
  45%,
  100% {
    left: 118%;
  }
}

@keyframes crew-idle {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

@keyframes crew-load {
  from {
    transform: translateY(0) rotate(-8deg);
  }
  to {
    transform: translateY(2px) rotate(6deg);
  }
}

@keyframes crew-load-left {
  0% {
    transform: translateX(0) translateY(0) rotate(0deg);
  }
  50% {
    transform: translateX(12px) translateY(2px) rotate(-12deg);
  }
  100% {
    transform: translateX(0) translateY(0) rotate(3deg);
  }
}

@keyframes crew-load-right {
  0% {
    transform: translateX(0) translateY(0) rotate(0deg);
  }
  50% {
    transform: translateX(-12px) translateY(2px) rotate(12deg);
  }
  100% {
    transform: translateX(0) translateY(0) rotate(-3deg);
  }
}

@keyframes cannon-recoil-left {
  0% {
    transform: translateX(0);
    filter: brightness(1);
  }
  25% {
    transform: translateX(-11px);
    filter: brightness(1.4);
  }
  100% {
    transform: translateX(0);
    filter: brightness(1);
  }
}

@keyframes cannon-recoil-right {
  0% {
    transform: scaleX(-1) translateX(0);
    filter: brightness(1);
  }
  25% {
    transform: scaleX(-1) translateX(-11px);
    filter: brightness(1.3);
  }
  100% {
    transform: scaleX(-1) translateX(0);
    filter: brightness(1);
  }
}

@keyframes cannon-round-recoil-left {
  0% {
    transform: translateX(0) rotate(0deg);
    filter: brightness(1);
  }
  28% {
    transform: translateX(-13px) rotate(-1.4deg);
    filter: brightness(1.36);
  }
  100% {
    transform: translateX(0) rotate(0deg);
    filter: brightness(1);
  }
}

@keyframes cannon-round-recoil-right {
  0% {
    transform: scaleX(-1) translateX(0) rotate(0deg);
    filter: brightness(1);
  }
  28% {
    transform: scaleX(-1) translateX(-13px) rotate(-1.4deg);
    filter: brightness(1.36);
  }
  100% {
    transform: scaleX(-1) translateX(0) rotate(0deg);
    filter: brightness(1);
  }
}

@keyframes cannon-shell-kick-left {
  0% {
    transform: translateX(0) rotate(0deg);
    filter: brightness(1);
  }
  22% {
    transform: translateX(-8px) rotate(-6deg);
    filter: brightness(1.46);
  }
  58% {
    transform: translateX(-2px) rotate(-2deg);
    filter: brightness(1.2);
  }
  100% {
    transform: translateX(0) rotate(0deg);
    filter: brightness(1);
  }
}

@keyframes cannon-shell-kick-right {
  0% {
    transform: scaleX(-1) translateX(0) rotate(0deg);
    filter: brightness(1);
  }
  22% {
    transform: scaleX(-1) translateX(-8px) rotate(-6deg);
    filter: brightness(1.46);
  }
  58% {
    transform: scaleX(-1) translateX(-2px) rotate(-2deg);
    filter: brightness(1.2);
  }
  100% {
    transform: scaleX(-1) translateX(0) rotate(0deg);
    filter: brightness(1);
  }
}

@keyframes cannon-canister-recoil-left {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  18% {
    transform: translateX(-10px) rotate(-0.8deg);
  }
  36% {
    transform: translateX(-6px) rotate(0.6deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes cannon-canister-recoil-right {
  0% {
    transform: scaleX(-1) translateX(0) rotate(0deg);
  }
  18% {
    transform: scaleX(-1) translateX(-10px) rotate(-0.8deg);
  }
  36% {
    transform: scaleX(-1) translateX(-6px) rotate(0.6deg);
  }
  100% {
    transform: scaleX(-1) translateX(0) rotate(0deg);
  }
}

@keyframes muzzle-round {
  0% {
    transform: scale(0.3);
    opacity: 0.95;
    background: radial-gradient(circle, #fff4aa 0%, #ffc35f 55%, rgba(255, 149, 64, 0.05) 100%);
  }
  100% {
    transform: scale(1.25);
    opacity: 0;
  }
}

@keyframes muzzle-shell {
  0% {
    transform: scale(0.28);
    opacity: 1;
    background: radial-gradient(circle, #fff9d6 0%, #ffdf6f 34%, #ff9f5f 62%, rgba(255, 104, 74, 0.08) 100%);
  }
  45% {
    transform: scale(1.5);
    opacity: 0.88;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

@keyframes smoke-round-left {
  0% {
    transform: translate(0, 0) scale(0.7);
    opacity: 0.65;
  }
  100% {
    transform: translate(22px, -10px) scale(1.22);
    opacity: 0;
  }
}

@keyframes smoke-round-right {
  0% {
    transform: translate(0, 0) scale(0.7);
    opacity: 0.65;
  }
  100% {
    transform: translate(-22px, -10px) scale(1.22);
    opacity: 0;
  }
}

@keyframes smoke-shell-left {
  0% {
    transform: translate(0, 0) scale(0.65);
    opacity: 0.85;
  }
  100% {
    transform: translate(34px, -18px) scale(1.7);
    opacity: 0;
  }
}

@keyframes smoke-shell-right {
  0% {
    transform: translate(0, 0) scale(0.65);
    opacity: 0.85;
  }
  100% {
    transform: translate(-34px, -18px) scale(1.7);
    opacity: 0;
  }
}

@keyframes round-flight {
  from {
    left: 3%;
    top: 62%;
    transform: scale(1);
  }
  to {
    left: 93%;
    top: 60%;
    transform: scale(1.05);
  }
}

@keyframes shell-arc {
  0% {
    left: 3%;
    top: 66%;
    transform: scale(1);
  }
  45% {
    left: 51%;
    top: 34%;
    transform: scale(1.12);
  }
  100% {
    left: 93%;
    top: 60%;
    transform: scale(1);
  }
}

@keyframes canister-flight-a {
  from {
    left: 3%;
    top: 64%;
  }
  to {
    left: 92%;
    top: 58%;
  }
}

@keyframes canister-flight-b {
  from {
    left: 3%;
    top: 58%;
  }
  to {
    left: 92%;
    top: 45%;
  }
}

@keyframes canister-flight-c {
  from {
    left: 3%;
    top: 70%;
  }
  to {
    left: 92%;
    top: 75%;
  }
}

@keyframes enemy-round-flight {
  from {
    right: 3%;
    top: 62%;
    transform: scale(1);
  }
  to {
    right: 93%;
    top: 60%;
    transform: scale(1.05);
  }
}

@keyframes enemy-shell-arc {
  0% {
    right: 3%;
    top: 64%;
    transform: scale(1);
  }
  45% {
    right: 51%;
    top: 32%;
    transform: scale(1.12);
  }
  100% {
    right: 93%;
    top: 61%;
    transform: scale(1);
  }
}

@keyframes enemy-canister-flight-a {
  from {
    right: 3%;
    top: 64%;
  }
  to {
    right: 92%;
    top: 58%;
  }
}

@keyframes enemy-canister-flight-b {
  from {
    right: 3%;
    top: 58%;
  }
  to {
    right: 92%;
    top: 45%;
  }
}

@keyframes enemy-canister-flight-c {
  from {
    right: 3%;
    top: 70%;
  }
  to {
    right: 92%;
    top: 75%;
  }
}

@keyframes impact-burst-round {
  0% {
    transform: scale(0.42);
    filter: brightness(1.2);
  }
  100% {
    transform: scale(1.25);
    opacity: 0;
    filter: brightness(0.92);
  }
}

@keyframes impact-burst-shell {
  0% {
    transform: scale(0.34);
    filter: brightness(1.45);
  }
  35% {
    transform: scale(1.2);
    opacity: 0.95;
    filter: brightness(1.2);
  }
  100% {
    transform: scale(1.85);
    opacity: 0;
    filter: brightness(0.88);
  }
}

@keyframes impact-burst-canister {
  0% {
    transform: scale(0.45);
    filter: brightness(1.18);
  }
  100% {
    transform: scale(1.08);
    opacity: 0;
    filter: brightness(0.92);
  }
}

@keyframes battery-hit-right {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  35% {
    transform: translateX(8px) rotate(1.1deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes battery-hit-left {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  35% {
    transform: translateX(-8px) rotate(-1.1deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes battery-hit-shell-right {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  20% {
    transform: translateX(14px) rotate(2deg);
  }
  48% {
    transform: translateX(7px) rotate(0.7deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes battery-hit-shell-left {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  20% {
    transform: translateX(-14px) rotate(-2deg);
  }
  48% {
    transform: translateX(-7px) rotate(-0.7deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes crew-stagger-right {
  0% {
    transform: translateX(0);
  }
  40% {
    transform: translateX(6px) rotate(7deg);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes crew-stagger-left {
  0% {
    transform: translateX(0);
  }
  40% {
    transform: translateX(-6px) rotate(-7deg);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes impact-burst {
  0% {
    transform: scale(0.45);
    filter: brightness(1.3);
  }
  100% {
    transform: scale(1.45);
    opacity: 0;
    filter: brightness(0.95);
  }
}

@keyframes reload-fill {
  from {
    width: 0%;
  }
  to {
    width: 100%;
  }
}

@keyframes flash-slide-out-left {
  from {
    transform: translateX(0);
    opacity: 1;
    filter: blur(0);
  }
  to {
    transform: translateX(-124px) rotate(-2deg) scale(0.98);
    opacity: 0;
    filter: blur(2.2px);
  }
}

@keyframes flash-slide-out-right {
  from {
    transform: translateX(0);
    opacity: 1;
    filter: blur(0);
  }
  to {
    transform: translateX(124px) rotate(2deg) scale(0.98);
    opacity: 0;
    filter: blur(2.2px);
  }
}

@keyframes flash-slide-in-left {
  from {
    transform: translateX(-124px) rotate(-2deg) scale(0.98);
    opacity: 0;
    filter: blur(2.2px);
  }
  to {
    transform: translateX(0);
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes flash-slide-in-right {
  from {
    transform: translateX(124px) rotate(2deg) scale(0.98);
    opacity: 0;
    filter: blur(2.2px);
  }
  to {
    transform: translateX(0);
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes tool-thrust {
  from {
    transform: translateX(0) rotate(0deg);
  }
  to {
    transform: translateX(10px) rotate(12deg);
  }
}

@keyframes tool-thrust-rev {
  from {
    transform: translateX(0) rotate(0deg);
  }
  to {
    transform: translateX(-10px) rotate(-12deg);
  }
}

@media (max-width: 960px) {
  .lang-toggle {
    margin-left: 0;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .user-panel {
    min-width: 0;
  }

  .desktop-shell {
    grid-template-columns: 1fr;
  }

  .dock {
    flex-direction: row;
    overflow-x: auto;
  }

  .icon-btn {
    min-width: 120px;
  }

  .egg-btn {
    min-width: 132px;
  }

  .tactics-row {
    flex-wrap: wrap;
  }

  .artillery-options {
    grid-template-columns: 1fr;
  }

  .fortress-angle-text {
    min-width: 180px;
  }
}

@media (max-width: 760px) {
  .search-row {
    flex-direction: column;
  }

  .flashcard-wrap {
    grid-template-columns: 1fr;
  }

  .nav-btn {
    width: 100%;
    height: auto;
    border-radius: 12px;
    padding: 8px;
  }

  .flashcard-scene {
    height: min(420px, 56vh);
  }

  .game-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .battle-ground {
    min-height: 124px;
    padding: 0 12px;
  }

  .battery {
    min-width: 0;
  }

  .fortress-controls {
    align-items: stretch;
  }

  .fortress-actions {
    width: 100%;
  }
}

/* Mobile-only optimization layer (desktop remains unchanged). */
@media (max-width: 900px) {
  body {
    padding: 14px 10px calc(112px + env(safe-area-inset-bottom, 0px));
  }

  body::before,
  body::after,
  .bg-shape {
    display: none;
  }

  .lang-toggle {
    margin: 0 auto 8px;
    position: sticky;
    top: 8px;
    z-index: 35;
  }

  .topbar {
    width: 100%;
    margin-bottom: 10px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: clamp(1.5rem, 7.6vw, 2rem);
    line-height: 1.05;
  }

  .topbar p {
    font-size: 0.94rem;
    margin-top: 4px;
  }

  .user-panel {
    width: 100%;
    border-width: 2px;
    box-shadow: 2px 2px 0 #20365f;
  }

  .desktop-shell {
    width: 100%;
    display: block;
  }

  .window {
    border-width: 3px;
    border-radius: 16px;
    box-shadow: 3px 3px 0 #111111;
    padding: 10px;
    min-height: 0;
  }

  .window-title {
    margin-bottom: 10px;
    border-width: 3px;
    padding: 6px 13px;
  }

  .card-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .list-words {
    grid-template-columns: 1fr;
  }

  .search-row {
    gap: 7px;
  }

  input,
  select,
  button {
    min-height: 44px;
  }

  .toolbar {
    gap: 6px;
    margin-bottom: 10px;
  }

  .quiz-area {
    min-height: 0;
    padding: 10px;
  }

  .artillery-wrap,
  .fortress-root {
    box-shadow: none;
  }

  .battle-stage {
    min-height: 188px;
  }

  .battle-ground {
    padding: 0 8px;
    min-height: 118px;
  }

  .stage-hp {
    width: min(40%, 210px);
  }
}

@media (max-width: 760px) {
  .dock {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    margin: 0;
    padding: 7px;
    border-width: 3px;
    border-radius: 18px;
    box-shadow: 3px 3px 0 #0c1b39;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(230, 252, 214, 0.98) 100%);
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  .icon-btn {
    min-width: 0;
    min-height: 60px;
    border-width: 3px;
    border-radius: 14px;
    box-shadow: 2px 2px 0 #0c1b39;
    padding: 7px 2px;
    text-align: center;
  }

  .icon-btn span {
    font-size: 0.82rem;
    line-height: 1.1;
  }

  .icon-btn small {
    display: none;
  }

  .icon-btn:hover {
    transform: none;
  }

  .egg-btn {
    min-width: 0;
    min-height: 60px;
    border-radius: 14px;
    padding: 0;
    transform: none;
  }

  .icon-btn.egg-btn span {
    font-size: 1.32rem;
  }

  .flashcard-wrap {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "scene scene"
      "prev next";
    gap: 8px;
  }

  #flashcard-scene {
    grid-area: scene;
    height: min(57vh, 410px);
  }

  #flash-prev {
    grid-area: prev;
  }

  #flash-next {
    grid-area: next;
  }

  .nav-btn {
    width: 100%;
    height: 44px;
    border-radius: 12px;
    font-size: 1.3rem;
    padding: 0;
  }

  .face {
    padding: 20px;
  }

  .face-front h2 {
    font-size: clamp(1.55rem, 8vw, 2.2rem);
  }

  .face-front p {
    margin-top: 12px;
    font-size: 0.96rem;
  }

  .face-back h3 {
    font-size: 1.35rem;
  }

  .face-back p {
    font-size: 0.98rem;
    margin: 6px 0;
  }

  .action-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
  }

  .word-audio-btn {
    width: 32px;
    min-width: 32px;
    height: 32px;
  }

  .fortress-canvas-wrap {
    min-height: 170px;
  }

  .fortress-head,
  .fortress-angle-text,
  .fortress-msg {
    font-size: 0.82rem;
  }

  .fortress-stats p {
    font-size: 0.77rem;
  }

  .artillery-option {
    min-height: 50px;
    padding: 8px;
    font-size: 0.9rem;
  }

  .shot-btn {
    padding: 7px 5px;
    font-size: 0.88rem;
  }
}

@media (max-width: 520px) {
  .dock {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .icon-btn {
    min-height: 54px;
    padding: 6px 2px;
  }

  .icon-btn span {
    font-size: 0.78rem;
  }

  .topbar h1 {
    font-size: clamp(1.35rem, 8.2vw, 1.82rem);
  }

  .window {
    padding: 8px;
  }

  .word-card {
    padding: 10px;
  }

  .mini-word {
    padding: 7px;
    padding-top: 23px;
  }
}

@media (max-width: 430px) {
  body {
    padding: 10px 8px calc(118px + env(safe-area-inset-bottom, 0px));
  }

  .lang-toggle {
    top: 6px;
    border-width: 3px;
    padding: 6px 8px;
    gap: 6px;
  }

  .lang-pill {
    width: 48px;
    height: 38px;
    border-width: 2px;
    border-radius: 12px;
  }

  .lang-swap {
    font-size: 1.5rem;
  }

  .topbar {
    gap: 8px;
    margin-bottom: 8px;
  }

  .user-panel {
    padding: 7px;
  }

  .user-chip {
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  .window-title {
    font-size: 1rem;
    padding: 5px 11px;
  }

  .status,
  .hint {
    font-size: 0.86rem;
    margin-bottom: 8px;
  }

  .dock {
    left: 6px;
    right: 6px;
    bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 5px;
    padding: 6px;
  }

  .icon-btn {
    min-height: 50px;
    border-width: 2px;
    border-radius: 12px;
    box-shadow: 1px 1px 0 #0c1b39;
  }

  .icon-btn span {
    font-size: 0.74rem;
  }

  .toolbar {
    gap: 5px;
  }

  .word-card {
    border-width: 2px;
    border-radius: 14px;
    box-shadow: 2px 2px 0 #1c305f;
    gap: 7px;
  }

  .word-card h3 {
    font-size: 1.08rem;
  }

  .word-card .furigana {
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .word-card .meaning {
    font-size: 0.95rem;
    line-height: 1.35;
  }

  .meaning-choice-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .meaning-choice-btn {
    min-height: 40px;
    padding: 7px 8px;
    font-size: 0.82rem;
    border-radius: 9px;
  }

  .example-stack {
    border-width: 2px;
    border-radius: 9px;
    padding: 7px;
  }

  .action-row {
    grid-template-columns: 1fr auto;
    gap: 7px;
    align-items: stretch;
  }

  .action-row .list-select {
    min-height: 44px;
  }

  .action-row .add-btn,
  .action-row button {
    min-width: 88px;
  }

  #flashcard-list-select,
  #quiz-list-select,
  #quiz-mode-select {
    min-width: 0;
    flex: 1 1 100%;
  }

  #flashcard-meta {
    width: 100%;
  }

  #flashcard-scene {
    height: min(53vh, 360px);
  }

  .face {
    border-radius: 22px;
    padding: 16px;
  }

  .face-back h3 {
    font-size: 1.2rem;
  }

  .example-jp {
    font-size: 1rem;
  }

  .battle-stage {
    min-height: 168px;
    border-width: 2px;
    border-radius: 10px;
  }

  .stage-hp {
    width: min(46%, 182px);
    padding: 4px;
  }

  .stage-hp p {
    font-size: 0.64rem;
  }

  .fortress-canvas-wrap {
    border-width: 2px;
    border-radius: 10px;
    min-height: 152px;
  }

  .fortress-canvas {
    aspect-ratio: 1240 / 460;
  }
}

@media (max-width: 390px) {
  body {
    padding-left: 7px;
    padding-right: 7px;
  }

  .topbar h1 {
    font-size: clamp(1.2rem, 7.9vw, 1.62rem);
  }

  .topbar p {
    font-size: 0.88rem;
  }

  .window {
    padding: 7px;
    border-radius: 13px;
  }

  .icon-btn span {
    font-size: 0.69rem;
  }

  .icon-btn.egg-btn span {
    font-size: 1.12rem;
  }

  .word-card {
    padding: 9px;
  }

  .word-card h3 {
    font-size: 1rem;
  }

  .word-card .furigana {
    font-size: 0.88rem;
  }

  .word-card .meaning {
    font-size: 0.92rem;
  }

  .meaning-choice-btn {
    min-height: 38px;
    font-size: 0.8rem;
  }

  .mini-word {
    padding: 6px;
    padding-top: 22px;
  }

  .face {
    padding: 14px;
  }

  .face-front h2 {
    font-size: clamp(1.4rem, 8.2vw, 1.9rem);
  }

  .nav-btn {
    height: 40px;
    font-size: 1.18rem;
  }

  .battle-stage {
    min-height: 158px;
  }

  .battle-ground {
    min-height: 106px;
  }

  .fortress-canvas-wrap {
    min-height: 142px;
  }
}
