/* どっちにする？
   色・ボタン・ふきだし・たぎっくまは shared/css/base.css、見出し・緑の台・案内と操作・あそびかたの窓は
   shared/css/play.css にある。ここはこのツールだけの見た目 */

/* ---------- 台の上のならび ----------
   上から「お題の種類」「お題のふだ」「答えのカード2枚」「ほかの答え」。
   HTML の順番は、キーボードで回る順（カード → ほかの答え → 種類）にしてあるので、場所はここで決める */

.stage {
  --t-pick: 220ms; /* えらんだカードが持ち上がる速さ */
  --t-clear: 180ms; /* 片づける速さ */
  --card-shadow: 5px 16px 0 rgba(6, 48, 20, 0.3); /* 台に落ちる影 */
  --num: clamp(34px, 3.6vw, 50px); /* 番号の丸の大きさ */
  display: grid;
  grid-template:
    "kinds" auto
    "ask" auto
    "duo" minmax(0, 1fr)
    "other" auto / minmax(0, 1fr);
  justify-items: center;
  gap: clamp(8px, 1.8vh, 16px);
}

:root[data-motion="reduce"] .stage {
  --t-pick: 0ms;
  --t-clear: 160ms;
}

/* ---------- お題の種類 ----------
   広い画面では、ボタンを全部ならべて出す。入りきらないときは折り返す（横スクロールにしない） */

.kinds {
  grid-area: kinds;
  justify-self: stretch;
  min-width: 0;
}

.kinds__list {
  font-size: 0; /* ボタンのあいだに、文字のすき間が入らないようにする */
  margin-bottom: -6px; /* ボタンの下のすき間（折り返したときの行間）を、いちばん下では打ち消す */
}

.kinds__list .kinds__label {
  margin-bottom: 0;
}

.kinds__toggle {
  display: none;
}

.kind[data-kind="tabemono"],
.stage[data-cat="tabemono"] {
  --cat: var(--sun);
  --cat-pale: #ffefc2;
}

.kind[data-kind="asobi"],
.stage[data-cat="asobi"] {
  --cat: var(--coral);
  --cat-pale: #ffe1db;
}

.kind[data-kind="moshimo"],
.stage[data-cat="moshimo"] {
  --cat: var(--lilac);
  --cat-pale: #ebe2fb;
}

.kind[data-kind="doubutsu"],
.stage[data-cat="doubutsu"] {
  --cat: var(--green);
  --cat-pale: #d6f0dd;
}

.kind[data-kind="kurashi"],
.stage[data-cat="kurashi"] {
  --cat: var(--sky);
  --cat-pale: #dcecfa;
}

/* ---------- 出てくる・片づける ----------
   お題のふだ・カード・「ほかの答え」は、外がわの箱（ここ）が出入りの動きを受けもち、
   内がわ（.opt__card など）が「持ち上がる・えらばれる」の動きを受けもつ。
   2つを分けておくと、出てくる途中でも、さわった手ごたえが遅れない */

.ask,
.opt,
.other,
.duo__or {
  transition: transform var(--t-move) var(--ease-back), opacity var(--t-move) ease;
}

.stage[data-state="loading"] :is(.ask, .opt, .other, .duo__or),
.stage[data-state="clearing"] :is(.ask, .opt, .other, .duo__or) {
  opacity: 0;
  pointer-events: none;
}

.stage[data-state="clearing"] :is(.ask, .opt, .other, .duo__or) {
  transition-duration: var(--t-clear);
  transition-timing-function: ease-in;
}

.stage[data-state="loading"] .ask,
.stage[data-state="clearing"] .ask {
  transform: translateY(-18px) scale(0.96);
}

.stage[data-state="loading"] .opt[data-n="1"],
.stage[data-state="clearing"] .opt[data-n="1"] {
  transform: translateX(-28%) rotate(-7deg);
}

.stage[data-state="loading"] .opt[data-n="2"],
.stage[data-state="clearing"] .opt[data-n="2"] {
  transform: translateX(28%) rotate(7deg);
}

.stage[data-state="loading"] .other,
.stage[data-state="clearing"] .other {
  transform: translateY(16px);
}

.stage[data-state="loading"] .duo__or,
.stage[data-state="clearing"] .duo__or {
  transform: rotate(-6deg) scale(0.4);
}

/* 出てくるときは、ふだ → 1番 → 2番 → まんなかの印、の順に少しずつずらす */
.stage[data-state="asking"] .opt[data-n="1"] {
  transition-delay: 60ms;
}

