:root {
  --clay-bg: #f0e9ff;
  --clay-text: #5b4b8a;
  --clay-accent: #7c6bb0;
  --clay-deep: #3f335d;
  --clay-surface: #f7f2ff;
  --clay-pink: #ffd6ec;
  --clay-mint: #d4f5e9;
  --clay-peach: #ffe4d6;
  --clay-lemon: #fff3c4;
  --clay-sky: #d6e8ff;
  --clay-grey: #d9d4e6;
  --shadow-out:
    10px 12px 24px rgba(91, 75, 138, 0.16),
    -6px -6px 18px rgba(255, 255, 255, 0.92);
  --shadow-in:
    inset 5px 5px 12px rgba(255, 255, 255, 0.88),
    inset -5px -5px 14px rgba(91, 75, 138, 0.1);
  --radius: 36px;
  --font: "Fredoka", "ZCOOL KuaiLe", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

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

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

body {
  font-family: var(--font);
  color: var(--clay-text);
  background: var(--clay-bg);
  line-height: 1.45;
  overflow-x: hidden;
}

.blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(8px);
  pointer-events: none;
  z-index: 0;
}

.blob-a {
  width: 280px;
  height: 280px;
  left: -80px;
  top: -40px;
  background: #ffd6ec;
  opacity: 0.55;
}

.blob-b {
  width: 240px;
  height: 240px;
  right: -60px;
  top: 180px;
  background: #d4f5e9;
  opacity: 0.5;
}

.blob-c {
  width: 200px;
  height: 200px;
  left: 18%;
  bottom: -70px;
  background: #fff3c4;
  opacity: 0.45;
}

.app {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 72px;
}

.hero {
  text-align: center;
  margin-bottom: 22px;
}

.eyebrow {
  display: inline-block;
  margin: 0 0 8px;
  padding: 6px 16px;
  border-radius: 999px;
  background: #ffe4d6;
  box-shadow: var(--shadow-out), var(--shadow-in);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 6px;
  font-size: clamp(40px, 7vw, 64px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--clay-deep);
}

.tagline {
  margin: 0;
  color: var(--clay-accent);
  font-size: 18px;
}

.clay-surface {
  background: var(--clay-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-out), var(--shadow-in);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.toolbar,
.input-panel,
.stage,
.history {
  padding: 22px 24px;
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  position: relative;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 64px;
  height: 36px;
  margin: 0;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  z-index: 2;
}

.toggle-ui {
  width: 64px;
  height: 36px;
  border-radius: 999px;
  background: #e4dcf7;
  box-shadow: var(--shadow-in);
  position: relative;
  flex-shrink: 0;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f7f2ff;
  box-shadow: 4px 4px 8px rgba(91, 75, 138, 0.18);
  transition: transform 0.25s ease;
}

.toggle input:checked + .toggle-ui {
  background: #cbb6ff;
}

.toggle input:checked + .toggle-ui::after {
  transform: translateX(28px);
  background: #fff;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
}

textarea {
  width: 100%;
  min-height: 168px;
  resize: vertical;
  border: none;
  outline: none;
  border-radius: 28px;
  padding: 18px 20px;
  font: inherit;
  font-size: 18px;
  color: var(--clay-deep);
  background: #efe8ff;
  box-shadow: var(--shadow-in);
}

textarea::placeholder {
  color: #a898c9;
}

.chips-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 14px;
}

.count-pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: #d6e8ff;
  box-shadow: var(--shadow-out);
  font-weight: 600;
  font-size: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 92px;
  overflow: auto;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: #ffd6ec;
  box-shadow: 3px 3px 8px rgba(91, 75, 138, 0.12), inset 2px 2px 4px rgba(255, 255, 255, 0.8);
  font-size: 14px;
}

.chip.is-drawn {
  background: var(--clay-grey);
  color: #8a819d;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.tab,
.btn {
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  color: var(--clay-text);
}

.tab {
  padding: 16px 10px;
  border-radius: 30px;
  background: #efe8ff;
  box-shadow: var(--shadow-out), var(--shadow-in);
  font-size: 18px;
}

.tab.is-active {
  background: #cbb6ff;
  color: var(--clay-deep);
}

.btn {
  border-radius: 30px;
  padding: 14px 26px;
  background: #efe8ff;
  box-shadow: var(--shadow-out), var(--shadow-in);
  font-size: 16px;
}

.btn:active:not(:disabled) {
  box-shadow: var(--shadow-in);
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #cbb6ff;
  color: var(--clay-deep);
  font-size: 20px;
  padding: 16px 36px;
}

.btn-ghost {
  background: #f0e9ff;
}

.btn-small {
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 22px;
}

.stage {
  min-height: 280px;
}

.hint {
  margin: 0 0 12px;
  text-align: center;
  color: var(--clay-accent);
  min-height: 1.4em;
}

.stage-body {
  min-height: 240px;
}

.stage-body.is-hidden,
.is-hidden {
  display: none !important;
}

.draw-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.draw-bar.is-hidden {
  display: none !important;
}

.count-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.count-field input {
  width: 72px;
  height: 44px;
  border: none;
  border-radius: 18px;
  text-align: center;
  font: inherit;
  font-size: 18px;
  color: var(--clay-deep);
  background: #efe8ff;
  box-shadow: var(--shadow-in);
}

.drawn-badge {
  position: relative;
}

.badge-btn {
  font-family: inherit;
  font-weight: 600;
  border: none;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 999px;
  background: #ffe4d6;
  color: var(--clay-text);
  box-shadow: var(--shadow-out);
}

.badge-pop {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: max(220px, 100%);
  padding: 12px 14px;
  border-radius: 20px;
  background: #fff8ff;
  box-shadow: var(--shadow-out);
  color: var(--clay-text);
  font-size: 14px;
  line-height: 1.6;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
}

.drawn-badge:hover .badge-pop,
.drawn-badge:focus-within .badge-pop {
  opacity: 1;
  transform: translateY(0);
}

.wheel-wrap {
  position: relative;
  width: min(420px, 82vw);
  margin: 28px auto 32px;
  aspect-ratio: 1;
  overflow: visible;
}

.wheel-pointer {
  position: absolute;
  top: -18px;
  left: 50%;
  z-index: 3;
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 28px solid #7c6bb0;
  transform: translateX(-50%);
  filter: drop-shadow(2px 4px 4px rgba(91, 75, 138, 0.25));
}

.wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  box-shadow:
    12px 16px 28px rgba(91, 75, 138, 0.2),
    inset 8px 8px 16px rgba(255, 255, 255, 0.55),
    inset -8px -10px 18px rgba(91, 75, 138, 0.16);
  overflow: hidden;
}

