/* Revolver Randomizer - responsive offline UI */

:root {
  color-scheme: dark;

  --bg: #090b0e;
  --bg-soft: #11151b;
  --surface: #151a21;
  --surface-raised: #1b222c;
  --surface-muted: #101419;
  --line: #2b333f;
  --line-soft: #202733;

  --brass: #d9a94a;
  --brass-muted: #8a6d2f;
  --text: #eee9df;
  --muted: #98a0ab;

  --wasted: #ff453a;
  --wasted-soft: #ff8a80;
  --wasted-glow: rgba(255, 69, 58, 0.5);
  --safe: #2eeea4;
  --safe-soft: #7af0c7;
  --safe-glow: rgba(47, 210, 154, 0.45);
  --lucky: #4b2cf8;

  --display: "Arial Narrow", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Roboto Mono", Menlo, Consolas, monospace;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --shadow-strong: 0 18px 45px rgba(0, 0, 0, 0.36);
}

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

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  font-family: var(--body);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 50% -160px, rgba(217, 169, 74, 0.16), transparent 65%),
    linear-gradient(180deg, #0c0e12 0%, var(--bg) 55%, #060709 100%);
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin-inline: auto;
  padding: clamp(18px, 4vw, 32px) clamp(14px, 4vw, 28px) 28px;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.4vw, 20px);
}

/* Header */
.head {
  text-align: center;
}

.title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(30px, 7vw, 52px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  text-wrap: balance;
  text-shadow: 0 1px 0 #000, 0 0 24px rgba(217, 169, 74, 0.18);
}

.subtitle {
  margin: 8px 0 0;
  color: rgba(238, 233, 223, 0.86);
  font-size: clamp(13px, 2.2vw, 15px);
}

