:root {
  --bg-1: #fff3e7;
  --bg-2: #ffd8b0;
  --card: #fffaf5;
  --line: #2b2f33;
  --text: #1f2328;
  --x: #f38020;
  --o: #d95700;
  --accent: #f38020;
  --accent-strong: #d95700;
  --shadow: 0 14px 40px rgba(25, 31, 38, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  height: 100dvh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 16%, rgba(243, 128, 32, 0.18) 0 20%, transparent 21%),
    radial-gradient(circle at 86% 82%, rgba(217, 87, 0, 0.14) 0 26%, transparent 27%),
    linear-gradient(150deg, var(--bg-1), var(--bg-2));
}

.app {
  min-height: 100svh;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(8px, 1.8vh, 16px);
  position: relative;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  z-index: 0;
  animation: float 8s ease-in-out infinite;
}

.orb-a {
  width: 220px;
  height: 220px;
  background: rgba(243, 128, 32, 0.22);
  top: 10%;
  left: -50px;
}

.orb-b {
  width: 180px;
  height: 180px;
  background: rgba(217, 87, 0, 0.2);
  bottom: 8%;
  right: -40px;
  animation-delay: 0.4s;
}

.panel {
  width: min(96vw, 520px);
  max-height: calc(100dvh - 16px);
  background: var(--card);
  border: 2px solid rgba(43, 47, 51, 0.2);
  border-radius: 26px;
  padding: 18px 16px;
  box-shadow:
    var(--shadow),
    0 0 0 2px rgba(243, 128, 32, 0.18);
  position: relative;
  z-index: 1;
  animation: rise 0.6s ease;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(circle at 14% 16%, rgba(243, 128, 32, 0.08), transparent 38%),
    radial-gradient(circle at 84% 86%, rgba(217, 87, 0, 0.1), transparent 40%);
}

.title {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: clamp(1.9rem, 2.2vw + 1rem, 2.7rem);
  letter-spacing: 0.02em;
  text-align: center;
  color: #1f2328;
}

.scoreboard {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.score {
  border: 1px solid rgba(43, 47, 51, 0.18);
  border-radius: 14px;
  text-align: center;
  padding: 8px 6px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: inset 0 0 0 1px rgba(243, 128, 32, 0.18);
}

.score h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
}

.score p {
  margin: 2px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.score-x p {
  color: var(--x);
}

.score-o p {
  color: var(--o);
}

.setup {
  margin-top: 10px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 6px;
  align-items: center;
}

.setup-label {
  font-size: 0.96rem;
  font-weight: 700;
}

.setup-select {
  border: 2px solid var(--line);
  border-radius: 10px;
  min-height: 42px;
  padding: 6px 10px;
  background: #ffffff;
  font-family: "Manrope", sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.setup-flip {
  min-height: 42px;
  padding-inline: 12px;
}

.coin-wrap {
  width: 52px;
  height: 52px;
  perspective: 800px;
}

.coin {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
}

.coin.flipping {
  animation: coin-flip 1.2s cubic-bezier(0.2, 0.7, 0, 1) forwards;
}

.coin.result-tails {
  transform: rotateY(180deg);
}

.coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid #b84d00;
  display: grid;
  place-items: center;
  font-family: "Sora", sans-serif;
  font-size: 1.15rem;
  color: #ffffff;
  backface-visibility: hidden;
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.16),
    0 7px 12px rgba(0, 0, 0, 0.18);
}

.coin-heads {
  background: radial-gradient(circle at 30% 30%, #ffa24f, #f38020 64%, #d95700);
}

.coin-tails {
  background: radial-gradient(circle at 30% 30%, #ff8f36, #e86a00 64%, #b84d00);
  transform: rotateY(180deg);
}

.status {
  margin: 10px 0;
  text-align: center;
  font-size: 1.03rem;
  font-weight: 700;
  min-height: 1.5em;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: min(78vh, 410px);
  margin: 0 auto;
}

.cell {
  aspect-ratio: 1;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: #fff6ed;
  font-family: "Sora", sans-serif;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  box-shadow: inset 0 0 0 2px rgba(243, 128, 32, 0.12);
  transition: transform 0.16s ease, background-color 0.16s ease;
}

.cell:hover:enabled,
.cell:focus-visible:enabled {
  transform: translateY(-2px);
  background: #ffe7d0;
}

.cell.x {
  color: #ff8f36;
  text-shadow: 0 2px 0 rgba(145, 62, 0, 0.32);
  -webkit-text-stroke: 1px #b84d00;
  letter-spacing: 0.02em;
}

.cell.o {
  color: transparent;
  -webkit-text-stroke: 3px #cc5a00;
  text-shadow: 0 1px 0 rgba(120, 50, 0, 0.22);
}

.cell.win {
  background: #ffc18b;
  border-style: solid;
}

.actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 10px 14px;
  min-height: 46px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: "Sora", sans-serif;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.btn-primary {
  background: linear-gradient(180deg, #ff9a44, #f38020 45%, #e86a00);
  color: #ffffff;
  border-color: #be5200;
}

.btn-secondary {
  background: #ffffff;
  color: var(--text);
  border-color: rgba(43, 47, 51, 0.22);
}

.btn:active {
  transform: translateY(1px);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(14px);
  }
}

@keyframes coin-flip {
  0% {
    transform: rotateY(0deg) rotateX(0deg) translateY(0);
  }
  45% {
    transform: rotateY(1080deg) rotateX(22deg) translateY(-6px);
  }
  100% {
    transform: rotateY(1980deg) rotateX(0deg) translateY(0);
  }
}

@media (max-width: 520px) {
  .app {
    padding: 6px;
  }

  .panel {
    padding: 10px 9px;
    width: min(98vw, 520px);
    max-height: calc(100dvh - 6px);
  }

  .title {
    font-size: clamp(1.7rem, 4.8vw, 2.2rem);
  }

  .scoreboard {
    gap: 6px;
  }

  .score {
    padding: 6px 4px;
  }

  .score h2 {
    font-size: 0.68rem;
  }

  .score p {
    font-size: 0.94rem;
  }

  .setup {
    grid-template-columns: 1fr auto auto;
    gap: 6px;
    margin-top: 8px;
  }

  .setup-label {
    grid-column: 1 / -1;
    font-size: 0.9rem;
    margin-bottom: 1px;
  }

  .setup-select {
    min-height: 38px;
    padding: 5px 9px;
    font-size: 0.9rem;
  }

  .coin-wrap {
    width: 44px;
    height: 44px;
  }

  .setup-flip {
    width: auto;
    min-height: 38px;
    padding-inline: 10px;
    font-size: 0.9rem;
  }

  .status {
    margin: 8px 0;
    font-size: 0.96rem;
    min-height: 1.25em;
  }

  .board {
    gap: 6px;
    width: min(100%, 300px);
    max-width: min(56dvh, 300px);
  }

  .actions {
    flex-direction: row;
    gap: 6px;
    margin-top: 8px;
  }

  .btn {
    min-height: 40px;
    font-size: 0.88rem;
    padding: 8px 10px;
  }

  .cell {
    font-size: clamp(1.35rem, 6.4vw, 1.95rem);
  }
}