.wheel-face {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.wheel-arm {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 0;
  height: 50%;
  transform-origin: center bottom;
  pointer-events: none;
}

.wheel-label {
  position: absolute;
  top: 16%;
  left: 0;
  width: 88px;
  margin-left: -44px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--clay-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wheel-label.is-drawn {
  color: #8a819d;
}

.wheel-cap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78px;
  height: 78px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #f7f2ff;
  box-shadow: var(--shadow-out), var(--shadow-in);
  z-index: 4;
  display: grid;
  place-items: center;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--clay-accent);
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.wheel-cap:hover:not(:disabled) {
  transform: translate(-50%, -50%) scale(1.08);
}

.wheel-cap:active:not(:disabled) {
  transform: translate(-50%, -50%) scale(0.96);
  box-shadow: var(--shadow-in);
}

.wheel-cap:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.flip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 14px;
  max-height: 430px;
  overflow: auto;
  padding: 8px 4px 16px;
}

.flip-card {
  aspect-ratio: 3 / 4;
  perspective: 900px;
}

.flip-card.is-pickable {
  cursor: pointer;
}

.flip-card.is-pickable:hover {
  filter: brightness(1.05);
}

.flip-card.is-drawn {
  cursor: default;
}

.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.flip-card.is-flipped .flip-inner {
  transform: rotateY(180deg);
}

.flip-face {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  display: grid;
  place-items: center;
  padding: 10px;
  backface-visibility: hidden;
  text-align: center;
  font-weight: 700;
  box-shadow: var(--shadow-out);
}

.flip-back {
  background: linear-gradient(160deg, #d6e8ff, #cbb6ff);
  color: #fff;
  font-size: 36px;
}

.flip-front {
  background: #fff8ff;
  color: var(--clay-deep);
  transform: rotateY(180deg);
  font-size: 16px;
  word-break: break-word;
}

.flip-card.is-drawn .flip-front {
  background: #e6e1f0;
  color: #8a819d;
  filter: grayscale(0.35);
}

.direct-box {
  width: min(280px, 70vw);
  margin: 20px auto;
  aspect-ratio: 1;
  border-radius: 40px;
  background: linear-gradient(160deg, #ffd6ec, #e8d5ff);
  box-shadow: var(--shadow-out), var(--shadow-in);
  display: grid;
  place-items: center;
  font-size: 42px;
  color: var(--clay-deep);
}

.direct-box.is-shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%,
  100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg) scale(1.03); }
  50% { transform: rotate(8deg) scale(1.05); }
  75% { transform: rotate(-4deg); }
}

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

.history h2 {
  margin: 0;
  font-size: 22px;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  max-height: 280px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 168px 88px 1fr;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 22px;
  background: #efe8ff;
  box-shadow: var(--shadow-in);
}

.history-item .time {
  color: var(--clay-accent);
  font-size: 14px;
}

.history-item .mode {
  font-weight: 600;
}

.history-empty {
  margin: 16px 0 0;
  color: var(--clay-accent);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(91, 75, 138, 0.28);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}

.modal[hidden] {
  display: none !important;
}

.modal-card {
  width: min(460px, 100%);
  padding: 36px 28px 28px;
  border-radius: 40px;
  background: #f7f2ff;
  box-shadow: var(--shadow-out), var(--shadow-in);
  text-align: center;
  animation: pop 0.45s cubic-bezier(0.2, 1.2, 0.3, 1);
}

@keyframes pop {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-kicker {
  margin: 0;
  color: var(--clay-accent);
}

.modal-names {
  margin: 12px 0 22px;
  font-size: clamp(32px, 6vw, 48px);
  font-weight: 700;
  color: var(--clay-deep);
  word-break: break-word;
}

.modal-note {
  margin: -8px 0 18px;
  color: var(--clay-accent);
}

@media (max-width: 640px) {
  .history-item {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .mode-tabs {
    gap: 8px;
  }

  .tab {
    font-size: 15px;
    padding: 14px 6px;
  }

  .toolbar,
  .input-panel,
  .stage,
  .history {
    padding: 18px 16px;
  }
}