.stage[data-state="asking"] .opt[data-n="2"] {
  transition-delay: 140ms;
}

.stage[data-state="asking"] .other {
  transition-delay: 200ms;
}

.stage[data-state="asking"] .duo__or {
  transition-delay: 260ms;
}

/* 動きを減らすとき：すべらせず、ふわっと出すだけ */
:root[data-motion="reduce"] .stage :is(.ask, .opt, .other) {
  transform: none;
  transition: opacity 160ms ease;
  transition-delay: 0ms;
}

:root[data-motion="reduce"] .stage .duo__or {
  transform: rotate(-6deg);
  transition: opacity 160ms ease;
  transition-delay: 0ms;
}

/* ---------- お題のふだ ---------- */

.ask {
  grid-area: ask;
  position: relative;
  display: grid;
  justify-items: center;
  max-width: min(100%, 1040px);
  margin-top: 8px; /* 左上にはみ出している、種類のしるしのぶん */
  padding: 0.42em 1.3em 0.4em;
  border: 3px solid var(--line);
  border-radius: clamp(16px, 2.2vw, 26px);
  background: var(--paper);
  box-shadow: 0 5px 0 var(--line), var(--card-shadow);
  font-size: clamp(19px, min(3.3vw, 5.4vh), 44px);
}

/* お題。文節の区切り（<wbr>）でだけ改行する */
.ask__text {
  font-weight: 900;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-align: center;
  word-break: keep-all;
  text-wrap: balance;
}

.ask__text span,
.opt__text span {
  white-space: nowrap;
}

.ask__note {
  color: var(--ink-soft);
  font-size: clamp(12px, 0.4em, 16px);
  line-height: 1.5;
  text-align: center;
}

/* どの種類のお題か。ふだの左上のふちに、しるしとして重ねる */
.chip {
  position: absolute;
  top: 0;
  left: clamp(12px, 1.6vw, 22px);
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.1em 0.9em 0.1em 0.55em;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--cat-pale, var(--cream-deep));
  font-size: clamp(12px, 1.1vw, 15px);
  font-weight: 900;
  line-height: 1.5;
  white-space: nowrap;
  transform: translateY(-58%) rotate(-2deg);
}

.chip__dot {
  width: 0.7em;
  height: 0.7em;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--cat, var(--coral));
}

/* ---------- 答えのカード2枚 ---------- */

.duo {
  grid-area: duo;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(10px, 1.8vw, 26px);
  width: min(100%, 1040px);
  min-height: 0;
  height: 100%;
  /* 上は、カードのふちに乗っている番号の丸のぶん。下は、カードの厚みのぶん */
  padding: calc(var(--num) * 0.5) 0 7px;
}

/* 2枚を縦にならべる（縦長の画面）。app.js が、カード置き場の形から決める */
.stage[data-duo="col"] .duo {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: calc(var(--num) * 0.5 + 8px);
  width: min(100%, 720px);
}

/* 押すところ。出入りの動きだけを受けもち、見た目は内がわの .opt__card にある */
.opt {
  position: relative;
  min-width: 0;
  height: 100%;
  max-height: 360px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.opt[data-n="1"] {
  --tone: var(--coral);
  --tone-pale: #ffe1db;
  --lean: -1.5deg;
}

.opt[data-n="2"] {
  --tone: var(--sky);
  --tone-pale: #dcecfa;
  --lean: 1.5deg;
}

.opt__card {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  /* 上は、ふちに乗っている番号の丸のぶん */
  padding: calc(var(--num) * 0.5 + 2px) 5% 6px;
  border: 3px solid var(--line);
  border-radius: clamp(16px, 2.2vw, 26px);
  background: var(--paper);
  box-shadow: 0 7px 0 var(--line), var(--card-shadow);
  transition: transform var(--t-pick) var(--ease-back), box-shadow var(--t-pick) ease, background-color var(--t-pick) ease;
}

/* 番号。カードの上のふちに、半分はみ出して乗せる（答えの文字の場所をとらない） */
.opt__num {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--num);
  height: var(--num);
  border: 2.5px solid var(--line);
  border-radius: 50%;
  background: var(--tone);
  font-size: calc(var(--num) * 0.54);
  font-weight: 900;
  line-height: 1;
  padding-bottom: calc(var(--num-lift) * 2);
}

.opt__card .opt__num {
  position: absolute;
  top: calc(var(--num) * -0.5);
  left: 50%;
  margin-left: calc(var(--num) * -0.5);
}

