:root {
  color-scheme: light;
  --paper: #f6f1e8;
  --ink: #27231d;
  --muted: #70685c;
  --line: #d8cdbd;
  --card: #fffaf0;
  --accent: #275d63;
  --accent-2: #b4452f;
  --accent-3: #e0b44c;
  --shadow: 0 18px 48px rgba(55, 42, 27, 0.16);
  font-family: "Droid Sans Fallback", "Hiragino Sans", "Yu Gothic", "YuGothic", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(90deg, rgba(39, 93, 99, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(39, 93, 99, 0.045) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  color: var(--ink);
}

a {
  color: inherit;
}

button,
textarea {
  font: inherit;
}

.page-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 32px) 30px;
}

.lab-header {
  display: grid;
  gap: 9px;
  margin: 0 0 18px;
}

.lab-mark,
.lab-kicker {
  width: fit-content;
  margin: 0;
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.78);
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0;
}

.lab-mark {
  padding: 7px 10px;
  text-decoration: none;
  font-weight: 700;
}

.lab-kicker {
  padding: 5px 9px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.7rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h1 span {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.05rem, 2.5vw, 1.55rem);
  color: var(--accent);
}

.lead {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.game-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.93);
  box-shadow: var(--shadow);
  padding: clamp(14px, 2.4vw, 24px);
}

.rule-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.rule-strip div,
.score-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf7;
}

.rule-strip div {
  min-width: 0;
  padding: 10px;
}

.rule-strip strong,
.rule-strip span {
  display: block;
}

.rule-strip strong {
  color: var(--accent-2);
  font-size: 0.78rem;
}

.rule-strip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.score-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: space-between;
  padding: 10px 12px;
  font-weight: 700;
  color: var(--accent);
}

.noise-stage {
  position: relative;
  min-height: 265px;
  overflow: hidden;
  border: 1px solid #cbbba4;
  border-radius: 8px;
  background:
    radial-gradient(circle at 18% 20%, rgba(224, 180, 76, 0.18), transparent 30%),
    radial-gradient(circle at 82% 78%, rgba(39, 93, 99, 0.14), transparent 28%),
    #fbf6ea;
}

.stage-guide {
  position: absolute;
  inset: 18px auto auto 18px;
  z-index: 2;
  max-width: min(460px, calc(100% - 36px));
  border: 1px dashed #b9aa93;
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.84);
  padding: 12px 14px;
  color: var(--muted);
  line-height: 1.6;
}

[hidden] {
  display: none !important;
}

.noise-field {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.noise-bit {
  position: absolute;
  color: rgba(44, 37, 29, 0.33);
  font-weight: 800;
  font-size: var(--size, 1rem);
  transform: rotate(var(--rot, 0deg));
  user-select: none;
  white-space: nowrap;
}

.noise-field.is-hard .noise-bit {
  animation: noise-wobble var(--speed, 3.2s) ease-in-out infinite alternate;
}

.noise-bit:nth-child(3n) {
  color: rgba(180, 69, 47, 0.35);
}

.noise-bit:nth-child(4n) {
  color: rgba(39, 93, 99, 0.38);
}

.target-card {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: min(88%, 580px);
  transform: translate(-50%, -50%);
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.96);
  box-shadow: 0 12px 24px rgba(39, 35, 29, 0.18);
  padding: 16px clamp(14px, 3vw, 24px);
  text-align: center;
}

.target-label {
  display: inline-block;
  margin-bottom: 8px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}

#targetText {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 2.05rem);
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.input-label {
  font-weight: 800;
  color: var(--accent);
}

#answerInput {
  width: 100%;
  resize: vertical;
  min-height: 70px;
  border: 2px solid #c9baa2;
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 13px 14px;
  line-height: 1.55;
}

#answerInput:focus {
  outline: 3px solid rgba(39, 93, 99, 0.22);
  border-color: var(--accent);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fffdf8;
}

.ghost-button {
  background: #fffdf8;
  color: var(--accent);
}

.status-text {
  margin: 0;
  color: var(--accent-2);
  font-weight: 900;
}

.game-card.is-clear .status-text {
  color: var(--accent);
}

.game-card.is-trapped .status-text {
  color: var(--accent-2);
}

.game-card.is-complete .status-text {
  color: #6d4f00;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 0;
}

.site-footer a {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
  padding: 10px 12px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
}

@keyframes noise-wobble {
  from {
    transform: translate(-2px, 1px) rotate(var(--rot, 0deg));
    opacity: 0.68;
  }
  to {
    transform: translate(3px, -2px) rotate(calc(var(--rot, 0deg) + 4deg));
    opacity: 0.34;
  }
}

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

  .lab-header {
    gap: 7px;
    margin-bottom: 12px;
  }

  h1 {
    font-size: 2.15rem;
  }

  .lead {
    font-size: 0.95rem;
  }

  .game-card {
    gap: 11px;
    padding: 12px;
  }

  .rule-strip {
    grid-template-columns: 1fr;
  }

  .rule-strip div {
    padding: 8px 10px;
  }

  .rule-strip span {
    font-size: 0.84rem;
  }

  .noise-stage {
    min-height: 230px;
  }

  .stage-guide {
    inset: 12px 12px auto 12px;
  }

  .target-card {
    width: calc(100% - 24px);
    padding: 14px 12px;
  }

  #answerInput {
    min-height: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .noise-field.is-hard .noise-bit {
    animation: none !important;
  }
}
