*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --felt-deep: #062818;
  --felt-mid: #0a3d24;
  --felt-light: #145a38;
  --card-cream: #fff8e7;
  --card-border: #c9a227;
  --gold-bright: #ffe08a;
  --gold: #d4af37;
  --chip-red: #b91c1c;
  --text: #f5f5dc;
  --text-muted: #c4d4c8;
  --danger: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --touch-min: 48px;
  font-family: Georgia, "Times New Roman", "Segoe UI", serif;
}

html,
body {
  margin: 0;
  height: 100%;
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

.card-room {
  position: relative;
  background:
    radial-gradient(ellipse 120% 80% at 50% 0%, rgba(212, 175, 55, 0.12), transparent 55%),
    linear-gradient(165deg, var(--felt-deep), var(--felt-mid) 45%, #041a10);
}

.card-room__decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.playing-card {
  position: absolute;
  width: 56px;
  height: 78px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--card-cream), #e8dcc0);
  border: 2px solid var(--card-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #1a1a1a;
  opacity: 0.35;
  font-size: 1.1rem;
}

.playing-card span {
  color: var(--chip-red);
  font-size: 1.25rem;
  margin-top: 2px;
}

.playing-card--a { top: 8%; left: 4%; transform: rotate(-18deg); }
.playing-card--b { top: 14%; right: 6%; transform: rotate(14deg); }
.playing-card--c { bottom: 18%; left: 8%; transform: rotate(22deg); }
.playing-card--d { bottom: 10%; right: 4%; transform: rotate(-12deg); }
.playing-card--e { top: 42%; left: -2%; transform: rotate(-8deg); opacity: 0.22; }
.playing-card--f { top: 38%; right: -1%; transform: rotate(10deg); opacity: 0.22; }

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

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent);
  flex-shrink: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.brand-lockup__crown {
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.45);
  flex-shrink: 0;
}

.brand-lockup__text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.brand-lockup__gw {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hud__title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.hud__scores {
  display: flex;
  gap: 0.55rem;
}

.score-block {
  text-align: right;
}

.score-block__label {
  display: block;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-family: system-ui, sans-serif;
}

.score-block__value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold-bright);
}

.level-banner {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--gold);
  flex-shrink: 0;
}

.level-progress {
  height: 4px;
  margin: 0 0.75rem 0.35rem;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.level-progress__bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width 0.25s ease;
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
}

.stage {
  position: relative;
  width: min(100%, 100vw - 1rem);
  aspect-ratio: 1;
  max-height: min(68dvh, 100%);
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 0 0 3px rgba(212, 175, 55, 0.35),
    inset 0 0 40px rgba(0, 0, 0, 0.25),
    0 16px 40px rgba(0, 0, 0, 0.45);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 20, 12, 0.88);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay__panel {
  width: min(100%, 340px);
  text-align: center;
  padding: 1.25rem 1rem;
  border-radius: 16px;
}

.overlay__panel--card {
  background: linear-gradient(160deg, #fff9ef, #eadfce);
  color: #1f2937;
  border: 2px solid var(--card-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.overlay__logo {
  border-radius: 12px;
  margin-bottom: 0.35rem;
}

.overlay__brand {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.overlay__eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
  color: #92400e;
  font-family: system-ui, sans-serif;
}

.overlay__heading {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  color: #145a32;
}

.overlay__text {
  margin: 0 0 1rem;
  color: #4b5563;
  font-size: 0.9rem;
  line-height: 1.45;
  font-family: system-ui, sans-serif;
}

.overlay__hint {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: #6b7280;
  font-family: system-ui, sans-serif;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  font-family: system-ui, sans-serif;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(180deg, #166534, #145a32);
  color: var(--gold-bright);
  width: 100%;
  border: 1px solid var(--gold);
}

.btn--ghost {
  background: transparent;
  color: #374151;
  border: 1px solid #9ca3af;
  width: 100%;
  margin-top: 0.5rem;
}

.btn--small {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.35);
  flex: 1;
}

.btn--icon {
  flex: 0 0 auto;
  min-width: var(--touch-min);
}

.controls {
  flex-shrink: 0;
  padding: 0.35rem 0.75rem 0.5rem;
}

.controls__row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, minmax(var(--touch-min), 1fr));
  gap: 0.35rem;
  max-width: 240px;
  margin: 0 auto;
}

.dpad__btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  background: rgba(212, 175, 55, 0.15);
  color: var(--gold-bright);
  font-size: 1.25rem;
  min-height: var(--touch-min);
  cursor: pointer;
  border: 1px solid rgba(212, 175, 55, 0.35);
}

.dpad__btn:active {
  background: rgba(212, 175, 55, 0.32);
}

.dpad__btn--up { grid-column: 2; grid-row: 1; }
.dpad__btn--left { grid-column: 1; grid-row: 2; }
.dpad__btn--right { grid-column: 3; grid-row: 2; }
.dpad__btn--down { grid-column: 2; grid-row: 3; }

.footer {
  text-align: center;
  padding: 0.25rem 0 0.35rem;
  font-size: 0.75rem;
  flex-shrink: 0;
  font-family: system-ui, sans-serif;
}

.footer a {
  color: var(--text-muted);
}

@media (min-width: 600px) {
  .stage {
    max-height: min(64dvh, 560px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .overlay,
  .level-progress__bar {
    transition: none;
  }
}
