:root {
  color-scheme: dark;
  --orange: #ff9a1f;
  --press-glow: rgba(255, 94, 0, 0.95);
  --draw-glow: rgba(255, 69, 0, 0.95);
  --card-w: 240px;
  --card-h: 360px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #050403;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  font-family: Baskerville, "Baskerville Old Face", "Times New Roman", Georgia, serif;
  overflow-x: hidden;
}

button {
  font: inherit;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  padding:
    max(16px, env(safe-area-inset-top))
    20px
    max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  background:
    linear-gradient(rgba(0, 0, 0, 0.04), rgba(0, 0, 0, 0.04)),
    url("assets/images/background.jpg") center center / cover fixed no-repeat;
}

.app-header {
  text-align: center;
  flex: 0 0 auto;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.12;
  font-weight: 700;
  color: var(--orange);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}

.app-header p {
  margin: 3px 0 10px;
  font-size: 18px;
  line-height: 1.2;
  color: var(--orange);
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.9);
}

.card-stage {
  position: relative;
  width: calc(var(--card-w) + 20px);
  height: calc(var(--card-h) + 20px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  overflow: visible;
}

.card-scene {
  width: var(--card-w);
  height: var(--card-h);
  perspective: 1000px;
  position: relative;
  z-index: 2;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 600ms ease;
}

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

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.card-glow {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  object-fit: contain;
  transform: scale(2.4);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.card-glow.flash {
  animation: card-glow-flash 800ms ease-out;
}

@keyframes card-glow-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  margin-top: 5px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 110px);
  justify-content: center;
  gap: 4px;
  padding: 10px 20px 0;
  margin: 5px 0;
  overflow: visible;
}

.category-button {
  position: relative;
  width: 110px;
  height: 60px;
  padding: 2px;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: visible;
  touch-action: manipulation;
}

.category-button::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 12px;
  background: rgba(255, 94, 0, 0.9);
  filter: blur(19px);
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
  transition: opacity 200ms ease-out;
}

.category-button.pressing::before {
  opacity: 1;
  transition-duration: 0ms;
}

.category-art {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  background: url("assets/images/button_parchment.png") center / 100% 100% no-repeat;
  color: #000;
  font-size: 18px;
  line-height: 1;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.category-button.selected .category-art {
  color: orange;
  font-weight: 700;
  opacity: 0.9;
}

.draw-button {
  position: relative;
  width: 280px;
  height: 70px;
  margin-top: 10px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: visible;
  touch-action: manipulation;
}

.draw-button-glow {
  position: absolute;
  inset: 9px 12px;
  border-radius: 16px;
  background: rgba(255, 69, 0, 0.95);
  filter: blur(28px);
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
  transition: opacity 200ms ease-out;
}

.draw-button.pressing:not(:disabled) .draw-button-glow {
  opacity: 1;
  transition-duration: 0ms;
}

.draw-button-art {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url("assets/images/draw_border.png") center / 100% 100% no-repeat;
  color: #f0e6d2;
  font-size: 20px;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  user-select: none;
  -webkit-user-select: none;
}

.draw-button:disabled {
  cursor: default;
}

.draw-button:disabled .draw-button-art {
  opacity: 0.5;
}

.category-button:focus-visible,
.draw-button:focus-visible {
  outline: 2px solid rgba(255, 165, 0, 0.95);
  outline-offset: 4px;
  border-radius: 8px;
}

@media (max-width: 370px) {
  :root {
    --card-w: 220px;
    --card-h: 330px;
  }

  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .category-grid {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2px;
    padding-left: 4px;
    padding-right: 4px;
  }

  .category-button {
    width: 100%;
    min-width: 0;
  }

  .category-art {
    font-size: 16px;
    padding-left: 3px;
    padding-right: 3px;
  }
}

@media (max-height: 730px) and (min-width: 371px) {
  :root {
    --card-w: 220px;
    --card-h: 330px;
  }

  .app-shell {
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .app-header h1 {
    font-size: 26px;
  }

  .app-header p {
    margin-bottom: 5px;
  }

  .category-grid {
    padding-top: 4px;
    margin-top: 0;
  }

  .draw-button {
    margin-top: 4px;
  }
}

@media (min-width: 700px) {
  .app-shell {
    background-position: center center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner,
  .category-button::before,
  .draw-button-glow {
    transition: none;
  }

  .card-glow.flash {
    animation-duration: 1ms;
  }
}

/* -----------------------------------------------------------
   Installed web-app / iPhone PWA polish
   ----------------------------------------------------------- */
html {
  background: #050403;
  overscroll-behavior: none;
}

body {
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

/* iOS supplies the Home Screen launch transition. Keeping the actual
   document free of a second HTML splash screen avoids duplicate UI and
   stale-cache mismatches after deployments. */
@media (display-mode: standalone) {
  html,
  body,
  .app-shell {
    min-height: 100dvh;
  }

  .app-shell {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-right: max(20px, env(safe-area-inset-right));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
  }
}
