:root {
  --color-black: #07070b;
  --color-ink: #10121c;
  --color-panel: rgba(10, 12, 24, 0.82);
  --color-panel-strong: rgba(15, 17, 31, 0.94);
  --color-purple: #442178;
  --color-blue: #073f7c;
  --color-cyan: #60d8ff;
  --color-gold: #ffd76a;
  --color-gold-strong: #ffe794;
  --color-muted: #b8bed8;
  --color-border: rgba(255, 215, 106, 0.24);
  --shadow-panel: 0 24px 70px rgba(0, 0, 0, 0.45);
  --radius: 8px;
  --focus-ring: 0 0 0 3px rgba(255, 215, 106, 0.36);
  --font-body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--color-black);
}

body {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: #f6f1dc;
  font-family: var(--font-body);
  background:
    linear-gradient(135deg, #050506 0%, #16102f 48%, #071f3f 100%);
  isolation: isolate;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url("assets/energia.png") center 48% / min(68vw, 620px) auto no-repeat;
  filter: brightness(0.55) saturate(0.9);
  mix-blend-mode: screen;
  opacity: 0.14;
}

button {
  font: inherit;
}

button {
  border: 0;
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 28px 0 34px;
}

.app-shell.is-finished {
  display: grid;
  align-content: center;
}

.app-shell.is-finished .app-header {
  display: none;
}

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

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--color-cyan);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--color-gold);
  font-weight: 850;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 7vw, 4.7rem);
  line-height: 0.95;
}

h2 {
  font-size: clamp(1.35rem, 3vw, 2.5rem);
  line-height: 1.05;
}

.scorebar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.metric {
  display: grid;
  gap: 4px;
  min-width: 120px;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: rgba(9, 10, 18, 0.62);
}

.metric span {
  color: var(--color-muted);
  font-size: 0.78rem;
}

.metric strong {
  color: var(--color-gold-strong);
  font-size: 1.35rem;
  line-height: 1;
}

.control-button {
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-gold);
  background: linear-gradient(180deg, rgba(22, 24, 39, 0.96), rgba(8, 9, 15, 0.96));
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.control-button:hover {
  border-color: rgba(255, 215, 106, 0.56);
  background: linear-gradient(180deg, rgba(31, 34, 54, 0.98), rgba(12, 13, 24, 0.98));
}

.control-button:active {
  transform: translateY(1px);
}

.control-button:focus-visible,
.piece:focus-visible {
  outline: 0;
  box-shadow: var(--focus-ring);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(380px, 1.2fr);
  gap: clamp(18px, 3vw, 34px);
  align-items: start;
}

.game-layout:not(.is-complete) {
  grid-template-columns: minmax(280px, 1fr);
  justify-items: center;
}

.game-layout.is-complete {
  grid-template-columns: minmax(300px, 980px);
  justify-content: center;
}

.board-panel,
.completion-panel {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-panel);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(16px);
}

.board-panel {
  display: grid;
  gap: 18px;
  justify-items: center;
  padding: clamp(16px, 3vw, 24px);
}

.game-layout:not(.is-complete) .board-panel {
  width: min(100%, 560px);
}

.game-layout.is-complete .board-panel {
  display: none;
}

.panel-heading {
  width: 100%;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.status-message {
  min-height: 1.25rem;
  margin: 0;
  color: var(--color-muted);
  font-size: 0.95rem;
  text-align: right;
}

.puzzle-board {
  --board-ratio: 9 / 16;
  --rows: 6;
  --cols: 6;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: auto;
  height: min(72dvh, 690px);
  max-width: 100%;
  aspect-ratio: var(--board-ratio);
  overflow: hidden;
  border: 1px solid rgba(255, 215, 106, 0.3);
  border-radius: var(--radius);
  background: #050506;
}

.piece {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-right: 1px solid rgba(255, 215, 106, 0.22);
  border-bottom: 1px solid rgba(255, 215, 106, 0.22);
  background-color: #111;
  background-repeat: no-repeat;
  cursor: grab;
  transition: filter 130ms ease, transform 130ms ease, box-shadow 130ms ease;
  touch-action: manipulation;
}

.piece:hover {
  filter: brightness(1.12);
}

.piece:active {
  cursor: grabbing;
}

.piece.is-selected,
.piece.is-drop-target {
  z-index: 2;
  box-shadow: inset 0 0 0 3px var(--color-gold), 0 0 18px rgba(255, 215, 106, 0.34);
}

.piece.is-locked {
  cursor: default;
  filter: saturate(0.94);
}

.completion-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.92fr) minmax(280px, 1.08fr);
  gap: 0;
  overflow: hidden;
  background: var(--color-panel-strong);
}

.final-image-frame {
  margin: 0;
  min-height: 100%;
  background: #050506;
}

.final-image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  object-fit: cover;
}

.poem-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  min-height: 420px;
  padding: clamp(20px, 4vw, 34px);
}

.poem-text {
  width: 100%;
  border: 1px solid rgba(255, 215, 106, 0.28);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 24px);
  color: #fff8df;
  background: rgba(2, 3, 8, 0.58);
  font-size: clamp(1rem, 1.45vw, 1.18rem);
  line-height: 1.7;
}

.poem-text p {
  margin: 0;
}

.poem-text p + p {
  margin-top: 0.25em;
}

.noscript-message {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 320px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-gold);
  background: var(--color-panel-strong);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100% - 22px, 680px);
    padding-top: 18px;
  }

  .app-header,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .scorebar {
    width: 100%;
    justify-content: space-between;
  }

  .metric {
    flex: 1;
  }

  .game-layout,
  .game-layout.is-complete {
    grid-template-columns: 1fr;
  }

  .puzzle-board {
    height: min(64dvh, 600px);
  }

  .status-message {
    text-align: left;
  }

  .completion-panel {
    grid-template-columns: 1fr;
  }

  .final-image-frame img,
  .poem-panel {
    min-height: 320px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: min(100% - 16px, 420px);
  }

  h1 {
    font-size: clamp(2rem, 14vw, 3.1rem);
  }

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

  .control-button {
    padding: 0 14px;
  }

  .board-panel {
    padding: 12px;
  }

  .puzzle-board {
    height: min(61dvh, 520px);
  }
}
