:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  background: #071f1a;
  color: #f8f4e9;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -10%, rgba(52, 155, 117, 0.34), transparent 42%),
    #071f1a;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 640px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 14px; background: #f4cc64; color: #102b25;
  font: 800 1.35rem Georgia, serif; box-shadow: 0 8px 28px #0004;
}
h1, h2, p { margin: 0; }
h1 { font-size: 1.18rem; letter-spacing: .01em; }
.topbar p { margin-top: 2px; color: #a9c5bb; font-size: .9rem; }

.game { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 40px 0 16px; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 18px; }
.section-heading h2 { font-size: clamp(1.55rem, 6vw, 2.15rem); font-family: Georgia, serif; }
.section-heading span { color: #a9c5bb; font-weight: 650; }

.card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(8px, 2.6vw, 15px); }
.card-slot {
  position: relative; aspect-ratio: 5 / 7; padding: 8px;
  border: 1.5px dashed #719287; border-radius: 14px;
  background: rgba(255,255,255,.035); color: #c6d7d1;
  cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.card-slot:hover { transform: translateY(-3px); border-color: #f4cc64; background: rgba(255,255,255,.07); }
.card-slot:focus-visible, button:focus-visible { outline: 3px solid #f4cc64; outline-offset: 3px; }
.card-slot.empty::before { content: "+"; display: block; font-size: clamp(1.5rem, 6vw, 2.5rem); line-height: 1; }
.card-slot small { display: block; margin-top: 8px; font-size: clamp(.72rem, 2.3vw, .86rem); }
.card-slot.filled {
  border-style: solid; border-color: #fff; background: #fff; color: #171b1a;
  box-shadow: 0 12px 34px #0005; text-align: left;
}
.card-slot.filled.red { color: #d32e39; }
.card-corner { position: absolute; top: 9px; left: 10px; font-weight: 800; font-size: clamp(1rem, 4vw, 1.5rem); line-height: .86; }
.card-suit { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(2rem, 9vw, 4rem); }

.reveal-button, .confirm-button {
  min-height: 56px; border: 0; border-radius: 16px; background: #f4cc64; color: #102b25;
  font-weight: 800; cursor: pointer; box-shadow: 0 12px 28px #0004;
  transition: transform .15s ease, filter .15s ease;
}
.reveal-button { width: 100%; margin-top: 24px; font-size: 1.05rem; }
.reveal-button:not(:disabled):hover, .confirm-button:hover { transform: translateY(-2px); filter: brightness(1.05); }
.reveal-button:disabled, .confirm-button:disabled { background: #47665c; color: #91a89f; cursor: not-allowed; box-shadow: none; }

dialog { color: #f8f4e9; }
dialog::backdrop { background: #00100ccc; backdrop-filter: blur(7px); }
.picker {
  width: min(calc(100% - 24px), 520px); max-height: calc(100svh - 24px); margin: auto auto 12px;
  padding: 0; border: 1px solid #41695b; border-radius: 24px; background: #102f28;
  box-shadow: 0 24px 80px #0009;
}
.picker form { padding: 24px; }
.picker-head { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.picker h2 { margin-top: 4px; font: 700 1.6rem Georgia, serif; }
.eyebrow { color: #f4cc64; font-size: .78rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.close-button { width: 42px; height: 42px; border: 0; border-radius: 50%; background: #25483e; color: white; font-size: 1.65rem; cursor: pointer; }
fieldset { margin: 24px 0 0; padding: 0; border: 0; }
legend { margin-bottom: 11px; color: #b8cec7; font-size: .88rem; font-weight: 700; }
.option-grid { display: grid; gap: 8px; }
.ranks { grid-template-columns: repeat(7, 1fr); }
.suits { grid-template-columns: repeat(4, 1fr); }
.option {
  min-height: 46px; padding: 6px; border: 1px solid #51766a; border-radius: 12px;
  background: #173a32; color: #fff; font-weight: 750; cursor: pointer;
}
.option[data-suit] { font-size: 1.45rem; }
.option.selected { border-color: #f4cc64; background: #f4cc64; color: #102b25; }
.option.red:not(.selected) { color: #ff7c84; }
.confirm-button { width: 100%; margin-top: 24px; }

.result-dialog {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: rgba(0, 0, 0, 0); transition: background-color 1.8s ease;
}
.result-dialog::backdrop { background: transparent; backdrop-filter: none; }
.result-dialog.darkened { background: #000; }
.confirmation-content {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 30px 20px; text-align: center; opacity: 0; transition: opacity .8s ease;
}
.confirmation-content[hidden] { display: none; }
.result-dialog.question-visible .confirmation-content { opacity: 1; }
.confirmation-content h2 { font: 700 clamp(2rem, 8vw, 3.25rem) Georgia, serif; }
.confirmation-content .confirm-button { width: min(100%, 280px); margin-top: 10px; }
.chaos-scene {
  position: absolute; inset: 0; overflow: hidden; background: #000; opacity: 0;
  transform: scale(1.08); transition: opacity .35s ease, transform .8s cubic-bezier(.2,.8,.2,1), filter .8s ease;
}
.chaos-scene[hidden] { display: none; }
.chaos-scene.active { opacity: 1; transform: scale(1); }
.chaos-scene.collapsing { opacity: 0; transform: scale(.05) rotate(28deg); filter: blur(28px) saturate(3); }
.chaos-scene::before,
.chaos-scene::after {
  content: ""; position: absolute; inset: -35%; border-radius: 42%; mix-blend-mode: screen; pointer-events: none;
}
.chaos-scene::before {
  background: conic-gradient(from 10deg, transparent, #ff174488, transparent 18%, #04e7ff88, transparent 42%, #d500f988, transparent 65%, #ffe60077, transparent 82%);
  animation: chaos-spin 2.1s linear infinite, chaos-pulse .47s ease-in-out infinite alternate;
}
.chaos-scene::after {
  background: repeating-conic-gradient(from 70deg, transparent 0 7deg, #ffffff18 8deg 9deg, transparent 10deg 22deg);
  animation: chaos-spin 5.5s linear infinite reverse;
}
#chaos-canvas { position: absolute; inset: 0; width: 100%; height: 100%; filter: saturate(1.7) contrast(1.25); mix-blend-mode: screen; }
.chaos-orbit {
  position: absolute; left: 50%; top: 50%; width: 58vmin; aspect-ratio: 1; border: clamp(2px, .5vw, 7px) solid #fff;
  border-radius: 43% 57% 62% 38% / 56% 31% 69% 44%; mix-blend-mode: difference; opacity: .72;
}
.orbit-one { animation: orbit-one 1.15s linear infinite; }
.orbit-two { width: 82vmin; border-color: #00eaff; animation: orbit-two 1.8s linear infinite; }
.orbit-three { width: 34vmin; border-color: #ff194f; animation: orbit-three .72s steps(7) infinite; }
.chaos-glyphs span {
  position: absolute; left: 50%; top: 50%; color: white; font: 800 clamp(2rem, 8vw, 8rem) Georgia, serif;
  text-shadow: .08em 0 #ff1744, -.08em 0 #00eaff; mix-blend-mode: screen; opacity: .82;
  animation: glyph-flight 2.4s cubic-bezier(.3,.8,.3,1) infinite;
}
.chaos-glyphs span:nth-child(2) { animation-delay: -.3s; --x: 34vw; --y: -31vh; }
.chaos-glyphs span:nth-child(3) { animation-delay: -.6s; --x: -42vw; --y: 23vh; }
.chaos-glyphs span:nth-child(4) { animation-delay: -.9s; --x: 39vw; --y: 34vh; }
.chaos-glyphs span:nth-child(5) { animation-delay: -1.2s; --x: -32vw; --y: -38vh; }
.chaos-glyphs span:nth-child(6) { animation-delay: -1.5s; --x: 12vw; --y: 43vh; }
.chaos-glyphs span:nth-child(7) { animation-delay: -1.8s; --x: -9vw; --y: -44vh; }
.chaos-glyphs span:nth-child(8) { animation-delay: -2.1s; --x: 44vw; --y: -5vh; }
.chaos-glyphs span:first-child { --x: -43vw; --y: -9vh; }
.result-content { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 30px 20px; text-align: center; }
.result-content[hidden] { display: none; }
.result-card {
  position: relative; width: min(48vw, 220px); aspect-ratio: 5 / 7; padding: 18px;
  border-radius: 22px; background: #fff; color: #151919; text-align: left;
  font: 800 clamp(1.8rem, 9vw, 3.2rem)/.82 Georgia, serif; box-shadow: 0 28px 80px #0009;
  opacity: 0; filter: blur(14px); transform: scale(.92);
  transition: opacity 4.5s ease, filter 4.5s ease, transform 4.5s cubic-bezier(.2,.8,.2,1);
}
.result-content.revealed .result-card { opacity: 1; filter: blur(0); transform: scale(1); }
.result-card.red { color: #d32e39; }
.result-card > span { display: block; }
.result-card strong { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(4rem, 20vw, 8rem); }
.result-card .bottom { position: absolute; right: 18px; bottom: 18px; transform: rotate(180deg); }

@keyframes chaos-spin { to { transform: rotate(1turn) scale(1.18); } }
@keyframes chaos-pulse { to { opacity: .22; filter: hue-rotate(100deg) blur(12px); } }
@keyframes orbit-one { from { transform: translate(-50%, -50%) rotate(0) skew(8deg); } to { transform: translate(-50%, -50%) rotate(1turn) skew(-16deg); } }
@keyframes orbit-two { from { transform: translate(-50%, -50%) rotate(1turn) scale(.68); } to { transform: translate(-50%, -50%) rotate(0) scale(1.22); } }
@keyframes orbit-three { from { transform: translate(-50%, -50%) rotate(0) scale(.6); } to { transform: translate(-50%, -50%) rotate(-1turn) scale(1.6); } }
@keyframes glyph-flight {
  0% { transform: translate(-50%, -50%) scale(.05) rotate(0); opacity: 0; }
  20% { opacity: .9; }
  100% { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1.45) rotate(520deg); opacity: 0; }
}
@media (min-width: 600px) { .picker { margin: auto; } .app-shell { padding-inline: 28px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