/* 答えの文字を入れる枠。大きさは app.js が、この枠に合わせる */
.opt__box {
  min-width: 0;
  min-height: 0;
  display: grid;
  /* 列の幅を枠の幅に固定する（auto のままだと、長い文字に合わせて列が広がり、はみ出しをはかれない） */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
}

/* 答え。文節の区切り（<wbr>）でだけ改行する */
.opt__text {
  width: 100%;
  font-weight: 900;
  line-height: 1.3;
  letter-spacing: 0.02em;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: normal;
}

.opt__text.is-tight,
.opt__text.is-tight span {
  white-space: normal;
  overflow-wrap: anywhere;
}

/* えらんだしるし。正解・不正解に見えないよう、丸やチェックではなく「これ！」のふだにする */
.opt__tag {
  position: absolute;
  top: -0.9em;
  right: -0.5em;
  padding: 0.05em 0.8em 0.1em;
  border: 2.5px solid var(--line);
  border-radius: 999px;
  background: var(--sun);
  font-size: clamp(14px, 1.7vw, 22px);
  font-weight: 900;
  line-height: 1.5;
  white-space: nowrap;
  transform: rotate(7deg) scale(0);
  transition: transform var(--t-pick) var(--ease-back);
}

[aria-pressed="true"] .opt__tag {
  transform: rotate(7deg) scale(1);
}

/* さわれるカードは、マウスを乗せる・キーボードで選ぶと少し持ち上がる */
.opt:focus-visible,
.other:focus-visible {
  outline: none;
}

.opt:focus-visible .opt__card,
.other:focus-visible .other__in {
  outline: 4px solid var(--cream);
  outline-offset: 4px;
}

.opt:focus-visible .opt__card {
  transform: translateY(-5px) rotate(var(--lean));
}

@media (hover: hover) {
  .opt:hover .opt__card {
    transform: translateY(-5px) rotate(var(--lean));
  }

  .other:hover .other__in {
    transform: translateY(-3px);
  }
}

/* えらんだカード：色がついて、持ち上がる。影は遠くなる */
.opt[aria-pressed="true"] .opt__card {
  background: var(--tone-pale);
  box-shadow: 0 7px 0 var(--line), 9px 27px 0 rgba(6, 48, 20, 0.3);
  transform: translateY(-9px) rotate(var(--lean)) scale(1.03);
}

/* えらばなかったほうは、台に少ししずむ（押し直せば、えらび直せる） */
.stage:is([data-picked="1"], [data-picked="2"], [data-picked="3"]) .opt[aria-pressed="false"]:not(:hover, :focus-visible) .opt__card {
  box-shadow: 0 3px 0 var(--line), 2px 7px 0 rgba(6, 48, 20, 0.3);
  transform: translateY(4px);
}

.opt:active .opt__card,
.opt[aria-pressed="true"]:active .opt__card {
  box-shadow: 0 3px 0 var(--line), 2px 7px 0 rgba(6, 48, 20, 0.3);
  transform: translateY(4px);
}

/* まんなかの印。押せるものではないので、台にかいてある模様として出す（厚みを付けない） */
.duo__or {
  display: grid;
  place-items: center;
  width: clamp(58px, 6.6vw, 96px);
  aspect-ratio: 1;
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: var(--green-deep);
  color: var(--cream);
  font-size: clamp(12px, 1.4vw, 19px);
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  transform: rotate(-6deg);
}

/* 縦にならべたとき・せまい画面では、カードを広く使うために印をはぶく */
.stage[data-duo="col"] .duo__or {
  display: none;
}

/* ---------- ほかの答え ---------- */

.other {
  grid-area: other;
  position: relative;
  margin-bottom: 6px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.other .opt__num {
  --num: 30px;
  --tone: var(--sun);
}

.other__in {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 4px 24px 4px 8px;
  border: 2.5px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--line), 3px 11px 0 rgba(6, 48, 20, 0.3);
  font-size: clamp(15px, 1.5vw, 19px);
  font-weight: 900;
  line-height: 1.3;
  transition: transform var(--t-pick) var(--ease-back), box-shadow var(--t-pick) ease, background-color var(--t-pick) ease;
}

/* 「ほかの答え」のしるしは、右横に出す（上に出すと、すぐ上のカードに重なる） */
.other .opt__tag {
  top: 50%;
  right: 0;
  font-size: clamp(13px, 1.3vw, 17px);
  transform: translate(78%, -50%) rotate(7deg) scale(0);
}

.other[aria-pressed="true"] .opt__tag {
  transform: translate(78%, -50%) rotate(7deg) scale(1);
}

