:root {
  --bg-top: #fff2d8;
  --bg-bottom: #f6b169;
  --card: rgba(255, 248, 236, 0.84);
  --card-strong: rgba(255, 250, 242, 0.92);
  --text: #1d140f;
  --muted: #6f584b;
  --accent: #c44f21;
  --accent-deep: #8b2500;
  --line: rgba(75, 34, 15, 0.12);
  --shadow: 0 24px 60px rgba(92, 41, 13, 0.18);
  --surface: rgba(255, 255, 255, 0.68);
  --toggle-bg: rgba(255, 255, 255, 0.72);
  --toggle-text: #4b220f;
}

body[data-theme="dark"] {
  --bg-top: #151820;
  --bg-bottom: #37231a;
  --card: rgba(28, 31, 38, 0.86);
  --card-strong: rgba(22, 25, 31, 0.92);
  --text: #f5ebdd;
  --muted: #c7b4a2;
  --accent: #ffb347;
  --accent-deep: #ff7a1a;
  --line: rgba(255, 231, 205, 0.1);
  --shadow: 0 28px 64px rgba(0, 0, 0, 0.38);
  --surface: rgba(255, 255, 255, 0.06);
  --toggle-bg: rgba(255, 255, 255, 0.08);
  --toggle-text: #fff2dc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "SUIT", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.65), transparent 28%),
    radial-gradient(circle at bottom right, rgba(145, 43, 0, 0.18), transparent 26%),
    linear-gradient(145deg, var(--bg-top), var(--bg-bottom));
  transition: background 0.35s ease, color 0.35s ease;
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(8px);
  pointer-events: none;
}

body::before {
  inset: auto auto 8% 6%;
  width: 180px;
  height: 180px;
  background: rgba(255, 255, 255, 0.22);
}

body::after {
  inset: 10% 8% auto auto;
  width: 220px;
  height: 220px;
  background: rgba(156, 44, 0, 0.14);
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 24px;
  align-items: center;
  padding: 32px 0;
}

.hero-card,
.stats-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 32px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-card {
  padding: 40px;
}

.hero-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.hero-card::after,
.stats-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 45%);
  pointer-events: none;
}

.stats-card {
  padding: 32px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.theme-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 118px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--toggle-bg);
  color: var(--toggle-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition: transform 0.18s ease, background 0.25s ease, color 0.25s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Black Han Sans", sans-serif;
  font-weight: 400;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(2.6rem, 5vw, 4.8rem);
  line-height: 0.95;
}

h2 {
  font-size: clamp(2rem, 3vw, 2.8rem);
}

h3 {
  font-size: 1.25rem;
}

.hero-copy {
  max-width: 34rem;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.coin-stage {
  display: grid;
  place-items: center;
  margin: 34px 0 28px;
  perspective: 1100px;
}

.coin {
  position: relative;
  width: min(260px, 52vw);
  aspect-ratio: 1;
  transform-style: preserve-3d;
  transition: transform 1.2s cubic-bezier(0.2, 0.75, 0.25, 1);
}

.coin.is-flipping {
  animation: float-spin 1.2s cubic-bezier(0.2, 0.75, 0.25, 1);
}

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 12px solid rgba(255, 243, 218, 0.85);
  box-shadow:
    inset 0 0 0 6px rgba(129, 63, 10, 0.14),
    inset 0 18px 28px rgba(255, 255, 255, 0.5),
    0 18px 36px rgba(123, 50, 11, 0.22);
  font-family: "Black Han Sans", sans-serif;
  font-size: clamp(3rem, 8vw, 5rem);
  color: #fff8ef;
  text-shadow: 0 6px 18px rgba(88, 28, 0, 0.25);
  backface-visibility: hidden;
}

.coin-front {
  background: radial-gradient(circle at 35% 30%, #ffeaa5, #f0a227 64%, #bc5b00 100%);
}

.coin-back {
  background: radial-gradient(circle at 35% 30%, #ffd0a9, #de6d32 62%, #812600 100%);
  transform: rotateY(180deg);
}

.result-panel,
.history-card,
.stat-box {
  background: var(--card-strong);
  border: 1px solid var(--line);
  transition: background 0.25s ease, border-color 0.25s ease;
}

.result-panel {
  padding: 18px 20px;
  border-radius: 20px;
}

.result-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.result-value {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.toss-button,
.reset-button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.toss-button {
  width: 100%;
  margin-top: 20px;
  padding: 18px 24px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: white;
  font-size: 1.05rem;
  font-weight: 800;
  box-shadow: 0 18px 32px rgba(139, 37, 0, 0.25);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.toss-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 38px rgba(139, 37, 0, 0.3);
}

.toss-button:active {
  transform: translateY(1px);
}

.toss-button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.stats-header {
  margin-bottom: 22px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stat-box {
  padding: 18px 16px;
  border-radius: 22px;
}

.stat-name {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.stat-value {
  display: block;
  margin-top: 12px;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.history-card {
  margin-top: 20px;
  padding: 20px;
  border-radius: 24px;
}

.history-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reset-button {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(139, 37, 0, 0.08);
  color: var(--accent-deep);
  font-weight: 700;
}

.history-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.history-item,
.history-empty {
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-badge {
  min-width: 56px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 999px;
  color: white;
  font-size: 0.92rem;
  font-weight: 800;
}

.history-badge.heads {
  background: linear-gradient(135deg, #f2aa2b, #c96c00);
}

.history-badge.tails {
  background: linear-gradient(135deg, #d86b37, #8d2900);
}

.history-time {
  color: var(--muted);
  font-size: 0.92rem;
}

@keyframes float-spin {
  0% {
    transform: rotateY(0deg) translateY(0) scale(1);
  }
  40% {
    transform: rotateY(720deg) translateY(-28px) scale(1.05);
  }
  100% {
    transform: rotateY(1440deg) translateY(0) scale(1);
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 20px 0 28px;
  }

  .hero-card,
  .stats-card {
    padding: 24px;
  }
}

@media (max-width: 560px) {
  .hero-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .history-title-row,
  .history-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .coin {
    width: min(220px, 62vw);
  }
}