.note {
  max-width: 52ch;
  margin: 6px auto 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

/* Mode selector */
.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(21, 26, 33, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.mode-btn {
  min-height: 46px;
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn:active {
  transform: translateY(1px);
}

.mode-btn[aria-pressed="true"] {
  border-color: rgba(217, 169, 74, 0.62);
  background: linear-gradient(180deg, #242c37, #171d25);
  color: var(--brass);
}

/* Status */
.status-section {
  display: block;
}

.eyebrow {
  margin: 0 0 8px;
  padding-left: 2px;
  color: var(--brass);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--line-soft);
  font-family: var(--mono);
}

.stat {
  min-width: 0;
  padding: 11px 12px;
  background: rgba(21, 26, 33, 0.96);
}

.stat-wide {
  grid-column: span 2;
}

.stat .k,
.stat .v {
  display: block;
  min-width: 0;
}

.stat .k {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.stat .v {
  margin-top: 4px;
  color: var(--text);
  font-size: clamp(13px, 2vw, 15px);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.stat .v.danger {
  color: var(--wasted-soft);
}

.stat .v.good {
  color: var(--safe-soft);
}

/* Cylinder stage */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-block: 2px 0;
}

.cylinder-wrap {
  position: relative;
  width: clamp(248px, 58vw, 340px);
  aspect-ratio: 1;
  filter: drop-shadow(var(--shadow-strong));
}

.cylinder {
  display: block;
  width: 100%;
  height: 100%;
}

.chamber {
  fill: #0c0f14;
  stroke: #414957;
  stroke-width: 2.5;
  transition: fill 0.18s ease, stroke 0.18s ease;
}

.chamber.hit {
  fill: var(--wasted);
  stroke: #ffc0bb;
  filter: drop-shadow(0 0 10px var(--wasted-glow));
}

.chamber.clear {
  fill: var(--safe);
  stroke: #c4ffe9;
  filter: drop-shadow(0 0 9px var(--safe-glow));
}

.chamber.dud {
  fill: var(--lucky);
  stroke: #fff0c2;
}

.fire {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 2;
  width: clamp(82px, 20vw, 104px);
  height: clamp(82px, 20vw, 104px);
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--brass-muted);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 35%, #423526 0%, #1b1711 56%, #090806 100%);
  color: var(--brass);
  box-shadow:
    0 0 0 4px rgba(217, 169, 74, 0.06),
    inset 0 2px 5px rgba(255, 255, 255, 0.06),
    inset 0 -3px 8px rgba(0, 0, 0, 0.66),
    0 8px 18px rgba(0, 0, 0, 0.52);
  font-family: var(--display);
  font-size: clamp(13px, 2.8vw, 16px);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
}

.fire:hover {
  filter: brightness(1.13);
}

.fire:active {
  transform: translate(-50%, -50%) scale(0.94);
}

.fire:disabled {
  cursor: default;
  opacity: 0.45;
  filter: grayscale(0.45);
}

.flash {
  position: absolute;
  top: -6px;
  left: 50%;
  width: 40%;
  aspect-ratio: 1;
  transform: translate(-50%, -40%) scale(0.2);
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--wasted) 35%, transparent 70%);
  opacity: 0;
  pointer-events: none;
}

.flash.go {
  animation: muzzle 0.42s ease-out;
}

.result {
  min-height: 46px;
  margin-top: 4px;
  opacity: 0;
  transform: translateY(6px);
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.result.show {
  opacity: 1;
  transform: none;
}

.result.wasted {
  color: var(--wasted);
  text-shadow: 0 0 26px var(--wasted-glow);
}

.result.safe {
  color: var(--safe);
  text-shadow: 0 0 22px var(--safe-glow);
}

.result.lucky {
  color: var(--lucky);
  font-size: clamp(18px, 3.8vw, 25px);
  letter-spacing: 0.08em;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn {
  min-height: 40px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover {
  border-color: var(--brass-muted);
  background: #202833;
}

.btn:active {
  transform: translateY(1px);
}

.btn.danger {
  border-color: #57302b;
  background: #211413;
  color: var(--wasted-soft);
}

.btn[hidden] {
  display: none;
}

/* Toggles */
.toggles {
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.toggle[hidden] {
  display: none;
}

.toggle .desc {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
}

.switch input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  opacity: 0;
}

.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #2b333f;
  transition: background 0.18s ease;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #cbc7be;
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input:checked + .track {
  background: var(--brass-muted);
}

.switch input:checked + .track::after {
  transform: translateX(20px);
  background: var(--brass);
}

.switch input:focus-visible + .track {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.foot {
  margin-top: auto;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-align: center;
}

/* Full-screen color flash */
.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
}

.screen-flash.red {
  animation: flashRed 0.5s ease-out;
}

.screen-flash.green {
  animation: flashGreen 0.55s ease-out;
}

@keyframes muzzle {
  0% {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.2);
  }

  18% {
    opacity: 1;
    transform: translate(-50%, -40%) scale(1.05);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -40%) scale(1.3);
  }
}

@keyframes flashRed {
  0% {
    opacity: 0;
    background: rgba(255, 69, 58, 0);
    box-shadow: inset 0 0 0 0 transparent;
  }

  12% {
    opacity: 1;
    background: rgba(255, 69, 58, 0.22);
    box-shadow: inset 0 0 140px 40px var(--wasted-glow);
  }

  100% {
    opacity: 0;
    background: rgba(255, 69, 58, 0);
    box-shadow: inset 0 0 0 0 transparent;
  }
}

@keyframes flashGreen {
  0% {
    opacity: 0;
    background: rgba(47, 210, 154, 0);
  }

  18% {
    opacity: 1;
    background: rgba(47, 210, 154, 0.14);
    box-shadow: inset 0 0 120px 30px var(--safe-glow);
  }

  100% {
    opacity: 0;
    background: rgba(47, 210, 154, 0);
    box-shadow: inset 0 0 0 0 transparent;
  }
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

@media (max-width: 680px) {
  .app {
    width: min(100%, 500px);
  }

  .status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-wide {
    grid-column: 1 / -1;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .btn {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .app {
    padding-inline: 12px;
    gap: 13px;
  }

  .title {
    font-size: 30px;
    letter-spacing: 0.06em;
  }

  .modes {
    grid-template-columns: 1fr;
  }

  .mode-btn {
    min-height: 38px;
    padding-block: 8px;
  }

  .status {
    grid-template-columns: 1fr;
  }

  .stat-wide {
    grid-column: auto;
  }

  .cylinder-wrap {
    width: min(82vw, 292px);
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .toggle {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
