:root {
  --bg: #0f1216;
  --bg-soft: #181e25;
  --text: #ececec;
  --muted: #9ca6b5;
  --accent: #2f83ff;
  --line: #2f3845;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 18% 15%, #1b2838 0%, transparent 30%), var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

body.layout-preview .card-zone {
  display: none;
}

.deck-app {
  --footer-h: 220px;
  height: 100%;
  padding: max(0.9rem, env(safe-area-inset-top)) 1rem 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.deck-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.back-link {
  text-decoration: none;
  color: #b9c0ca;
  font-size: 1rem;
}

.icon-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: #e3e7ed;
  padding: 0.35rem 0.65rem;
  font-size: 1.1rem;
  cursor: pointer;
}

.deck-meta {
  margin-top: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.primary-btn,
.ghost-btn {
  border: 0;
  border-radius: 999px;
  padding: 0.42rem 0.78rem;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  cursor: pointer;
}

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

.ghost-btn {
  background: transparent;
  color: #d7dbe2;
  border: 1px solid var(--line);
}

.progress-text {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.card-zone {
  flex: 1;
  margin-top: 0.75rem;
  min-height: 0;
  padding: 0.25rem 0;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  align-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.card-image {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 2.5 / 3.5;
  object-fit: contain;
  border-radius: clamp(12px, 2vw, 24px);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.34),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: transform 220ms ease;
}

.card-image.draw-anim {
  animation: cardDraw 360ms ease;
}

@keyframes cardDraw {
  0% {
    transform: rotateY(76deg) scale(0.92);
    opacity: 0.35;
  }
  65% {
    transform: rotateY(-8deg) scale(1.02);
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg) scale(1);
    opacity: 1;
  }
}

.card-hint {
  position: absolute;
  bottom: 9%;
  color: #d9da9b;
  font-size: clamp(1.3rem, 4.4vw, 2.2rem);
  font-weight: 700;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.55);
  display: none;
}

.card-zone.active .card-hint {
  visibility: hidden;
}

.task-hint {
  position: absolute;
  top: 6%;
  background: rgba(0, 0, 0, 0.6);
  color: #f0f2f6;
  padding: 0.36rem 0.65rem;
  border-radius: 999px;
  font-size: clamp(0.85rem, 2vw, 1.05rem);
  font-weight: 600;
  max-width: min(92vw, 580px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 220ms ease;
}

.task-hint.visible {
  opacity: 1;
}

.history-wrap {
  position: static;
  width: 100%;
  margin-inline: auto;
  padding-bottom: 0;
  margin-top: auto;
  z-index: 8;
  display: none;
}

.history-title {
  margin: 0 0 0.02rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.history-strip {
  --gap: 0.06rem;
  --rows: 4;
  --board-cell-w: calc((100% - (12 * var(--gap))) / 13);
  --board-cell-h: min(calc(var(--board-cell-w) * 1.4), 56px);
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: var(--gap);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  grid-template-rows: repeat(var(--rows), var(--board-cell-h));
  min-height: calc((var(--rows) * var(--board-cell-h)) + ((var(--rows) - 1) * var(--gap)));
  height: calc((var(--rows) * var(--board-cell-h)) + ((var(--rows) - 1) * var(--gap)));
  overflow: hidden;
  width: 100%;
  margin-inline: auto;
}

.history-strip.scrollable {
  max-height: 24vh;
  overflow-y: auto;
}

.history-card {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
  border: 0;
  background: transparent;
  opacity: 0;
  transition: opacity 180ms ease;
  transform: none;
  transform-origin: center center;
  box-shadow: none;
  justify-self: stretch;
  align-self: stretch;
}

.history-card.revealed {
  opacity: 1;
  border: 0;
  background: transparent;
}

.history-card.reveal-pop {
  animation: none;
}

.settings-panel {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: min(92vw, 360px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(20, 25, 32, 0.97);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45);
  padding: 1rem;
  z-index: 30;
  display: none;
}

.settings-panel.open {
  display: block;
}

.settings-panel h2 {
  margin: 0 0 0.7rem;
}

.settings-panel label {
  display: block;
  margin: 0.5rem 0 0.22rem;
  font-size: 0.92rem;
  color: #cad2dd;
}

.settings-panel input,
.settings-panel select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: #11161d;
  color: #eef1f6;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88rem;
}

.settings-actions {
  margin-top: 0.9rem;
  display: flex;
  gap: 0.45rem;
}

.complete-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  background: rgba(8, 10, 14, 0.82);
  backdrop-filter: blur(2px);
}

.complete-overlay.visible {
  display: flex;
}

.complete-card {
  position: relative;
  z-index: 2;
  width: min(90vw, 420px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(24, 33, 44, 0.98);
  padding: 1.1rem;
  text-align: center;
}

.complete-card h2 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 4.2vw, 2.1rem);
}

.complete-card p {
  margin: 0 0 0.85rem;
  color: #cad1db;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0.25;
  }
}

@media (max-width: 780px) {
  .card-image {
    max-width: 98%;
    max-height: 98%;
  }

  .card-zone {
    padding-bottom: 0;
  }

  .history-card {
    border-radius: 3px;
  }

  .history-strip {
    --gap: 0.03rem;
    --board-cell-h: min(calc(var(--board-cell-w) * 1.38), 50px);
    gap: 0.03rem;
  }

  .history-wrap {
    width: 100%;
  }

  .history-strip.scrollable {
    max-height: 20vh;
  }
}
