:root {
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-2: rgba(255, 255, 255, 0.92);
  --line: rgba(25, 32, 45, 0.1);
  --text: #172033;
  --muted: #697386;
  --cyan: #00a7c8;
  --blue: #007aff;
  --violet: #7b61ff;
  --gold: #ffb020;
  --pink: #ff2d8f;
  --danger: #ff3b30;
  --green: #34c759;
  --yellow: #ffcc00;
  --red: #ff3b30;
}

html,
body {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 14%, rgba(0, 122, 255, 0.16), transparent 30%),
    radial-gradient(circle at 86% 8%, rgba(255, 45, 143, 0.12), transparent 26%),
    linear-gradient(135deg, #fbfcff 0%, #edf2f8 48%, #f9fbff 100%);
}

button {
  font: inherit;
}

.app {
  width: min(1180px, calc(100% - 24px));
  height: 100dvh;
  margin: 0 auto;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
  margin-bottom: 12px;
}

main {
  flex: 1;
  min-height: 0;
}

.top-actions,
.wide-actions,
.menu-actions {
  display: flex;
  gap: 10px;
  min-width: 0;
}

.top-actions {
  justify-content: flex-start;
}

.topbar > .btn {
  justify-self: end;
}

.title-block {
  text-align: center;
}

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

h1 {
  margin-bottom: 1px;
  font-size: clamp(1.8rem, 4vw, 3rem);
  letter-spacing: 0;
  color: #111827;
  text-shadow: 0 8px 28px rgba(0, 122, 255, 0.14);
}

.title-block p {
  margin-bottom: 0;
  color: var(--muted);
}

.btn {
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  padding: 10px 16px;
  min-height: 40px;
  font-weight: 800;
  background: #fff;
  box-shadow: 0 10px 28px rgba(18, 32, 56, 0.12);
  transition: transform 0.18s ease, filter 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  filter: brightness(1.12);
  box-shadow: 0 14px 32px rgba(18, 32, 56, 0.16);
}

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

