:root {
  --bg-void: #000000;
  --panel: rgba(7, 16, 30, 0.82);
  --line: rgba(168, 224, 255, 0.3);
  --line-soft: rgba(168, 224, 255, 0.16);
  --text: #ecf6ff;
  --muted: #abd0e8;
  --gold: #ffd98d;
  --cyan: #88ecff;
  --mint: #a5ffd8;
  --focus: #f2fbff;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.48);
  --radius-lg: 22px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", "Gill Sans", sans-serif;
  background: var(--bg-void);
}

body {
  position: relative;
  overflow-x: hidden;
  line-height: 1.3;
}

.page-bg {
  position: fixed;
  inset: 0;
  background: #000000;
  z-index: -3;
}

.page-bg::before,
.page-bg::after {
  content: none;
}

.app {
  width: min(980px, calc(100% - 1.1rem));
  margin: 0.7rem auto 1rem;
  display: grid;
  gap: 0.82rem;
  padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
}

.reveal {
  animation: riseIn 420ms ease both;
}

.reveal:nth-child(2) {
  animation-delay: 45ms;
}

.reveal:nth-child(3) {
  animation-delay: 95ms;
}

@keyframes riseIn {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: linear-gradient(165deg, rgba(13, 27, 48, 0.88), rgba(6, 14, 27, 0.88));
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", "Iowan Old Style", serif;
  letter-spacing: 0.02em;
}

h2 {
  font-size: 1.1rem;
}

h3 {
  font-size: 0.96rem;
}

.topbar {
  padding: 0.6rem 0.72rem;
  display: flex;
  justify-content: center;
}

.title-brand {
  position: relative;
  min-height: 78px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(177, 226, 255, 0.26);
  background: rgba(5, 11, 22, 0.55);
  display: grid;
  place-items: center;
  padding: 0.35rem 0.75rem;
}

.title-crest {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.68;
  filter: saturate(1.06) contrast(1.04);
}

h1 {
  position: relative;
  z-index: 1;
  font-size: clamp(1.65rem, 4.4vw, 2.45rem);
  letter-spacing: 0.08em;
  color: #f3fbff;
  text-shadow:
    0 0 14px rgba(142, 236, 255, 0.78),
    0 2px 10px rgba(0, 0, 0, 0.45);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  justify-items: center;
}

.board-panel {
  width: min(760px, 100%);
}

.board-panel {
  padding: 0.76rem;
  display: grid;
  gap: 0.52rem;
}

.board-frame {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(178, 226, 255, 0.27);
  height: clamp(430px, 70vh, 760px);
  background: radial-gradient(circle at 65% 5%, rgba(168, 240, 255, 0.24), transparent 42%), #040912;
}

#game-canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: linear-gradient(180deg, rgba(8, 14, 30, 0.52), rgba(4, 8, 18, 0.8));
}

.hud-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.hud-strip {
  position: absolute;
  top: 0.56rem;
  left: 0.56rem;
  display: flex;
  gap: 0.4rem;
}

.hud-chip {
  min-width: 84px;
  border-radius: 10px;
  border: 1px solid rgba(179, 229, 255, 0.28);
  background: linear-gradient(155deg, rgba(10, 20, 39, 0.82), rgba(8, 15, 28, 0.68));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
  padding: 0.3rem 0.46rem;
}

.hud-chip span {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #abd4ea;
}

.hud-chip strong {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.hud-mana {
  position: absolute;
  top: 0.56rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, calc(100% - 18rem));
  border-radius: 10px;
  border: 1px solid rgba(186, 233, 255, 0.3);
  background: linear-gradient(155deg, rgba(10, 22, 41, 0.84), rgba(8, 17, 32, 0.7));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  padding: 0.34rem 0.46rem 0.38rem;
}

.hud-mana.ready {
  border-color: rgba(173, 251, 235, 0.66);
  box-shadow:
    0 0 18px rgba(121, 243, 223, 0.34),
    0 10px 24px rgba(0, 0, 0, 0.35);
}

.next-piece {
  position: absolute;
  top: 0.56rem;
  right: 0.56rem;
  width: 104px;
  border-radius: 12px;
  border: 1px solid rgba(170, 225, 252, 0.28);
  background: linear-gradient(155deg, rgba(10, 20, 39, 0.84), rgba(7, 15, 29, 0.72));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.36);
  padding: 0.4rem 0.38rem 0.34rem;
  text-align: center;
}

.next-piece h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #b9ddf2;
  margin-bottom: 0.2rem;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: linear-gradient(165deg, rgba(4, 8, 16, 0.58), rgba(3, 7, 15, 0.82));
  display: none;
  justify-content: center;
  align-items: center;
  padding: 0.9rem;
}

