/* 訪問看護 制度学習すごろく — iPad Safari 横向き前提 */
:root {
  --navy: #1f2a44;
  --navy-2: #2d3b5f;
  --cream: #fff8e7;
  --ink: #3b2a1a;
  --orange: #f28c28;
  --orange-d: #c86a10;
  --green: #3fae5a;
  --green-l: #d9f5e0;
  --red: #e5484d;
  --red-l: #fde1e2;
  --gray: #8a8f9c;
  --btn-min: 64px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 22px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

img { image-rendering: pixelated; -webkit-user-drag: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#app {
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- 縦向き警告 ---------- */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--navy);
  color: #fff;
  font-size: 34px;
  font-weight: bold;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}
.rotate-icon { font-size: 72px; }
@media (orientation: portrait) {
  #rotate { display: flex; }
  #app { display: none; }
}

/* ---------- 共通 ---------- */
.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--navy);
  background-size: cover;
  background-position: center;
  position: relative;
}
.screen.has-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(20, 28, 50, .62), rgba(20, 28, 50, .78));
  pointer-events: none;
}
.screen > * { position: relative; }

.btn {
  min-height: var(--btn-min);
  min-width: var(--btn-min);
  padding: 8px 22px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  background: var(--orange);
  color: #fff;
  font-weight: bold;
  font-size: 24px;
  box-shadow: 0 6px 0 var(--orange-d);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--orange-d); }
