:root {
  color-scheme: dark;
  --ink: #0c1118;
  --panel: #151d29;
  --panel-2: #202a38;
  --line: #334155;
  --paper: #f8fafc;
  --muted: #9aa8ba;
  --text: #eef5ff;
  --accent: #ffcc3f;
  --accent-2: #31d0aa;
  --danger: #ff5a66;
  --blue: #60a5fa;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 30% 0%, rgba(49, 208, 170, 0.14), transparent 26rem),
    linear-gradient(145deg, #0b1118 0%, #14151f 42%, #101820 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  overflow: hidden;
}

.studio,
.arena {
  min-height: 100vh;
  padding: clamp(12px, 2vw, 24px);
}

.studio-main {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.brand-strip {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.35rem);
  line-height: 0.96;
  max-width: 780px;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
}

.status-pill,
.rarity {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #dce8f8;
  font-size: 0.9rem;
}

.creation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.draw-panel,
.card-panel {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(18, 26, 38, 0.86);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.draw-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr);
  min-height: min(600px, calc(100vh - 136px));
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
}

.tool-btn,
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #263244;
  color: var(--text);
  font-size: 1.25rem;
}

.tool-btn.active,
.icon-btn:hover,
.swatch.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#brushSize {
  width: 120px;
  accent-color: var(--accent);
}

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

.swatch {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  background: var(--swatch);
}

#drawCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background:
    linear-gradient(90deg, rgba(15, 23, 42, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(15, 23, 42, 0.05) 1px, transparent 1px),
    #fbfbf4;
  background-size: 28px 28px;
  touch-action: none;
}

.card-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  min-height: min(600px, calc(100vh - 136px));
}

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

.avatar-preview {
  position: relative;
  display: grid;
  place-items: center;
  height: clamp(138px, 22vh, 210px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 204, 63, 0.16), rgba(49, 208, 170, 0.07)),
    #101923;
  overflow: hidden;
}

.base-card-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.base-card {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-weight: 800;
}

.base-card.active {
  border-color: rgba(255, 204, 63, 0.82);
  background: rgba(255, 204, 63, 0.14);
  color: var(--text);
}

.avatar-preview canvas {
  max-width: 100%;
  max-height: 100%;
}

.avatar-preview span {
  color: rgba(255, 255, 255, 0.35);
  font-size: 6rem;
  font-weight: 900;
}

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

.stats div,
.skill-list article,
.cooldowns div {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.stats div {
  display: flex;
  justify-content: space-between;
  padding: 9px 10px;
  color: var(--muted);
}

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

.skill-list {
  display: grid;
  gap: 10px;
  min-height: 130px;
}

.skill-list p {
  color: var(--muted);
  line-height: 1.6;
}

.skill-list article {
  padding: 9px 10px;
}

.skill-list h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.skill-list span {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

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

.primary-btn,
.secondary-btn {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
  color: #111827;
  font-weight: 900;
}

.primary-btn {
  background: var(--accent);
}

.secondary-btn {
  background: var(--accent-2);
}

.secondary-btn:disabled {
  cursor: default;
  filter: grayscale(1);
  opacity: 0.45;
}

.hidden {
  display: none !important;
}

.arena {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(96, 165, 250, 0.14), transparent 44%),
    #0b1017;
}

.hud,
.battle-controls {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
}

.fighter-hud,
.round-hud,
.battle-controls {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(12, 17, 24, 0.84);
  backdrop-filter: blur(10px);
}

.fighter-hud {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
}

.fighter-hud.enemy {
  text-align: right;
}

.bar {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #2b3443;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #31d0aa, #ffcc3f);
  transition: width 0.16s ease;
}

.enemy .bar i {
  background: linear-gradient(90deg, #ff5a66, #ffcc3f);
}

.round-hud {
  min-width: 130px;
  padding: 10px 16px;
  display: grid;
  justify-items: center;
  gap: 2px;
}

.round-hud strong {
  font-size: 0.82rem;
  color: var(--muted);
}

.round-hud span {
  color: var(--accent);
  font-size: 1.7rem;
  font-weight: 950;
  line-height: 1;
}

#gameCanvas {
  width: 100%;
  min-height: 0;
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: #16202d;
}

.battle-controls {
  grid-template-columns: 1fr auto;
  padding: 10px 12px;
}

.key-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

kbd {
  min-width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: #202a38;
  color: var(--text);
  font-weight: 900;
}

.cooldowns {
  display: flex;
  gap: 8px;
}

.cooldowns div {
  min-width: 90px;
  padding: 7px 9px;
  display: grid;
  gap: 2px;
}

.cooldowns span {
  color: var(--muted);
  font-size: 13px;
}

.cooldowns i {
  color: var(--accent);
  font-style: normal;
  font-weight: 800;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 12, 0.76);
  text-align: center;
}

