:root {
  color-scheme: light;
  --ink: #243044;
  --muted: #647087;
  --paper: #fffdf9;
  --line: #e9dfd0;
  --accent: #4169e1;
  --accent-dark: #3153bd;
  --accent-soft: #eef2ff;
  --warm: #fff4df;
  --shadow: 0 18px 50px rgba(69, 52, 31, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(255, 220, 153, 0.45), transparent 34rem), #f6f3ee;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}
button, textarea, input { font: inherit; }
.app-shell { width: min(100% - 32px, 680px); margin: 0 auto; padding: 40px 0 28px; }
.app-header { margin-bottom: 22px; text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .14em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.8rem, 7vw, 2.55rem); line-height: 1.2; }
.subtitle { margin-bottom: 0; color: var(--muted); line-height: 1.7; }
.room-card, .step-card { border: 1px solid var(--line); border-radius: 24px; background: rgba(255, 253, 249, .96); box-shadow: var(--shadow); }

.room-card {
  display: grid;
  grid-template-columns: 112px 1fr;
  grid-template-areas:
    "character speech"
    "character observation"
    "last-event last-event";
  gap: 14px 18px;
  align-items: start;
  min-height: 210px;
  padding: 28px;
}

.character-area { text-align: center; }
.character { display: grid; width: 92px; height: 92px; place-items: center; border: 1px solid #f4ddb3; border-radius: 50%; background: var(--warm); font-size: 3.35rem; }
.character-name { margin: 9px 0 0; font-size: .84rem; font-weight: 800; }
.speech-bubble { position: relative; padding: 18px 20px; border: 1px solid #dce3f9; border-radius: 18px; background: var(--accent-soft); line-height: 1.75; }
.speech-bubble::before { position: absolute; top: 26px; left: -10px; width: 18px; height: 18px; border-bottom: 1px solid #dce3f9; border-left: 1px solid #dce3f9; background: var(--accent-soft); content: ""; transform: rotate(45deg); }
.speech-bubble p, .last-event p { margin-bottom: 0; }
.last-event { grid-column: 1 / -1; padding: 12px 14px; border-radius: 14px; background: #f7f3eb; color: var(--muted); font-size: .88rem; }
.last-event-label { display: block; margin-bottom: 4px; color: #8a7351; font-size: .72rem; font-weight: 800; }
.step-card { margin-top: 18px; padding: 24px; }
.step-heading { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.step-heading h2 { margin-bottom: 0; font-size: 1.08rem; }
.step-number { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--ink); color: white; font-size: .82rem; font-weight: 800; }
label { font-size: .9rem; font-weight: 700; }
textarea { display: block; width: 100%; margin: 9px 0 12px; resize: vertical; border: 1px solid #cfd6e2; border-radius: 14px; padding: 13px 14px; background: white; color: var(--ink); line-height: 1.6; }
textarea:focus, button:focus-visible, input:focus-visible + span { outline: 3px solid rgba(65, 105, 225, .24); outline-offset: 2px; }
.primary-button { width: 100%; min-height: 48px; border: 0; border-radius: 14px; background: var(--accent); color: white; cursor: pointer; font-weight: 800; }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.primary-button:disabled { cursor: not-allowed; opacity: .42; }
.help-text { margin-bottom: 14px; color: var(--muted); font-size: .86rem; }
fieldset { margin: 0 0 14px; padding: 0; border: 0; }

.field-label {
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 800;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.action-option {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 2px solid #e4e7ed;
  border-radius: 14px;
  background: white;
  cursor: pointer;
}

.action-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.action-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.item-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.item-option { display: grid; gap: 5px; place-items: center; min-height: 104px; border: 2px solid #e4e7ed; border-radius: 16px; background: white; cursor: pointer; }
.item-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.item-option input { position: absolute; opacity: 0; pointer-events: none; }
.item-emoji { font-size: 2rem; }
.is-locked { box-shadow: none; opacity: .72; }
.save-status { min-height: 24px; margin: 14px 0 0; color: #2f6c45; font-size: .88rem; font-weight: 700; text-align: center; }
.state-card { margin-top: 18px; padding: 16px 18px; border: 1px dashed #d7c8b2; border-radius: 16px; background: #fbf7ef; color: var(--muted); font-size: .86rem; line-height: 1.65; }
.state-card h2 { margin-bottom: 6px; color: var(--ink); font-size: .96rem; }
.state-card p { margin-bottom: 0; }
footer { margin-top: 2px; text-align: center; }
.text-button { border: 0; padding: 10px; background: transparent; color: var(--muted); cursor: pointer; font-size: .8rem; text-decoration: underline; text-underline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 540px) {
  .app-shell { width: min(100% - 24px, 680px); padding-top: 26px; }
  
  .room-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "character"
      "speech"
      "observation"
      "last-event";
    justify-items: center;
    padding: 22px;
  }
  
  .speech-bubble {
    width: 100%;
    max-width: 100%;
  }
  .speech-bubble::before { top: -10px; left: calc(50% - 9px); border-top: 1px solid #dce3f9; border-right: 0; border-bottom: 0; border-left: 1px solid #dce3f9; }
  .item-grid { gap: 7px; }
  .item-option { min-height: 92px; }

  .observation-panel {
    grid-column: 1 / -1;
  }
}

.state-card summary {
  cursor: pointer;
  font-weight: 700;
}

.state-card[open] summary {
  margin-bottom: 8px;
}

.last-event summary {
  cursor: pointer;
}

.last-event[open] summary {
  margin-bottom: 6px;
}

.observation-panel {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 3px solid #d8c9a8;
  background: #fffaf0;
  border-radius: 8px;
}

.observation-label {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #8a6f3f;
}

#observation-message {
  margin: 0;
  line-height: 1.7;
}

.speech-bubble {
  justify-self: start;
  width: fit-content;
  min-width: 160px;
  max-width: min(100%, 420px);
}

.observation-panel {
  grid-column: 2 / -1;
  width: 100%;
  justify-self: stretch;
}


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

.mode-option {
  min-height: 52px;
  padding: 10px 12px;
  border: 2px solid #e4e7ed;
  border-radius: 14px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.mode-option.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

@media (max-width: 540px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}