:root {
  color-scheme: light;
  --table-bg: radial-gradient(circle at top, #2a6a4b 0%, #0e3b2c 70%);
  --card-width: clamp(160px, 40vw, 240px);
  --card-height: calc(var(--card-width) * 1.4);
  --card-radius: 14px;
  --shadow: 0 18px 30px rgba(0, 0, 0, 0.3);
  --shadow-soft: 0 8px 16px rgba(0, 0, 0, 0.2);
  --accent: #f3c76a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--table-bg);
  color: #fdf6e3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: min(900px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 2.5rem 1rem 3rem;
}

.header {
  text-align: center;
}

h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.subtitle {
  margin: 0;
  opacity: 0.85;
}

.deck-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.deck-button {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  outline-offset: 6px;
}

.deck-button:focus-visible {
  outline: 3px solid var(--accent);
}

.deck-button[disabled] {
  cursor: not-allowed;
  opacity: 0.7;
}

.deck-stack {
  position: relative;
  width: var(--card-width);
  height: var(--card-height);
}

.deck-stack::before,
.deck-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  background: rgba(0, 0, 0, 0.15);
  box-shadow: var(--shadow-soft);
  transform: translate(10px, -10px);
  z-index: 0;
}

.deck-stack::after {
  transform: translate(5px, -5px);
  opacity: 0.8;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  z-index: 1;
}

.card.is-flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  backface-visibility: hidden;
  overflow: hidden;
  background: #fefefe;
  display: grid;
  place-items: center;
}

.card-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-back {
  background: #fff;
}

.card-back.fallback {
  background: linear-gradient(135deg, #a31621, #d72a32);
  position: relative;
}

.card-back.fallback::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: calc(var(--card-radius) - 6px);
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.card-back.fallback::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: calc(var(--card-radius) - 12px);
  border: 1px dashed rgba(255, 255, 255, 0.7);
}

.card-front {
  transform: rotateY(180deg);
}

.deck-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.counter {
  margin: 0;
  font-weight: 600;
}

.status {
  margin: 0;
  min-height: 1.4rem;
}

.reset-button {
  padding: 0.65rem 1.4rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #2a1b00;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.reset-button:hover {
  filter: brightness(1.05);
}

.log-section {
  width: min(520px, 90vw);
  text-align: center;
}

.log-region {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  max-height: 220px;
  overflow-y: auto;
  text-align: left;
}

.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.5rem;
}

.log-entry {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.log-entry .red {
  color: #ffb0b0;
}

.footer {
  width: min(720px, 92vw);
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.85;
}

.footer p {
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

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

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
}
