/* おうちでプログラミング体験
   色は教室のホームページ（02_トップ共通CSS.css の --lg-*）に合わせている。
   字は 入退室メール と同じ同梱フォント（SIL Open Font License 1.1）。 */
@font-face {
  font-family: "Zen Kaku Gothic New";
  src: url("../fonts/ZenKakuGothicNew-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans JP";
  src: url("../fonts/NotoSansJP-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --main: #59b04f;
  --main-dark: #3f8f37;
  --text: #333;
  --teal: #15a195;
  --lime: #bed84f;
  --yellow: #f6ee69;
  --gray: #f7f7f7;
  --btn-red: #f74a4a;
  --line: #e6e6e6;
  --focus: #ffb400;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--gray);
  color: var(--text);
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", Meiryo, sans-serif;
  font-weight: 700;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
p { margin: 0; }

/* ---------- 全体の枠（1画面に収める。スクロールさせない） ---------- */
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px 16px;
}
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: clamp(17px, 2.2vw, 24px); color: var(--main-dark); }
.brand { font-size: 12px; color: #666; }

/* ---------- 先生 ---------- */
.teacher {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "avatar mission actions" "avatar bubble bubble";
  gap: 6px 14px;
  align-items: center;
  background: #fff;
  border: 2px solid var(--line);
  border-top: 5px solid var(--main);
  border-radius: 14px;
  padding: 10px 14px;
}
.avatar {
  grid-area: avatar;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--teal); color: #fff;
  display: grid; place-items: center; font-size: 14px;
}
.mission-box { grid-area: mission; min-width: 0; }
.mission {
  display: inline-block; font-size: 12px; color: #fff; background: var(--main);
  border-radius: 999px; padding: 0 10px; margin-bottom: 2px;
}
/* 分かち書きの文は、ことばの途中で折り返さない */
.mission-text, .bubble, .steps, .rotate-tip, .card > p:not(.parent):not(.fine) { word-break: keep-all; overflow-wrap: anywhere; }
.mission-text { font-size: clamp(15px, 2vw, 20px); line-height: 1.35; }
.bubble {
  grid-area: bubble;
  background: #fdf9ee; border-radius: 10px; padding: 8px 12px;
  font-size: clamp(14px, 1.6vw, 16px); min-height: 40px;
}
.actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.ui {
  font: inherit; font-size: 15px; line-height: 1.3;
  display: inline-block; text-align: center; text-decoration: none;
  border: 2px solid var(--text); border-radius: 999px;
  background: #fff; color: var(--text);
  padding: 8px 18px; min-height: 40px; cursor: pointer;
  touch-action: manipulation;
}
.ui.primary { background: var(--main); border-color: var(--main); color: #fff; }
.ui.reserve { background: var(--btn-red); border-color: var(--btn-red); color: #fff; }
.ui.big { font-size: 18px; padding: 12px 32px; }
.ui:focus-visible, .cv-btn:focus-visible, #chara:focus-visible, .block:focus-visible {
  outline: 4px solid var(--focus); outline-offset: 2px;
}
@media (hover: hover) {
  .ui:hover { filter: brightness(1.06); }
}

/* ---------- ステージ（1720×927 の座標をそのまま縮めて表示） ---------- */
#stage-wrap { flex: 1 1 0; min-height: 0; display: grid; place-items: start center; }
#frame {
  position: relative; overflow: hidden;
  border-radius: 12px; border: 2px solid var(--line);
  background: #fde6a8;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#canvas { position: absolute; left: 0; top: 0; width: 1720px; height: 927px; transform-origin: 0 0; }
#canvas img { -webkit-user-drag: none; user-drag: none; }
#bg { position: absolute; inset: 0; width: 1720px; height: 927px; }
#chara {
  position: absolute; width: 253px; height: 331px; padding: 0; border: 0; background: none;
  transform-origin: 50% 100%; cursor: pointer; touch-action: manipulation;
  transition: left .45s ease-in-out, top .45s ease-in-out, transform .4s ease-in-out, opacity .35s;
}
#chara img {
  width: 253px; height: 331px; display: block; transform-origin: 50% 100%;
  animation: chara-breathe 2.6s ease-in-out infinite;
}
#chara.is-waiting img { animation: chara-call 1.1s ease-in-out infinite; }   /* タッチを待っているとき */
#chara.is-running img { animation: none; }
@keyframes chara-breathe {
  50% { transform: translateY(-5px) scale(1.012, .988); }
}
@keyframes chara-call {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-12px) rotate(-2deg); }
  75% { transform: translateY(-12px) rotate(2deg); }
}
.cv-btn { position: absolute; padding: 0; border: 0; background: none; cursor: pointer; z-index: 30; touch-action: manipulation; }
#picker { left: 16px; top: 16px; width: 157px; height: 159px; }
#play { right: 18px; bottom: 6px; width: 174px; height: 174px; }
#play.is-ready img { animation: play-pulse 1.4s ease-in-out infinite; }
@keyframes play-pulse { 50% { transform: scale(1.08); } }
#stop {
  right: 30px; bottom: 20px; width: 150px; height: 150px; border-radius: 50%;
  background: var(--btn-red); color: #fff; font-family: inherit; font-weight: 700; font-size: 34px;
  box-shadow: 0 6px 14px rgba(0,0,0,.25);
}
#banner {
  position: absolute; left: 50%; top: 22px; transform: translateX(-50%);
  background: #fff; border: 4px solid var(--main); border-radius: 999px;
  padding: 10px 40px; font-size: 40px; white-space: nowrap; z-index: 25;
}

