:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-synthesis: none;
  color: #392e39;
  background: #fff;
  --accent: #914766;
  --accent-dark: #76354f;
  --accent-soft: #f6edf2;
  --line: #e9e1e8;
  --muted: #7b6b79;
  --paper: #fff;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, summary:focus-visible {
  outline: 3px solid #b586a2;
  outline-offset: 3px;
}
[hidden] { display: none !important; }
h1, h2, p { overflow-wrap: anywhere; }
h2 { margin: 0; font-size: 17px; }
.game-shell {
  width: 100%;
  max-width: 450px;
  margin: 0 auto;
  padding: 10px 14px max(20px, env(safe-area-inset-bottom));
}
.notice {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  line-height: 1.65;
}
.notice.error { background: #fae9eb; color: #9b354d; }
#retry, #cancel { margin: 0 0 12px; }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 14px;
}
#selection-count {
  padding: 5px 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
input[type=search], select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  color: inherit;
  background: var(--paper);
  font-size: 16px;
}
input[type=search] {
  margin-bottom: 14px;
  padding-left: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%23877687' stroke-width='1.7' viewBox='0 0 24 24'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='m16 16 4 4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 13px center;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
.cast-picker {
  max-height: min(390px, 42svh);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  padding: 2px 3px 4px;
}
.cast-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 9px;
}
.cast-card {
  position: relative;
  min-width: 0;
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}
.cast-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  border-radius: 10px;
  background: #f4f1f3;
  object-fit: cover;
  object-position: center top;
}
.cast-card span {
  display: block;
  min-height: 2.5em;
  margin-top: 6px;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.cast-card[aria-pressed=true] {
  color: var(--accent);
}
.cast-card[aria-pressed=true] img {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.cast-card[aria-pressed=true]::after {
  content: "✓";
  position: absolute;
  right: 6px;
  top: 6px;
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
}
.selected-casts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.selected-casts:empty { margin: 0; }
.selected-casts button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px 4px 0;
  background: transparent;
  color: var(--accent);
}
.selected-casts img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; object-position: top; }
.selected-casts span { font-size: 18px; line-height: 1; }
.host-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 20px 0 14px;
}
.host-choice legend { margin-bottom: 9px; color: var(--muted); font-size: 11px; }
.host-choice label {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 8px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 9px 12px;
  background: #f7f5f6;
  font-size: 13px;
  cursor: pointer;
}
input[type=radio] { accent-color: var(--accent); }
#setup-animal-wrap > label, #next-animal-wrap > label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
}
.small { color: var(--muted); font-size: 12px; }
.primary {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
}
.primary:active:not(:disabled) { background: var(--accent-dark); }
.start-button { display: block; width: 100%; min-height: 50px; margin: 18px 0 0; }
.secondary {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 9px 15px;
  background: #f6f2f4;
  color: var(--accent-dark);
  font-size: 12px;
}
.text-button {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  padding: 9px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
#more { display: block; margin: 9px auto 0; }
#play {
  padding: 0;
  background: var(--paper);
}
.round-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  flex-wrap: wrap;
  border-bottom: 1px solid #f0eaf0;
  color: var(--muted);
  font-size: 11px;
}
#round { color: var(--accent); font-weight: 600; letter-spacing: .04em; }
#turns { font-variant-numeric: tabular-nums; }
#turns[data-low=true] { color: var(--accent-dark); font-weight: 700; }
#change-casts { margin-left: auto; padding-right: 0; font-size: 10px; }
.participants { display: flex; justify-content: center; gap: 10px; padding: 12px 0; }
.participant {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 108px;
  text-align: center;
}
.participant img {
  display: block;
  width: 54px;
  height: 54px;
  margin: 0 auto;
  border: 0;
  border-radius: 50%;
  background: #eee8ee;
  object-fit: cover;
  object-position: top;
}
.participant strong { overflow-wrap: anywhere; display: block; margin-top: 8px; font-size: 11px; font-weight: 500; line-height: 1.45; }
.participant.is-host img { outline: 2px solid var(--accent); outline-offset: 3px; }
.participant span {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 9px;
  line-height: 1.4;
  white-space: nowrap;
}
.role-note {
  width: fit-content;
  margin: 0 auto 12px;
  border-radius: 10px;
  padding: 7px 12px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
}
.messages {
  height: 40vh;
  height: 40svh;
  min-height: 180px;
  max-height: 380px;
  border-top: 1px solid #f0eaf0;
  padding: 16px 0 4px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: #dbcbd7 transparent;
  scroll-behavior: smooth;
}
.message { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 15px; }
.message > div { min-width: 0; max-width: calc(100% - 44px); }
.message img {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eee8ee;
  object-fit: cover;
  object-position: top;
}
.message-name { overflow-wrap: anywhere; display: block; margin: 0 0 5px 2px; color: var(--muted); font-size: 10px; }
.message p {
  margin: 0;
  border-radius: 12px;
  padding: 11px 13px;
  background: #f6f4f5;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.user { justify-content: flex-end; }
.message.user .message-name { margin-right: 2px; text-align: right; }
.message.user p { border-radius: 12px; background: var(--accent-soft); }
.system-message { margin: 8px 0 16px; color: var(--muted); font-size: 11px; text-align: center; line-height: 1.7; }
#playing-tools { border-top: 1px solid #f0eaf0; padding-top: 10px; }
.action-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0;
  margin: 0 0 10px;
  background: transparent;
}
.action-tabs label { position: relative; min-width: 0; cursor: pointer; }
.action-tabs input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.action-tabs span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 12px;
}
.action-tabs input:checked + span { border-bottom-color: var(--accent); color: var(--accent-dark); font-weight: 600; }
.action-tabs input:focus-visible + span { outline: 3px solid #b586a2; outline-offset: 1px; }
.action-tabs input:disabled + span { opacity: .5; cursor: default; }
.input-row { display: flex; align-items: stretch; gap: 8px; }
.input-row textarea {
  flex: 1;
  min-width: 0;
  min-height: 58px;
  max-height: 130px;
  border: 1px solid #e0d4de;
  border-radius: 10px;
  padding: 13px 12px;
  background: var(--paper);
  color: inherit;
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
}
.input-row .primary { padding: 10px 15px; }
.tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0 10px; }
.tools .secondary { min-height: 38px; padding: 7px 13px; }
.tools .text-button { min-height: 44px; padding: 7px 2px 7px 10px; font-size: 11px; }
.result { border-top: 1px solid var(--line); padding: 22px 2px 18px; text-align: center; }
.result h2 { font-size: 25px; font-weight: 600; line-height: 1.5; }
.result[data-outcome=solved] h2 { color: var(--accent); }
.result .host-choice { text-align: left; }
.result .primary { width: 100%; margin-top: 14px; }
.howto { margin-top: 16px; color: var(--muted); font-size: 11px; line-height: 1.8; }
.howto summary { width: fit-content; min-height: 38px; padding: 8px 0; cursor: pointer; }
.howto p { margin: 4px 0 8px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 360px) {
  .game-shell { padding-inline: 10px; }
  .cast-grid { gap: 10px 6px; }
  .participant img { width: 50px; height: 50px; }
  .input-row .primary { padding-inline: 11px; }
}
/* Keep the transcript and composer together within the mobile visual viewport.
   The play region scrolls when controls exceed the available height. */