.other[aria-pressed="true"] .other__in {
  background: #ffefc2;
  box-shadow: 0 5px 0 var(--line), 6px 18px 0 rgba(6, 48, 20, 0.3);
  transform: translateY(-5px);
}

.other:active .other__in,
.other[aria-pressed="true"]:active .other__in {
  box-shadow: 0 2px 0 var(--line), 2px 5px 0 rgba(6, 48, 20, 0.3);
  transform: translateY(3px);
}

/* ---------- せまい画面（スマホ）・高さのない画面（スマホを横にしたとき） ----------
   種類のボタンを1つにたたんで、カードの場所をあける。押すと、ならんで出てくる */

@media (max-width: 760px), (max-height: 520px) {
  .kinds {
    justify-self: start;
  }

  .kinds__toggle {
    display: inline-flex;
    margin: 0;
    padding-left: 12px;
  }

  .kinds__toggle-label::after {
    content: "：";
  }

  .kinds__toggle svg {
    width: 14px;
    height: 14px;
    transition: transform var(--t-fast) ease;
  }

  .kinds.is-open .kinds__toggle svg {
    transform: rotate(180deg);
  }

  /* ならんで出てくる場所。台と同じ見た目の小さな板にして、カードの上に重ねる */
  .kinds__list {
    position: absolute;
    top: 44px;
    right: 0;
    left: 0;
    z-index: 5;
    display: none;
    margin: 0;
    padding: 12px 6px 6px 12px;
    border: 3px solid var(--line);
    border-radius: 18px;
    background: var(--green);
    box-shadow: 0 5px 0 var(--line);
  }

  .kinds.is-open .kinds__list {
    display: block;
  }

  .kinds__list .kinds__label {
    display: none;
  }
}

@media (max-width: 760px) {
  .stage {
    --num: 32px;
    --card-shadow: 3px 10px 0 rgba(6, 48, 20, 0.3);
    gap: 8px;
  }

  .ask {
    padding-inline: 0.9em;
    border-radius: 16px;
  }

  .chip {
    left: 10px;
  }

  .opt__card {
    border-radius: 16px;
  }

  .opt__tag {
    right: -4px;
  }

  .other__in {
    min-height: 42px;
  }

  .other .opt__num {
    --num: 28px;
  }
}