/* ---------- 編集画面 ---------- */
#editor { position: absolute; inset: 0; z-index: 20; touch-action: none; }
#palette {
  position: absolute; left: 0; top: 0; width: 620px; height: 927px;
  background: linear-gradient(90deg, #f1f1ee 190px, #fff 190px); border-right: 3px solid var(--line);
}
#work { position: absolute; left: 620px; top: 0; right: 0; bottom: 0; background: rgba(0,0,0,.52); }
#work-title { position: absolute; left: 110px; top: 16px; color: #fff; font-size: 44px; opacity: .85; }
#close {
  left: 630px; top: 12px; width: 72px; height: 72px; border-radius: 10px;
  background: #ff5d73; color: #fff; font: 700 48px/1 sans-serif; z-index: 31;
}
#clear {
  right: 24px; top: 20px; height: 60px; padding: 0 28px; border-radius: 999px;
  background: #fff; color: var(--text); font-family: inherit; font-weight: 700; font-size: 28px; z-index: 31;
}
.block { position: absolute; padding: 0; border: 0; background: none; cursor: grab; touch-action: none; }
.block img { display: block; pointer-events: none; }
.block.dragging { cursor: grabbing; z-index: 40; filter: drop-shadow(0 8px 6px rgba(0,0,0,.3)); }

/* ---------- 重ねて出す画面（はじめ・クリア） ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(40, 60, 40, .55); overflow: auto;
}
#start { position: fixed; background: linear-gradient(180deg, #f3faf1, var(--gray)); }
.card {
  width: min(520px, 100%); background: #fff; border-radius: 18px;
  border-top: 8px solid var(--main);
  padding: 22px 22px 20px; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  display: grid; gap: 12px; justify-items: center;
}
.card h1, .card h2 { margin: 0; font-size: clamp(20px, 4.4vw, 26px); line-height: 1.35; color: var(--text); }
.card h1 span { color: var(--main-dark); }
.card .hero { width: 96px; height: auto; animation: chara-breathe 2.6s ease-in-out infinite; transform-origin: 50% 100%; }
.steps {
  margin: 0; padding: 12px 16px 12px 40px; text-align: left; font-size: 16px;
  background: #f3faf1; border-radius: 12px; width: 100%;
}
.steps li + li { margin-top: 4px; }
.rotate-tip { background: var(--yellow); border-radius: 10px; padding: 8px 14px; font-size: 15px; }
.fine, .parent { font-family: "Noto Sans JP", sans-serif; font-weight: 400; font-size: 13px; color: #555; }
.parent { background: var(--gray); border-radius: 10px; padding: 8px 12px; text-align: left; }
#goal .card { animation: pop-in .35s ease-out; }
@keyframes pop-in { from { transform: scale(.9); opacity: 0; } }

/* ---------- 高さが低い画面（スマホの横向きなど）: 先生を1行にまとめる ---------- */
html.compact #app { flex-direction: row; gap: 6px; padding: 6px 8px; max-width: none; }
html.compact .top { display: none; }
html.compact .teacher {
  flex: none; width: 132px;
  display: flex; flex-direction: column; align-items: stretch;
  padding: 6px 7px; gap: 5px; border-top-width: 3px; border-radius: 10px; overflow: hidden;
}
html.compact .avatar { display: none; }
html.compact .mission { font-size: 10px; margin: 0; }
html.compact .mission-text { font-size: 12.5px; line-height: 1.3; }
html.compact .bubble { flex: 1 1 0; min-height: 0; overflow: auto; font-size: 12px; line-height: 1.4; padding: 5px 7px; }
html.compact .actions { flex-direction: column; flex-wrap: nowrap; gap: 4px; }
html.compact .ui { font-size: 12px; padding: 5px 6px; min-height: 34px; }
html.compact #stage-wrap { place-items: center; }
html.compact .card { padding: 12px 16px; gap: 6px; border-top-width: 5px; }
html.compact .card h1, html.compact .card h2 { font-size: 18px; }
html.compact:not(.rot) #start .hero, html.compact:not(.rot) #start .fine { display: none; }
html.compact:not(.rot) #start .steps { font-size: 14px; padding: 8px 12px 8px 34px; }
html.compact .card .ui.big { font-size: 15px; padding: 8px 22px; }

/* ---------- スマホの縦持ち: 画面ごと横向きに回す（本体を横にすると読める） ---------- */
html.rot #app {
  position: fixed; left: 0; top: 0; margin: 0; max-width: none;
  width: 100vh; width: 100dvh;
  height: 100vw;
  transform-origin: 0 0;
  transform: translateX(100vw) rotate(90deg);
  touch-action: none;
}

/* ---------- 幅がせまい画面で先生の欄を縦に積む（タブレット縦など） ---------- */
@media (max-width: 700px) {
  html:not(.compact) .teacher {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "avatar mission" "bubble bubble" "actions actions";
  }
}

/* ---------- 動きを減らす設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  #chara { transition: opacity .01s; }
  #chara img, #chara.is-waiting img, #play.is-ready img, .card .hero, #goal .card { animation: none; }
}