.btn-cyan { background: linear-gradient(135deg, #00a7c8, #4cd9f0); }
.btn-blue { background: linear-gradient(135deg, #007aff, #5ac8fa); }
.btn-violet { background: linear-gradient(135deg, #6f5cff, #af9cff); }
.btn-gold { background: linear-gradient(135deg, #ffb020, #ffd166); color: #2a1b00; }
.btn-pink { background: linear-gradient(135deg, #ff2d8f, #ff7ac5); }
.btn-danger { background: linear-gradient(135deg, #ff3b30, #ff7b72); }

.battle-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.monster-card {
  min-height: 0;
  height: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.54)),
    rgba(255, 255, 255, 0.72);
  box-shadow: 0 22px 60px rgba(54, 73, 104, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(18px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: cardIn 0.42s ease both;
}

.player-card {
  border-color: rgba(0, 122, 255, 0.2);
}

.enemy-card {
  border-color: rgba(255, 176, 32, 0.22);
}

.player-card.mega {
  border-color: rgba(255, 45, 143, 0.6);
  box-shadow: 0 0 0 5px rgba(255, 45, 143, 0.1), 0 22px 60px rgba(255, 45, 143, 0.18);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card-head h2 {
  margin-bottom: 6px;
  font-size: clamp(1.15rem, 2.4vw, 1.7rem);
}

.level-box,
.type-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 10px;
  min-height: 30px;
  color: #152033;
  font-weight: 900;
  background: rgba(255, 176, 32, 0.22);
}

.type-pill {
  color: #344054;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.sprite {
  display: grid;
  place-items: center;
  flex: 1 1 120px;
  min-height: 92px;
  margin: 10px 0;
  border-radius: 24px;
  font-size: clamp(4rem, 10vw, 7.5rem);
  background:
    radial-gradient(circle at 50% 58%, rgba(0, 122, 255, 0.1), transparent 44%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(239, 244, 250, 0.7));
  text-shadow: 0 16px 28px rgba(54, 73, 104, 0.18);
  animation: floatSprite 3.8s ease-in-out infinite;
}

.meter-block {
  margin-top: 9px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.95rem;
}

.meter-label strong {
  color: var(--text);
}

.hp-shell,
.xp-shell {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(105, 115, 134, 0.14);
  box-shadow: inset 0 1px 4px rgba(18, 32, 56, 0.08);
}

.hp-fill,
.xp-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.2s ease;
}

.xp-fill {
  width: 0;
  background: linear-gradient(90deg, #007aff, #7b61ff);
}

.hp-fill.flash {
  filter: brightness(2);
}

.effects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 31px;
  margin: 12px 0;
}

.effect-tag {
  border: 1px solid rgba(25, 32, 45, 0.08);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.8rem;
}

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

.attack-btn {
  min-height: 70px;
  padding: 9px;
  border-radius: 18px;
  text-align: left;
  border: 1px solid rgba(25, 32, 45, 0.08);
  color: var(--text);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 24px rgba(54, 73, 104, 0.1);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.attack-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 30px rgba(54, 73, 104, 0.14);
}

.attack-btn strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.attack-btn span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.attack-btn:disabled {
  opacity: 0.43;
  cursor: not-allowed;
}

.wide-actions {
  margin-top: 9px;
}

.wide-actions .btn {
  flex: 1;
}

.enemy-note {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-weight: 700;
}

.log-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  width: min(360px, calc(100vw - 36px));
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
}

.log-panel h3 {
  display: none;
}

.combat-log {
  display: flex;
  flex-direction: column;
  gap: 9px;
  height: auto;
  overflow: visible;
  padding: 0;
}

.log-line {
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 18px;
  color: #172033;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 16px 42px rgba(54, 73, 104, 0.18);
  backdrop-filter: blur(18px);
  animation: toastIn 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 18px;
  overflow: hidden;
  background: rgba(245, 247, 251, 0.72);
  backdrop-filter: blur(12px);
}

.modal.active {
  display: grid;
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-width: calc(100vw - 24px);
  max-height: min(780px, 92vh);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 30px 80px rgba(54, 73, 104, 0.22);
  backdrop-filter: blur(18px);
}

#menuModal .modal-card {
  width: min(560px, 100%);
}

#menuModal .menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#menuModal .menu-actions .btn {
  width: 100%;
  min-width: 0;
  white-space: normal;
  line-height: 1.2;
}

#menuModal .help-box {
  overflow-wrap: anywhere;
}

.large-modal {
  width: min(900px, 100%);
}

.muted {
  color: var(--muted);
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.82);
  font-size: 1.5rem;
  line-height: 1;
}

.starter-grid,
.dex-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.choice-card,
.dex-card,
.list-item {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.choice-card {
  cursor: pointer;
  text-align: center;
}

.choice-card:hover {
  outline: 2px solid rgba(0, 122, 255, 0.35);
}

.choice-card .mini-sprite {
  font-size: 4rem;
  margin: 8px 0;
}

.list-stack {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.list-item p {
  margin-bottom: 0;
  color: var(--muted);
}

.ether-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.hidden {
  display: none;
}

.help-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  line-height: 1.5;
}

.ending-stats {
  display: grid;
  gap: 8px;
  margin: 14px 0 18px;
  color: var(--muted);
}

.shake {
  animation: shake 0.34s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}

@keyframes logIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes floatSprite {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
  }

  .top-actions,
  .topbar > .btn,
  .title-block {
    justify-self: initial;
  }

  .top-actions,
  .topbar > .btn {
    justify-content: flex-start;
  }

  .starter-grid,
  .dex-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .battle-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
  }

  .monster-card {
    padding: 10px;
    border-radius: 22px;
  }

  .sprite {
    min-height: 76px;
    margin: 7px 0;
    font-size: clamp(3.2rem, 11vw, 5.5rem);
  }

  h1 {
    font-size: clamp(1.35rem, 5vw, 2rem);
  }

  .title-block p,
  .meter-label,
  .attack-btn span,
  .effect-tag,
  .enemy-note {
    font-size: 0.72rem;
  }

  .btn {
    min-height: 34px;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .top-actions {
    gap: 6px;
  }

  .attack-grid {
    gap: 6px;
  }

  .attack-btn {
    min-height: 58px;
    padding: 7px;
    border-radius: 14px;
  }

  .attack-btn strong {
    font-size: 0.82rem;
  }

  .effects {
    min-height: 25px;
    margin: 7px 0;
  }

  .xp-wrap {
    display: none;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 10px, 1180px);
    padding: 8px 0;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .title-block {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .top-actions {
    grid-column: 1;
    grid-row: 2;
  }

  .topbar > .btn {
    grid-column: 2;
    grid-row: 2;
  }

  .battle-grid {
    gap: 7px;
  }

  .monster-card {
    padding: 8px;
    border-radius: 18px;
  }

  .card-head {
    gap: 6px;
  }

  .card-head h2 {
    margin-bottom: 3px;
    font-size: 0.98rem;
  }

  .level-box,
  .type-pill {
    min-height: 24px;
    padding: 4px 7px;
    font-size: 0.68rem;
  }

  .sprite {
    min-height: 58px;
    font-size: clamp(2.7rem, 12vw, 4.2rem);
  }

  .hp-shell,
  .xp-shell {
    height: 9px;
  }

  .attack-btn {
    min-height: 52px;
  }

  .wide-actions {
    gap: 6px;
  }

  .enemy-note {
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
  }

  .log-panel {
    right: 10px;
    bottom: 10px;
    width: min(310px, calc(100vw - 20px));
  }

  #menuModal .modal-card {
    padding: 18px;
  }

  #menuModal .menu-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .starter-grid,
  .dex-grid {
    grid-template-columns: 1fr;
  }

  .list-item {
    flex-direction: column;
  }

  .top-actions .btn {
    padding-left: 8px;
    padding-right: 8px;
  }

  .attack-btn span:last-child {
    display: none;
  }
}