.btn.sub {
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 6px 0 #c9b98f;
  text-shadow: none;
  font-size: 20px;
}
.btn.sub:active { box-shadow: 0 2px 0 #c9b98f; }

.chip {
  display: inline-block;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: bold;
  line-height: 26px;
  background: var(--navy-2);
  color: #fff;
}
.chip.review { background: #b26a00; }
.chip.pending { background: var(--red); }
.chip.basis { background: #e9dfc2; color: var(--ink); font-weight: normal; }

/* ---------- ステージ選択 ---------- */
.select-head { text-align: center; padding: 22px 16px 6px; color: #fff; }
.select-head h1 { margin: 0; font-size: 38px; text-shadow: 0 3px 0 rgba(0, 0, 0, .4); }
.select-head p { margin: 4px 0 0; font-size: 22px; opacity: .9; }
.select-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 24px;
  padding: 12px 24px;
  overflow: auto;
}
.stage-card {
  position: relative;
  width: 360px;
  height: 250px;
  padding: 0;
  border: 5px solid var(--cream);
  border-radius: 16px;
  overflow: hidden;
  background: #46557f;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .35);
  text-align: left;
}
.stage-card .card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
}
.stage-card .card-info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 8px 14px 10px;
  background: rgba(20, 28, 50, .82);
  color: #fff;
}
.card-no { font-size: 17px; opacity: .85; font-weight: bold; }
.card-title { font-size: 21px; font-weight: bold; line-height: 1.3; }
.card-prog { font-size: 17px; margin-top: 2px; color: #ffd98a; }
.stage-card.is-locked { border-color: #6b7386; }
.stage-card.is-locked .card-bg { filter: grayscale(1) brightness(.3); }
.stage-card.is-locked .card-prog { color: #b9bfcc; }
.stage-card .lock {
  position: absolute; inset: 0 0 60px 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 64px;
}
.badge-clear {
  position: absolute; top: 12px; right: 12px;
  background: var(--green); color: #fff; font-weight: bold;
  padding: 2px 14px; border-radius: 999px; border: 3px solid #fff;
  font-size: 20px; transform: rotate(6deg);
}
.select-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px 16px; color: #fff; font-size: 16px;
}
.select-foot .note { opacity: .75; }

/* ---------- ゲーム画面 ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 4px;
  color: #fff;
}
.hud .hud-title { flex: 1; min-width: 0; }
.hud .t1 { font-size: 18px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .t2 { font-size: 24px; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 2px 0 rgba(0,0,0,.4); }
.hud .score { font-size: 22px; font-weight: bold; white-space: nowrap; }

/* 盤面 */
.board {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 4px 16px 6px;
}
.slot-end {
  flex: 0 0 auto;
  width: 60px;
  text-align: center;
  color: #fff;
  font-size: 15px;
  font-weight: bold;
}
.area-group {
  flex: 1 1 0;
  min-width: 0;
  padding: 2px 6px 6px;
  border: 3px dashed rgba(255, 255, 255, .5);
  border-radius: 10px;
}
.area-group .area-name {
  color: #ffe9b0;
  font-size: 16px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.cells { display: flex; gap: 6px; }
.cell, .slot-cell {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 56px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 18px;
}
.cell.done { background: #ffd98a; }
.cell.current { background: #fff; box-shadow: 0 0 0 4px var(--orange); }
.slot-cell { flex: none; width: 56px; background: #cfd8ee; }
.slot-cell.goal { background: #ffe082; }
.token {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  z-index: 2;
  pointer-events: none;
}
.token img { width: 52px; height: 52px; object-fit: contain; }
.token.hop { animation: hop .6s ease-out; }

/* キャラ＋パネル */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 6px 16px;
}
.dog-col {
  flex: 0 0 auto;
  width: clamp(130px, 17vw, 200px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.dog {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  transform-origin: 50% 100%;
}
.dog img {
  width: 100%;
  max-height: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .3));
}
.dog-ph {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 100%;
  border: 4px solid var(--ink);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
  font-weight: bold;
}
.dog-ph.sensei { background: #4a4a4f; color: #fff; box-shadow: inset 0 -16px 0 var(--orange); }
.dog-ph.seito { background: #f6f3ea; color: var(--ink); }
.dog-ph .ph-emoji { font-size: 52px; }
.dog-ph .ph-label { font-size: 15px; white-space: pre-line; }
.dog.bounce { animation: bounce .6s ease-out 2; }
.dog.shake { animation: shake .5s ease-in-out 2; }
.dog.nod { animation: nod .5s ease-in-out 2; }

.panel-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
}
/* 吹き出しがスクロールできる時だけ、下端に「▼ つづきがあるよ」を重ねる */
.scroll-cue {
  display: none;
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  height: 56px;
  border-radius: 0 0 12px 12px;
  background: linear-gradient(rgba(255, 248, 231, 0), var(--cream) 70%);
  pointer-events: none;
}
.scroll-cue::after {
  content: "▼ つづきがあるよ";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: var(--orange-d);
  animation: cue-bob 1.2s ease-in-out infinite;
}
.panel-wrap.can-scroll .scroll-cue { display: block; }
.panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 18px;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.panel.sensei { border-color: var(--orange-d); }
.panel.seito { border-color: #5b7bd5; }
.name-tag {
  align-self: flex-start;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: bold;
  font-size: 18px;
  color: #fff;
  background: var(--orange-d);
}
.panel.seito .name-tag { background: #5b7bd5; }
.say { font-size: 26px; line-height: 1.6; white-space: pre-wrap; }
.q-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-meta .right { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.q-text { font-size: 27px; font-weight: bold; line-height: 1.45; white-space: pre-wrap; }
.q-text.small { font-size: 20px; opacity: .8; }
.feedback {
  border-radius: 12px;
  padding: 8px 14px;
  border: 3px solid;
}
.feedback.ok { background: var(--green-l); border-color: var(--green); }
.feedback.ng { background: var(--red-l); border-color: var(--red); }
.feedback.none { background: #eee; border-color: var(--gray); }
.feedback .fb-title { font-size: 26px; font-weight: bold; }
.feedback.ok .fb-title { color: #21803a; }
.feedback.ng .fb-title { color: #c0282d; }
.feedback .fb-body { font-size: 21px; white-space: pre-wrap; }
.tap-hint { align-self: flex-end; margin-top: auto; font-size: 16px; opacity: .6; }

/* 下部（4択・つぎへ） */
.bottom { padding: 8px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
/* 回答後の「つぎへ」: 選択肢があった画面下部に全幅で表示（高さは60px以上） */
.bottom .next { width: 100%; min-height: 72px; font-size: 28px; }
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.choice {
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px;
  text-align: left;
  border: 4px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font-size: 25px;
  font-weight: bold;
  line-height: 1.3;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35);
}
.choice:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.choice .mark {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.choice .ctext { flex: 1; min-width: 0; }
.wide-btn { width: 100%; min-height: 84px; font-size: 28px; }

/* ---------- クリア画面 ---------- */
.clear-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #fff;
  text-align: center;
  padding: 24px;
  overflow: hidden;
}
.clear-wrap h2 {
  margin: 0;
  font-size: 64px;
  color: #ffe082;
  text-shadow: 0 5px 0 rgba(0, 0, 0, .5);
  animation: pop .7s ease-out;
}
.clear-wrap .sub-t { font-size: 28px; }
.clear-wrap .dogs { display: flex; gap: 24px; align-items: flex-end; height: 200px; }
.clear-wrap .dogs .dog { width: 180px; height: 100%; }
.clear-wrap .dogs .dog img, .clear-wrap .dogs .dog-ph { max-height: 200px; }
.confetti { position: absolute; top: -40px; font-size: 32px; animation: fall linear infinite; pointer-events: none; }

.error-box {
  margin: auto;
  max-width: 720px;
  padding: 24px;
  background: var(--cream);
  border: 4px solid var(--red);
  border-radius: 16px;
  font-size: 22px;
}

/* ---------- アニメ ---------- */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-34px); }
  55% { transform: translateY(0); }
  75% { transform: translateY(-16px); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-12px) rotate(-3deg); }
  40% { transform: translateX(12px) rotate(3deg); }
  60% { transform: translateX(-8px) rotate(-2deg); }
  80% { transform: translateX(8px) rotate(2deg); }
}
@keyframes nod {
  0%, 100% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(8px) rotate(3deg); }
  70% { transform: translateY(0) rotate(-1deg); }
}
@keyframes cue-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}
@keyframes hop {
  0% { transform: translateY(0); }
  40% { transform: translateY(-26px); }
  100% { transform: translateY(0); }
}
@keyframes pop {
  0% { transform: scale(.3); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes fall {
  to { transform: translateY(115vh) rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .dog.bounce, .dog.shake, .dog.nod, .token.hop, .confetti, .scroll-cue::after { animation: none; }
}