.overlay.active {
  display: flex;
}

.overlay-card {
  width: min(480px, 100%);
  border-radius: 16px;
  border: 1px solid rgba(186, 231, 255, 0.42);
  background:
    radial-gradient(620px 240px at 10% 4%, rgba(123, 228, 255, 0.2), transparent 54%),
    radial-gradient(530px 200px at 100% 100%, rgba(255, 216, 142, 0.16), transparent 58%),
    rgba(11, 22, 42, 0.93);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.5);
  padding: 0.95rem;
  text-align: center;
}

.overlay-card h2 {
  margin-bottom: 0.36rem;
}

.overlay-card p {
  margin: 0.4rem 0;
  color: var(--muted);
  white-space: pre-line;
}

.overlay-actions {
  margin-top: 0.76rem;
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.overlay-hint {
  font-size: 0.8rem;
}

.meter-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #c6e8fb;
  margin-bottom: 0.18rem;
}

.meter {
  height: 11px;
  border-radius: 999px;
  border: 1px solid rgba(186, 233, 255, 0.34);
  background: rgba(5, 12, 26, 0.84);
  overflow: hidden;
}

.meter-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #67cfff 0%, #8bffff 65%, #fff2b2 100%);
  box-shadow: 0 0 15px rgba(116, 232, 255, 0.7);
  transition: width 160ms ease;
}

#next-canvas {
  width: 62px;
  height: 78px;
}

.btn {
  border: 1px solid rgba(176, 226, 255, 0.32);
  border-radius: 11px;
  background: linear-gradient(160deg, rgba(18, 42, 74, 0.88), rgba(9, 22, 41, 0.93));
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
  min-height: 36px;
  padding: 0.4rem 0.72rem;
  font-size: 0.84rem;
}

.btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.btn-primary {
  background: linear-gradient(145deg, rgba(127, 230, 255, 0.33), rgba(57, 161, 223, 0.37));
  border-color: rgba(173, 238, 255, 0.72);
}

.btn-ghost {
  background: rgba(11, 27, 47, 0.78);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.12);
  transform: none;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 780px) {
  .app {
    width: min(100%, calc(100% - 0.54rem));
    margin: 0.34rem auto 0.8rem;
  }

  .topbar {
    padding: 0.52rem;
  }

  .title-brand {
    min-height: 70px;
  }

  .board-panel {
    padding: 0.56rem;
  }

  .board-frame {
    height: clamp(420px, 66vh, 640px);
    height: clamp(420px, 66svh, 640px);
  }

  .hud-strip {
    top: 0.44rem;
    left: 0.44rem;
    gap: 0.3rem;
  }

  .hud-chip {
    min-width: 66px;
    padding: 0.22rem 0.34rem;
  }

  .hud-chip span {
    font-size: 0.54rem;
  }

  .hud-chip strong {
    font-size: 0.8rem;
  }

  .hud-mana {
    top: auto;
    bottom: 0.44rem;
    transform: none;
    left: 0.44rem;
    right: 0.44rem;
    width: auto;
    padding: 0.3rem 0.42rem 0.34rem;
  }

  .next-piece {
    top: 0.44rem;
    right: 0.44rem;
    width: 82px;
    padding: 0.3rem 0.24rem 0.26rem;
  }

  .next-piece h2 {
    font-size: 0.62rem;
  }

  #next-canvas {
    width: 50px;
    height: 66px;
  }

  .overlay-card {
    padding: 0.8rem 0.76rem;
  }

  .overlay-hint {
    font-size: 0.74rem;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 0.46rem;
  }

  .title-brand {
    min-height: 64px;
    padding: 0.3rem 0.58rem;
  }

  h1 {
    font-size: clamp(1.44rem, 8vw, 2rem);
  }

  .board-panel {
    padding: 0.48rem;
  }

  .board-frame {
    height: clamp(430px, 70vh, 620px);
    height: clamp(430px, 70svh, 620px);
  }

  .hud-strip {
    gap: 0.24rem;
  }

  .hud-chip {
    min-width: 60px;
    padding: 0.2rem 0.3rem;
  }

  .hud-chip span {
    font-size: 0.5rem;
  }

  .hud-chip strong {
    font-size: 0.74rem;
  }

  .next-piece {
    width: 74px;
    padding: 0.25rem 0.2rem 0.24rem;
  }

  #next-canvas {
    width: 46px;
    height: 62px;
  }

  .hud-mana {
    left: 0.38rem;
    right: 0.38rem;
    bottom: 0.38rem;
    padding: 0.26rem 0.38rem 0.3rem;
  }

  .meter-label-row {
    font-size: 0.62rem;
    margin-bottom: 0.14rem;
  }

  .meter {
    height: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