.game-shell[data-playing=true] {
  display: flex;
  flex-direction: column;
  height: var(--game-height, calc(100dvh - 88px));
  min-height: 320px;
  padding-block: 0 max(6px, env(safe-area-inset-bottom));
}
.game-shell[data-playing=true] > :not(#play) { flex-shrink: 0; }
.game-shell[data-playing=true] .notice { margin-bottom: 4px; padding-block: 5px; }
.game-shell[data-playing=true] #play {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
#play > :not(.conversation) { flex-shrink: 0; }
.conversation { display: flex; flex-direction: column; flex: 1; min-height: 64px; }
.conversation .messages { flex: 1; height: auto; min-height: 0; max-height: none; padding-top: 10px; }
#playing-tools { padding-top: 5px; }
.action-tabs { margin-bottom: 5px; }
.input-label { display: block; margin: 0 0 4px; color: var(--accent-dark); font-size: 11px; line-height: 1.5; }
.input-note { margin: 0 0 5px; color: var(--accent-dark); font-size: 12px; line-height: 1.5; }
.question-examples { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 5px; }
.question-examples button {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 5px 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
}
.tools { padding-block: 2px; }
.tools .secondary, .tools .text-button { min-height: 44px; }
.game-shell[data-playing=true] .howto { margin-top: 0; }
.game-shell[data-playing=true] .howto[open] { max-height: 22svh; overflow-y: auto; }
.game-shell[data-compact=true] .participants { gap: 6px; padding: 6px 0; }
.game-shell[data-compact=true] .participant { display: grid; grid-template-columns: 28px 1fr; column-gap: 5px; align-items: center; text-align: left; max-width: none; }
.game-shell[data-compact=true] .participant img { grid-row: 1 / 3; width: 28px; height: 28px; }
.game-shell[data-compact=true] .participant strong { margin: 0; font-size: 10px; }
.game-shell[data-compact=true] .participant span { margin: 0; }
.game-shell[data-compact=true] .role-note { margin-bottom: 4px; padding-block: 3px; }
.game-shell[data-compact=true] .question-examples { display: none; }
.game-shell[data-compact=true] .input-row textarea { min-height: 48px; padding-block: 6px; }
#play[data-finished=true] { overflow-y: auto; }
#play[data-finished=true] .participants { display: none; }
#play[data-finished=true] .result { order: 1; border-top: 0; padding: 12px 0 8px; }
#play[data-finished=true] .conversation { order: 2; flex: none; min-height: 0; }
#play[data-finished=true] .messages { flex: none; height: 64px; }
#play[data-finished=true] .conversation[data-expanded=true] .messages { height: 40svh; min-height: 120px; }
#history-toggle { align-self: flex-start; min-height: 44px; }
.result-summary { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.next-settings { margin-top: 5px; text-align: left; }
.next-settings summary { min-height: 44px; padding: 12px 4px; color: var(--accent-dark); font-size: 12px; cursor: pointer; }
.next-settings .host-choice { margin: 6px 0 10px; }

@media (prefers-reduced-motion: reduce) {
  .messages { scroll-behavior: auto; }
}
