:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --line: #cbd5e1;
  --text: #0f172a;
  --accent: #0ea5e9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: radial-gradient(circle at top, #e0f2fe 0%, var(--bg) 45%, #e2e8f0 100%);
  color: var(--text);
  overflow: hidden;
}

.app-shell {
  width: min(98vw, 1120px);
  display: grid;
  grid-template-columns: minmax(420px, 680px) minmax(260px, 340px);
  gap: 14px;
  align-items: stretch;
}

.container {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  position: relative;
  z-index: 2;
}

.history-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.history-panel h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  text-align: center;
}

.history-list {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  padding: 10px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: "SFMono-Regular", Menlo, Consolas, "Hiragino Sans", monospace;
  font-size: 0.84rem;
  line-height: 1.45;
  max-height: 78vh;
}

.history-list > div {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #cbd5e1;
}

.history-empty {
  color: #64748b;
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

h1 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 1.7rem;
}

.settings {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.size-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

.size-picker select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 700;
  background: #fff;
}

.mode-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

.mode-toggle input {
  width: 18px;
  height: 18px;
}

.rule {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 700;
  color: #334155;
  font-size: 0.93rem;
}

.role {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 700;
  color: #0369a1;
}

.status {
  margin: 0 0 16px;
  text-align: center;
  font-weight: 700;
}

.board {
  display: grid;
  gap: 8px;
}

.cell {
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: clamp(1.4rem, 7.5vw, 2.5rem);
  line-height: 1;
  font-weight: 900;
  color: var(--accent);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.cell:not(:disabled):hover {
  transform: scale(1.04);
}

.cell:disabled {
  cursor: not-allowed;
  opacity: 0.92;
}

.reset {
  margin-top: 16px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 12px;
  font-weight: 700;
  color: #fff;
  background: #0284c7;
  cursor: pointer;
}

.reset:hover {
  background: #0369a1;
}

.effect-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1;
}

.confetti {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  opacity: 0.95;
  animation: fall linear forwards;
}

.sad-drop {
  position: absolute;
  top: -20px;
  width: 8px;
  height: 16px;
  border-radius: 0 0 8px 8px;
  background: rgba(71, 85, 105, 0.55);
  animation: rain linear forwards;
}

.celebrate .container {
  animation: pop 0.45s ease;
}

.defeat .container {
  animation: shake 0.5s ease;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0.95;
  }
}

@keyframes rain {
  to {
    transform: translateY(110vh);
    opacity: 0.2;
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(8px);
  }
  60% {
    transform: translateX(-6px);
  }
  80% {
    transform: translateX(6px);
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
    padding: 12px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .history-list {
    max-height: 34vh;
  }
}