/* 横にならべたままの、せまい画面では、カードを広く使うために印をはぶく */
@media (max-width: 480px) {
  .duo {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .duo__or {
    display: none;
  }

  /* カードの幅がせまいので、番号を左によせて、右上の「これ！」と重ならないようにする */
  .stage[data-duo="row"] .opt__card .opt__num {
    left: 27%;
  }
}

/* 縦長で、高さの足りない画面（小さいスマホ・ブラウザの帯で画面がせまくなったとき）：
   カードの場所をあけるために、流れの表示と「なんとなくでOK」をはぶき、
   種類のボタンを「ほかの答え」と同じ段（いちばん下）に置く */
@media (max-width: 760px) and (min-height: 521px) and (max-height: 640px) {
  .steps {
    display: none;
  }

  .dock {
    --dock-h: 64px;
  }

  .stage {
    grid-template:
      "ask ask" auto
      "duo duo" minmax(0, 1fr)
      "kinds other" auto / minmax(0, 1fr) auto;
    align-items: center;
  }

  .ask__note {
    display: none;
  }

  .ask {
    padding-block: 0.3em;
  }

  .kinds {
    min-width: 0;
    max-width: 100%;
  }

  .kinds__toggle {
    max-width: 100%;
  }

  /* 場所がないので、「お題の種類」を「種類」とだけ出す */
  .kinds__toggle-label {
    font-size: 0;
  }

  .kinds__toggle-label::before {
    content: "種類";
    font-size: 13px;
  }

  .kinds__toggle-label::after {
    font-size: 13px;
  }

  /* 種類のボタンは、上に向かって出す */
  .kinds__list {
    top: auto;
    bottom: 52px;
  }

  .other {
    justify-self: end;
    margin-bottom: 6px;
  }

  .other .opt__tag,
  .other[aria-pressed="true"] .opt__tag {
    top: -1em;
    right: -4px;
    transform: rotate(7deg) scale(0);
  }

  .other[aria-pressed="true"] .opt__tag {
    transform: rotate(7deg) scale(1);
  }
}

/* 高さのない画面：1段目に「種類」と「お題のふだ」、2段目に「カード2枚」と「ほかの答え」を横にならべる */
@media (max-height: 520px) {
  .stage {
    --num: 30px;
    --card-shadow: 3px 10px 0 rgba(6, 48, 20, 0.3);
    grid-template:
      "kinds ask ask" auto
      "duo duo other" minmax(0, 1fr) / auto minmax(0, 1fr) auto;
    gap: 6px 10px;
    align-items: center;
  }

  .kinds__list {
    top: 38px;
  }

  .ask {
    justify-self: start;
    margin-top: 6px;
    padding: 0.2em 1em 0.24em;
    border-radius: 14px;
    font-size: clamp(17px, 5.6vh, 24px);
  }

  .ask__text span {
    white-space: normal; /* 1行におさめたいので、文節にこだわらず流しこむ */
  }

  /* 高さがないので、種類のしるしと「なんとなくでOK」ははぶく（たぎっくまが言ってくれる） */
  .ask .chip,
  .ask__note {
    display: none;
  }

  .duo {
    width: 100%;
    gap: 10px;
  }

  .opt__card {
    border-radius: 14px;
  }

  .opt__card,
  .opt[aria-pressed="true"] .opt__card {
    box-shadow: 0 5px 0 var(--line), var(--card-shadow);
  }

  .opt[aria-pressed="true"] .opt__card {
    transform: translateY(-5px) rotate(var(--lean)) scale(1.02);
  }

  /* 「ほかの答え」は、3枚目の小さなカードにする */
  .other {
    align-self: stretch;
    margin: 0;
    padding: calc(var(--num) * 0.5) 0 7px;
  }

  .other__in {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 86px;
    height: 100%;
    min-height: 0;
    padding: 4px 6px;
    border-radius: 14px;
    font-size: 15px;
    text-align: center;
  }

  .other__text {
    display: grid;
  }

  /* しるしは、小さなカードの右上のかどに出す */
  .other .opt__tag,
  .other[aria-pressed="true"] .opt__tag {
    top: -0.9em;
    right: -6px;
    transform: rotate(7deg) scale(0);
  }

  .other[aria-pressed="true"] .opt__tag {
    transform: rotate(7deg) scale(1);
  }
}

/* ---------- あそびかたの絵 ---------- */

/* このツールの流れは2つなので、2コマにする */
@media (min-width: 641px) {
  .howto__steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hstep__art {
    aspect-ratio: 16 / 8;
  }
}

/* 小さな「お題のふだ」 */
.dmini-ask {
  position: absolute;
  top: 9%;
  left: 12%;
  display: grid;
  place-items: center;
  width: 46%;
  height: 18%;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--line);
}

.dmini-ask u {
  width: 62%;
  height: 5px;
  border-radius: 999px;
  background: var(--ink-soft);
}

/* 小さな「答えのカード」 */
.dmini {
  position: absolute;
  top: 46%;
  display: grid;
  place-items: center;
  width: 25%;
  height: 34%;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--line), 3px 9px 0 rgba(6, 48, 20, 0.3);
}

.dmini--1 {
  left: 8%;
  transform: rotate(-3deg);
}

.dmini--2 {
  left: 38%;
}

/* えらんだ1枚は、色がついて、浮いている */
.dmini--up {
  background: #dcecfa;
  box-shadow: 0 3px 0 var(--line), 6px 18px 0 rgba(6, 48, 20, 0.3);
  transform: translateY(-10%) rotate(3deg);
}

.dmini b {
  display: grid;
  place-items: center;
  width: clamp(18px, 3vw, 24px);
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--coral);
  font-size: clamp(11px, 1.8vw, 14px);
  font-weight: 900;
  line-height: 1;
  padding-bottom: calc(var(--num-lift) * 2);
}

.dmini--2 b {
  background: var(--sky);
}

.dmini i {
  position: absolute;
  top: -32%;
  right: -26%;
  padding: 0 7px 1px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--sun);
  font-size: clamp(9px, 1.4vw, 12px);
  font-style: normal;
  font-weight: 900;
  line-height: 1.5;
  white-space: nowrap;
  transform: rotate(7deg);
}

/* スマホでは、絵の枠が縦長になるので、ふだとカードを大きめにする */
@media (max-width: 640px) {
  .dmini-ask {
    top: 10%;
    left: 10%;
    width: 62%;
    height: 15%;
  }

  .dmini {
    top: 38%;
    width: 34%;
    height: 27%;
  }

  .dmini--1 {
    left: 8%;
  }

  .dmini--2 {
    left: 50%;
  }

  .dmini i {
    top: -42%;
    right: -22%;
  }
}
