:root {
  --bg-1: #0f1324;
  --bg-2: #1f0a1a;
  --accent-red: #ff3d43;
  --accent-blue: #2e6bff;
  --accent-yellow: #ffd54a;
  --text-main: #fff6dd;
  --text-sub: #ffd9a2;
  --panel: rgba(14, 11, 26, 0.76);
  --ok: #4dff8c;
  --danger: #ff6b71;
  --shadow: rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "YouYuan", "STHeiti", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at 22% 10%, #2a274b 0%, transparent 35%),
    radial-gradient(circle at 83% 77%, #3a1313 0%, transparent 40%),
    linear-gradient(140deg, var(--bg-1), var(--bg-2));
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.bg-layer {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(120deg, rgba(255, 255, 255, 0.04) 20%, transparent 20%, transparent 40%, rgba(255, 255, 255, 0.04) 40%, rgba(255, 255, 255, 0.04) 60%, transparent 60%);
  background-size: 30px 30px;
  opacity: 0.16;
  animation: drift 12s linear infinite;
  pointer-events: none;
}

.app {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 18px 14px 22px;
  min-height: 100dvh;
  display: flex;
  align-items: center;
}

.panel {
  width: 100%;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.13);
  border-radius: 24px;
  box-shadow: 0 16px 34px var(--shadow);
  padding: 20px 16px;
  backdrop-filter: blur(6px);
}

.hidden {
  display: none;
}

.start-panel {
  text-align: center;
}

.game-title {
  margin: 0;
  font-size: clamp(2rem, 7vw, 2.8rem);
  letter-spacing: 1px;
  text-shadow: 0 4px 0 #2b0508;
}

.slogan {
  margin: 12px 0 16px;
  color: var(--text-sub);
  line-height: 1.5;
}

.rules-box {
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.55;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 18px;
}

.rules-box p {
  margin: 6px 0;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #180a0f;
}

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

.btn-main {
  width: 100%;
  background: linear-gradient(90deg, var(--accent-yellow), #ff9f2f);
  box-shadow: 0 6px 0 #844f00;
}

.btn-sub {
  width: 100%;
  background: linear-gradient(90deg, #b7b1c4, #dfd4f0);
  box-shadow: 0 6px 0 #5d5769;
}

.game-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  text-align: center;
  padding: 8px 4px;
}

.chip span {
  display: block;
  font-size: 0.75rem;
  color: #f7c8a3;
}

.chip strong {
  font-size: 1.15rem;
}

.mode-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.mode-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.88rem;
  font-weight: 700;
}

.mode-badge.normal {
  background: rgba(77, 255, 140, 0.14);
  border: 1px solid rgba(77, 255, 140, 0.45);
  color: #a8ffca;
}

.mode-badge.reverse {
  background: rgba(255, 107, 113, 0.2);
  border: 1px solid rgba(255, 107, 113, 0.55);
  color: #ffd0d3;
  animation: blink 0.7s ease-in-out infinite alternate;
}

.mode-hint {
  font-size: 0.84rem;
  color: #f3c98e;
}

.timer-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.timer-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #76ffda, #ffe673, #ff7a55);
  transform-origin: left center;
}

.command-box {
  text-align: center;
  border-radius: 16px;
  padding: 16px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
}

.command-label {
  margin: 0;
  color: #ffcda5;
  font-size: 0.84rem;
}

.command-text {
  margin: 8px 0 2px;
  font-size: clamp(1.7rem, 8vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 1px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  animation: pop 160ms ease;
}

.toast {
  margin: 0;
  min-height: 1.4rem;
  text-align: center;
  font-size: 0.9rem;
  color: #ffd89d;
}

.toast.error {
  color: #ffc0be;
}

.pad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-btn {
  border: none;
  min-height: 124px;
  border-radius: 18px;
  font-size: clamp(2.1rem, 10vw, 2.8rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28);
}

.action-btn.red {
  background: linear-gradient(170deg, #ff5d67, #d92230);
}

.action-btn.blue {
  background: linear-gradient(170deg, #4f8fff, #1f4dd2);
}

.action-btn.pressed,
.action-btn:active {
  transform: translateY(2px) scale(0.985);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.tip {
  margin: 0;
  text-align: center;
  color: #ffc78c;
  font-size: 0.82rem;
}

.result-panel {
  text-align: center;
}

.result-title {
  margin: 0 0 14px;
  font-size: 1.75rem;
  text-shadow: 0 3px 0 #2f0812;
}

.result-grid {
  text-align: left;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.result-grid p {
  margin: 7px 0;
}

.fail-reason {
  margin: 4px 0 10px;
  color: #ffb4b8;
}

.share-card {
  text-align: left;
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.share-title {
  margin: 0;
  font-size: 0.82rem;
  color: #ffcf92;
}

.share-text {
  margin: 8px 0 0;
  line-height: 1.5;
  color: #ffe8bf;
}

.result-actions {
  margin-top: 12px;
  display: grid;
  gap: 9px;
}

.flip-flash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2rem, 12vw, 4.2rem);
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 22px rgba(255, 255, 255, 0.5);
  background: rgba(255, 34, 34, 0.22);
  z-index: 9;
  animation: flash 420ms ease;
  pointer-events: none;
}

.flip-flash.recover {
  background: rgba(47, 212, 138, 0.2);
}

@media (max-width: 360px) {
  .action-btn {
    min-height: 108px;
  }

  .panel {
    padding: 16px 12px;
  }
}

@keyframes drift {
  0% {
    transform: translate3d(-12px, -8px, 0);
  }
  100% {
    transform: translate3d(12px, 6px, 0);
  }
}

@keyframes pop {
  from {
    transform: scale(0.9);
    opacity: 0.2;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes blink {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.03);
  }
}

@keyframes flash {
  from {
    opacity: 0;
    transform: scale(1.08);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.98);
  }
}