.overlay h2 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 8vw, 5rem);
}

.overlay p {
  max-width: 520px;
  margin: 0 auto 20px;
  color: var(--muted);
}

@media (max-width: 880px) {
  .creation-grid,
  .hud,
  .battle-controls {
    grid-template-columns: 1fr;
  }

  .draw-panel,
  .card-panel {
    min-height: auto;
  }

  .draw-panel {
    height: 620px;
  }

  .brand-strip {
    align-items: start;
    flex-direction: column;
  }

  .card-panel {
    padding: 14px;
  }

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

  .cooldowns {
    justify-content: stretch;
  }

  .cooldowns div {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .studio,
  .arena {
    padding: 10px;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  #brushSize {
    flex: 1;
    min-width: 110px;
  }

  .action-row,
  .stats {
    grid-template-columns: 1fr;
  }
}

/* Pointer controls use the existing game's keyboard actions. */
.touch-controls { display: none; }
@media (pointer: coarse), (max-width: 760px) {
  .key-row { display: none; }
  .touch-controls { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
  .touch-controls button { min-width: 0; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--text); font-size: 14px; font-weight: 700; touch-action: none; user-select: none; -webkit-user-select: none; }
  .touch-controls button.is-held { background: var(--accent); color: var(--ink); }
  .battle-controls { grid-template-columns: 1fr; }
}

/* Keep portfolio navigation outside the product canvas and controls. */
.portfolio-return-bar { min-height: 52px; padding: 3px 16px; border-bottom: 1px solid var(--line); }
.portfolio-return-bar a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 8px; color: inherit; font: 500 14px/1.4 system-ui, -apple-system, "PingFang SC", sans-serif; text-decoration: none; border-radius: 8px; }
.portfolio-return-bar a:hover { text-decoration: underline; text-underline-offset: 4px; }
.portfolio-return-bar a:focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
button { min-height: 44px; min-width: 44px; }
input, textarea, select { font-size: 16px; }
label { font-size: 14px; }
.portfolio-return-bar { background: rgba(12, 17, 24, .65); }
.tool-btn, .icon-btn, .swatch { width: 44px; height: 44px; flex-shrink: 0; }

/* Six actions stay thumb-sized on narrow phones without squeezing the arena. */
@media (max-width: 360px) {
  .arena { min-height: calc(100dvh - 52px); }
  .touch-controls { grid-template-columns: repeat(3, minmax(44px, 1fr)); }
  .touch-controls button { min-width: 44px; min-height: 48px; }
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .fighter-hud { min-width: 0; padding: 8px; font-size: 13px; }
  .fighter-hud.enemy { grid-column: 2; grid-row: 1; }
  .round-hud { grid-column: 1 / -1; grid-row: 2; min-width: 0; display: flex; justify-content: center; gap: 10px; padding: 5px 12px; }
  .round-hud span { font-size: 24px; }
  #gameCanvas { height: auto; aspect-ratio: 16 / 9; align-self: start; }
  .cooldowns div { padding: 5px 8px; }
}
