:root {
  color-scheme: light;
  --ink: #202024;
  --muted: #62636c;
  --paper: #f5f1e8;
  --panel: #fffdf8;
  --line: #d8d1c4;
  --accent: #6b4cb8;
  --accent-dark: #42306f;
  --danger: #a73532;
  --clear: #17684c;
  --shadow: 0 18px 48px rgba(48, 42, 33, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 0;
  background: var(--paper);
}

body {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  line-height: 1.75;
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
}

.page-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 32px 18px 28px;
}

.hero {
  padding: 18px 0 24px;
}

.lab-label,
.eyebrow,
.input-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 6px 0 10px;
  font-size: clamp(2.15rem, 4.4vw, 4.5rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.lead {
  max-width: 720px;
  margin: 0;
  color: #3f4046;
  font-size: 1.05rem;
}

.game-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel-header,
.status-bar,
.controls,
.result-line {
  display: flex;
  align-items: center;
  gap: 14px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 2px 0 0;
  font-size: clamp(1.24rem, 2.5vw, 2rem);
  line-height: 1.32;
  letter-spacing: 0;
}

.round-badge {
  flex: 0 0 auto;
  min-width: 72px;
  border: 1px solid #c9c1b3;
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
  font-weight: 900;
  background: #f2eadc;
}

.status-bar {
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 12px;
  color: #4b4c53;
  font-weight: 800;
}

.pop-stage {
  position: relative;
  min-height: 270px;
  overflow: hidden;
  border: 1px dashed #bdb3a2;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(107, 76, 184, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(107, 76, 184, 0.07) 1px, transparent 1px),
    #fbf7ef;
  background-size: 28px 28px;
}

.stage-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.pop-card {
  position: absolute;
  left: 0;
  top: 0;
  max-width: calc(100% - 24px);
  min-width: 150px;
  border: 2px solid #342a45;
  border-radius: 8px;
  padding: 14px 16px;
  background: #fffefb;
  box-shadow: 0 14px 28px rgba(43, 37, 55, 0.18);
  transform: translate(var(--card-x, 12px), var(--card-y, 12px)) scale(1);
  transition: opacity 160ms ease, transform 160ms ease;
  will-change: transform;
}

.pop-card.is-live {
  animation: card-pop 180ms ease-out;
}

.pop-card.is-hard {
  animation: card-pop 180ms ease-out, card-drift 1.8s ease-in-out infinite alternate;
}

.card-kicker {
  display: block;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.card-text {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.55rem, 4vw, 2.65rem);
  font-weight: 900;
  line-height: 1.25;
}

.input-label {
  display: block;
  margin-top: 18px;
}

textarea {
  display: block;
  width: 100%;
  min-height: 108px;
  margin-top: 6px;
  border: 2px solid #bdb5a6;
  border-radius: 8px;
  padding: 14px;
  resize: vertical;
  background: #fff;
  color: var(--ink);
  font-size: 1.2rem;
}

textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(107, 76, 184, 0.18);
}

textarea:disabled {
  color: #74757b;
  background: #ece8df;
}

.controls {
  flex-wrap: wrap;
  margin-top: 16px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  background: var(--accent-dark);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

button.secondary {
  background: #4d4a44;
}

button:hover {
  filter: brightness(1.08);
}

button:focus-visible {
  outline: 3px solid rgba(107, 76, 184, 0.28);
  outline-offset: 2px;
}

.result-line {
  flex-wrap: wrap;
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

#judgeText {
  min-width: 118px;
  border-radius: 8px;
  padding: 8px 12px;
  background: #efe5d4;
  font-weight: 900;
  text-align: center;
}

#judgeText.is-clear {
  background: #d9efe4;
  color: var(--clear);
}

#judgeText.is-trapped {
  background: #f5d9d6;
  color: var(--danger);
}

#judgeText.is-complete {
  background: #e4deef;
  color: var(--accent-dark);
}

#statusText {
  min-width: 0;
  color: var(--muted);
}

.history-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #faf7ef;
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.history-list .clear {
  border-color: #9fcfb7;
  background: #e6f5ed;
  color: var(--clear);
}

.history-list .trapped {
  border-color: #e1aaa4;
  background: #fff0ee;
  color: var(--danger);
}

.notes {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(255, 253, 248, 0.7);
  color: #4d4e55;
}

.notes p {
  margin: 0;
}

.site-footer {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 0 18px 30px;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.site-footer a {
  color: #4d3e82;
  text-underline-offset: 3px;
}

@keyframes card-pop {
  0% {
    opacity: 0;
    transform: translate(var(--card-x, 12px), var(--card-y, 12px)) scale(0.86);
  }
  100% {
    opacity: 1;
    transform: translate(var(--card-x, 12px), var(--card-y, 12px)) scale(1);
  }
}

@keyframes card-drift {
  from {
    margin-left: -4px;
    margin-top: 0;
  }
  to {
    margin-left: 5px;
    margin-top: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pop-card,
  .pop-card.is-live,
  .pop-card.is-hard {
    animation: none;
    transition: none;
  }
}

@media (max-width: 620px) {
  .page-shell {
    padding: 22px 14px 22px;
  }

  .game-panel {
    padding: 16px;
  }

  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .round-badge {
    width: 100%;
    text-align: left;
  }

  .pop-stage {
    min-height: 245px;
  }

  .pop-card {
    min-width: 132px;
    padding: 12px 14px;
  }

  .history-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
