:root {
  color-scheme: light;
  --paper: #fbf3e6;
  --paper-strong: #fffaf1;
  --ink: #2b241d;
  --muted: #746752;
  --line: #dcc8aa;
  --green: #536d48;
  --green-deep: #304734;
  --amber: #bd8741;
  --orange: #c66b3d;
  --red: #9b4c42;
  --shadow: 0 18px 48px rgba(75, 55, 30, .15);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: #f2e5d1;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  line-height: 1.7;
  background:
    radial-gradient(circle at 14% 6%, rgba(255, 255, 255, .86), transparent 31rem),
    linear-gradient(135deg, #fbf0dd 0%, #e8d7bc 100%);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.lab-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.title-bar {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 20px;
  align-items: end;
  padding: 22px 0 18px;
}

.home-link {
  color: var(--green-deep);
  font-weight: 800;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 250, 242, .8);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 1.04;
  letter-spacing: 0;
}

.lead {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.control-panel,
.order-board,
.input-panel,
.meter-grid article,
.result-panel,
.related-panel,
.prompt-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 249, 237, .9);
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 16px;
  margin-bottom: 16px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
}

.status-code {
  color: var(--paper-strong);
  background: var(--green-deep);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 800;
  font-size: .82rem;
}

.control-row,
.result-actions,
.related-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 800;
}

.primary-button {
  color: #fffaf0;
  background: var(--green-deep);
  border: 0;
}

.secondary-button {
  color: var(--green-deep);
  background: #efe0c6;
  border: 1px solid var(--line);
}

.primary-button:focus-visible,
.secondary-button:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(189, 135, 65, .38);
  outline-offset: 3px;
}

.toggle-label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
}

.order-board {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  padding: 22px;
  display: grid;
  gap: 14px;
  background:
    linear-gradient(90deg, rgba(83, 109, 72, .08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(83, 109, 72, .08) 1px, transparent 1px),
    linear-gradient(135deg, #fff7e9 0%, #eadabf 100%);
  background-size: 38px 38px, 38px 38px, auto;
}

.order-board::before,
.order-board::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border: 1px dashed rgba(83, 109, 72, .22);
  border-radius: 999px;
}

.order-board::before {
  width: 320px;
  height: 120px;
  right: -80px;
  top: 34px;
  transform: rotate(-10deg);
}

.order-board::after {
  width: 260px;
  height: 90px;
  left: -70px;
  bottom: 28px;
  transform: rotate(14deg);
}

.phase-ribbon {
  position: relative;
  z-index: 1;
  width: fit-content;
  color: #fffaf0;
  background: var(--amber);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 900;
  letter-spacing: .04em;
}

.order-board.is-shuffled .phase-ribbon {
  background: var(--orange);
}

.order-board.is-result .phase-ribbon {
  background: var(--green-deep);
}

.countdown-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
}

.countdown-wrap strong {
  color: var(--ink);
}

.order-card {
  position: relative;
  z-index: 1;
  min-height: 210px;
  border: 2px solid #caa36e;
  border-radius: 8px;
  padding: 24px;
  display: grid;
  align-content: center;
  gap: 14px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .42), transparent 35%, rgba(65, 45, 22, .05)),
    #fff6e5;
  box-shadow: inset 0 0 0 7px rgba(255, 232, 188, .28);
}

.phase-title {
  margin-bottom: 0;
  color: var(--green-deep);
  font-weight: 900;
  text-align: center;
}

.phrase-display {
  min-height: 4.2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: clamp(1.5rem, 3.2vw, 2.55rem);
  font-weight: 900;
  line-height: 1.45;
  text-align: center;
}

.phrase-display.is-idle {
  color: rgba(43, 36, 29, .5);
}

.phrase-display.is-memorize {
  display: block;
}

.phrase-display.is-shuffled {
  justify-content: center;
}

.phrase-chip {
  display: inline-flex;
  align-items: center;
  min-height: 2.25em;
  border: 1px solid rgba(111, 83, 45, .3);
  border-radius: 8px;
  padding: 5px 10px;
  background: #fffdf7;
  box-shadow: 0 6px 14px rgba(75, 55, 30, .12);
}

.phrase-chip:nth-child(2n) {
  transform: translateY(4px) rotate(-1deg);
}

.phrase-chip:nth-child(3n) {
  transform: translateY(-3px) rotate(1.4deg);
}

.board-note {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.input-panel {
  margin-top: 16px;
  padding: 16px;
}

.input-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

textarea {
  width: 100%;
  max-width: 100%;
  resize: vertical;
  min-height: 96px;
  border: 2px solid #cdb78f;
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fffdf8;
  font-size: 1.08rem;
}

textarea.is-active {
  border-color: var(--orange);
  box-shadow: 0 0 0 4px rgba(198, 107, 61, .14);
}

textarea:disabled {
  color: #8a7d68;
  background: #eee2cc;
}

.rule-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .92rem;
}

.meter-grid,
.result-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.meter-grid article,
.result-grid article {
  padding: 12px;
}

.meter-grid span,
.result-grid span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.meter-grid strong,
.result-grid strong {
  display: block;
  font-size: 1.25rem;
}

.result-panel,
.related-panel,
.prompt-list {
  margin-top: 18px;
  padding: 18px;
}

.result-panel h2 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 5vw, 3.4rem);
}

.result-copy {
  color: var(--muted);
  font-weight: 700;
}

.review-panel {
  margin-top: 18px;
}

.review-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.review-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf0;
}

.review-card.is-scrambled {
  border-color: rgba(155, 76, 66, .4);
}

.review-card span,
.review-card small {
  display: block;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}

.review-card strong,
.review-card em {
  display: block;
}

.review-card strong {
  margin: 4px 0;
  color: var(--ink);
}

.review-card em {
  color: var(--orange);
  font-style: normal;
}

.related-links a {
  color: var(--green-deep);
  text-decoration: none;
  font-weight: 800;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fffaf0;
}

.prompt-list summary {
  cursor: pointer;
  font-weight: 800;
}

#allPrompts {
  columns: 2;
  margin-top: 12px;
  color: var(--muted);
}

#allPrompts p {
  break-inside: avoid;
  margin-bottom: 8px;
}

@media (max-width: 760px) {
  .lab-shell {
    width: min(100% - 20px, 680px);
    padding-top: 12px;
  }

  .title-bar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .home-link {
    width: fit-content;
  }

  .order-board {
    min-height: 300px;
    padding: 16px;
  }

  .order-card {
    min-height: 205px;
    padding: 18px 14px;
  }

  .phrase-display {
    font-size: clamp(1.28rem, 6.4vw, 1.9rem);
  }

  .phrase-chip {
    padding: 4px 8px;
  }

  .meter-grid,
  .result-grid,
  .review-list {
    grid-template-columns: 1fr;
  }

  #allPrompts {
    columns: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }

  .phrase-chip {
    transform: none !important;
  }
}
