:root {
  --red: #ef4444;
  --red-dark: #b91c1c;
  --yellow: #fbbf24;
  --yellow-dark: #d97706;
  --blue-glass: #bee3f8;
  --ink: #292524;
  --card-bg: #ffffff;
  --capsule-colors: #ff6b6b, #4dabf7, #51cf66, #ffd43b, #cc5de8, #ff922b, #20c997;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, #ffe8d6 0%, #ffd6e8 35%, #d6e8ff 100%);
  color: var(--ink);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

/* ---------- Header ---------- */
.app-header {
  text-align: center;
  margin-bottom: 24px;
}

.app-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  margin: 0 0 6px;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.6);
}

.subtitle {
  margin: 0;
  color: #57534e;
  font-size: 0.95rem;
}

/* ---------- Category panel ---------- */
.category-panel {
  background: rgba(255, 255, 255, 0.65);
  border-radius: 20px;
  padding: 16px 20px 20px;
  margin-bottom: 24px;
  backdrop-filter: blur(4px);
}

.category-panel h2,
.history-panel h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.category-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid transparent;
  background: #ffffff;
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.category-tile:hover {
  transform: translateY(-2px);
}

.category-tile.checked {
  border-color: var(--red);
  background: #fff5f5;
  box-shadow: 0 3px 0 var(--red);
}

.category-tile input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.category-tile .tile-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.category-tile .tile-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.category-tile .tile-label {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-tile .tile-count {
  font-size: 0.7rem;
  color: #78716c;
}

.category-tile.empty .tile-count {
  color: #dc2626;
  font-weight: 700;
}

/* ---------- Machine section ---------- */
.machine-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.gacha-machine {
  width: 260px;
  max-width: 80vw;
  position: relative;
}

.dome {
  height: 130px;
  border-radius: 130px 130px 18px 18px;
  background: radial-gradient(circle at 35% 30%, #eaf6ff, var(--blue-glass) 70%);
  border: 6px solid #fff;
  border-bottom-width: 10px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.dome-capsules {
  position: absolute;
  inset: 0;
}

.dome-capsules span {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0,0,0,.15);
  animation: capsule-float 3.6s ease-in-out infinite;
}

.dome-shine {
  position: absolute;
  top: -20px;
  left: 10px;
  width: 55px;
  height: 160px;
  background: rgba(255, 255, 255, 0.55);
  transform: rotate(20deg);
  filter: blur(2px);
  pointer-events: none;
}

@keyframes capsule-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.machine-body {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
  border-radius: 0 0 18px 18px;
  padding: 14px 16px 18px;
  position: relative;
  box-shadow: 0 10px 0 #8f1616, 0 14px 24px rgba(0, 0, 0, 0.28);
}

.display-window {
  background: #241f1f;
  color: #7cffb0;
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  text-align: center;
  border-radius: 8px;
  padding: 6px 8px;
  margin-bottom: 34px;
  letter-spacing: 0.02em;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

.crank-wrap {
  position: absolute;
  right: -14px;
  top: 54px;
}

.crank {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fde68a;
  border: 4px solid var(--yellow-dark);
  position: relative;
  transform-origin: center;
}

.crank-arm {
  position: absolute;
  width: 6px;
  height: 22px;
  background: var(--yellow-dark);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -100%);
  border-radius: 3px;
}

.crank-knob {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--yellow-dark);
  left: 50%;
  top: -6px;
  transform: translateX(-50%);
}

.crank.spinning {
  animation: crank-turn 0.6s ease-in-out;
}

@keyframes crank-turn {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.coin-slot {
  width: 26px;
  height: 8px;
  background: #241f1f;
  border-radius: 3px;
  margin: 0 auto 8px;
}

.brand-plate {
  text-align: center;
  color: #ffe4e4;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  font-weight: 700;
  opacity: 0.85;
}

.outlet {
  height: 22px;
  background: #3f3f46;
  margin: 0 18px;
  border-radius: 0 0 8px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.outlet-hole {
  width: 60%;
  height: 8px;
  background: #17171a;
  border-radius: 4px;
}

/* ---------- Tray / result ---------- */
.tray {
  position: relative;
  width: 100%;
  max-width: 320px;
  min-height: 150px;
  background: linear-gradient(180deg, #f5deb3, #e0b478);
  border-radius: 16px;
  border: 3px solid #c98a3d;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.15);
}

.tray-placeholder {
  color: #7c5324;
  font-size: 0.85rem;
  margin: 0;
}

.capsule {
  position: absolute;
  width: 88px;
  height: 88px;
  opacity: 0;
  pointer-events: none;
}

.capsule-top,
.capsule-bottom {
  position: absolute;
  left: 0;
  width: 88px;
  height: 44px;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
}

.capsule-top {
  top: 0;
  border-radius: 44px 44px 0 0;
  border-bottom: 2px solid rgba(0, 0, 0, 0.15);
}

.capsule-bottom {
  bottom: 0;
  border-radius: 0 0 44px 44px;
  filter: brightness(0.88);
}

.capsule.falling {
  opacity: 1;
  animation: capsule-fall 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes capsule-fall {
  0% { transform: translateY(-90px) scale(0.5); opacity: 0; }
  45% { opacity: 1; }
  62% { transform: translateY(8px) scale(1); }
  78% { transform: translateY(-5px) scale(1); }
  90% { transform: translateY(2px) scale(1); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.capsule.wiggle {
  animation: capsule-wiggle 0.14s ease-in-out 4;
}

@keyframes capsule-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-9deg); }
  75% { transform: rotate(9deg); }
}

.capsule.open .capsule-top {
  transform: translate(-30px, -46px) rotate(-110deg);
  opacity: 0;
}

.capsule.open .capsule-bottom {
  transform: translate(30px, 46px) rotate(110deg);
  opacity: 0;
}

.result-card {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px 22px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: scale(0.3);
}

.result-card.show {
  animation: card-pop 0.45s ease-out forwards;
}

@keyframes card-pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.result-emoji {
  font-size: 2.6rem;
  line-height: 1;
}

.result-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.result-category {
  font-size: 0.75rem;
  color: #78716c;
  background: #f5f5f4;
  padding: 2px 10px;
  border-radius: 999px;
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.draw-btn,
.reset-btn {
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 28px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.15s ease;
}

.draw-btn {
  background: linear-gradient(180deg, var(--yellow) 0%, var(--yellow-dark) 100%);
  color: #422006;
  box-shadow: 0 4px 0 #92400e;
}

.draw-btn:not(:disabled):hover {
  transform: translateY(-2px);
}

.draw-btn:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #92400e;
}

.draw-btn:disabled {
  background: #d6d3d1;
  color: #a8a29e;
  box-shadow: 0 4px 0 #a8a29e;
  cursor: not-allowed;
}

.reset-btn {
  background: #fff;
  color: #57534e;
  border: 2px solid #d6d3d1;
}

.reset-btn:hover {
  border-color: #a8a29e;
}

.status-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: #dc2626;
  font-weight: 600;
}

/* ---------- History ---------- */
.history-panel {
  background: rgba(255, 255, 255, 0.65);
  border-radius: 20px;
  padding: 16px 20px 20px;
  backdrop-filter: blur(4px);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.history-list:empty::after {
  content: "まだ何も獲得していません";
  color: #a8a29e;
  font-size: 0.85rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
}

.history-item .h-emoji {
  font-size: 1.2rem;
}

.history-item .h-name {
  font-weight: 700;
  flex: 1;
}

.history-item .h-cat {
  font-size: 0.7rem;
  color: #78716c;
  background: #f5f5f4;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}
