:root {
  color-scheme: dark;
  --bg: #111214;
  --bg-soft: #181a1f;
  --text: #f4f1ea;
  --muted: #aaa49b;
  --red: #bd1f2d;
  --red-dark: #83131e;
  --line: rgba(255, 255, 255, 0.16);
  --focus: #f3d36b;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button {
  font: inherit;
}

.app {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(100%, 540px);
  height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 20px max(22px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 0%, rgba(189, 31, 45, 0.16), transparent 34%),
    linear-gradient(180deg, #17181c 0%, #0e0f11 100%);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 42px;
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0;
}

.counter {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.message-area {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 28px 0;
}

.message {
  width: 100%;
  margin: 0;
  color: var(--text);
  font-size: clamp(1.25rem, 6.4vw, 2rem);
  font-weight: 700;
  line-height: 1.55;
  letter-spacing: 0;
  text-align: center;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.controls {
  display: grid;
  gap: 14px;
  padding-bottom: 8px;
}

.main-button {
  width: 100%;
  min-height: 96px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: linear-gradient(180deg, #d02d39 0%, var(--red) 48%, var(--red-dark) 100%);
  color: #fff8f3;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.36), inset 0 2px 0 rgba(255, 255, 255, 0.18);
  cursor: pointer;
  font-size: clamp(2rem, 11vw, 3.75rem);
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
  touch-action: manipulation;
}

.main-button:active,
.main-button.is-pressed {
  transform: translateY(5px) scale(0.985);
  filter: brightness(0.92);
}

.main-button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

.sub-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.sub-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
}

.sub-button:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.status {
  min-height: 1.3em;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.hidden {
  display: none;
}

.image-flash {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.image-flash.is-visible {
  opacity: 1;
}

.image-flash img {
  width: min(92vw, 760px);
  max-height: 78dvh;
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.58);
}

.shake {
  animation: shake 420ms ease-in-out;
}

.flash {
  animation: flash 560ms ease;
}

.flash .app {
  animation: appFlash 560ms ease;
}

.blackout::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 5;
  background: #000;
  pointer-events: none;
  animation: blackout 760ms ease forwards;
}

.message-pop {
  animation: messagePop 210ms ease;
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes flash {
  0%, 100% { background-color: var(--bg); }
  45% { background-color: #3a1820; }
}

@keyframes appFlash {
  0%, 100% { filter: none; }
  45% { filter: brightness(1.28) saturate(1.25); }
}

@keyframes blackout {
  0% { opacity: 0; }
  35% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes messagePop {
  from {
    opacity: 0.25;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 480px) {
  .sub-controls {
    grid-template-columns: repeat(3, 1fr);
  }

  #resetButton {
    grid-column: auto;
  }
}

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