/* 学びタッチ 共通の見た目（kaku.css）。外部フォント・ライブラリなし。 */
:root {
  --paper: #fffdf7;
  --card: #ffffff;
  --ink: #1f2937;
  --sub: #57534e;
  --line: #e7e0d2;
  --guide: #f2b8b5;
  --model: #d9d4cb;
  --model-strong: #44403c;
  --next: #fb923c;
  --accent: #c2410c;
  --accent-bg: #fff1e6;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --warn: #b45309;
  --warn-bg: #fff7e0;
  --red: #dc2626;
  --blue: #1d4ed8;
  --r: 18px;
  --tap: 52px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "UD デジタル 教科書体 N-R", "UD Digi Kyokasho N-R", "BIZ UDPGothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
ruby rt { font-size: 0.55em; }

/* ---- 上の帯 ---- */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right));
  border-bottom: 2px solid var(--line);
  background: var(--card);
}
.brand { color: var(--accent); font-weight: 700; text-decoration: none; font-size: 15px; white-space: nowrap; }
.top h1 { margin: 0; font-size: 21px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top h1 small { font-size: 15px; color: var(--sub); margin-left: 4px; }

/* ---- ボタン ---- */
.btn {
  min-height: var(--tap); min-width: var(--tap);
  padding: 6px 16px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--card);
  font-size: 18px; font-weight: 700; letter-spacing: .02em;
  cursor: pointer; touch-action: manipulation;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  user-select: none; -webkit-user-select: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn[disabled] { opacity: .4; cursor: default; }
.btn.main { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.go { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.small { min-height: 44px; font-size: 16px; padding: 4px 12px; }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn.pulse { animation: pulse 1.2s ease-in-out 3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(194, 65, 12, .18); } }

/* ---- 字の まとまり ---- */
.grp {
  display: block; margin: 10px 14px 0; min-height: 48px; max-width: calc(100% - 28px);
  padding: 4px 36px 4px 12px; font: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
  -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--sub) 50%), linear-gradient(135deg, var(--sub) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 14px) 21px; background-size: 6px 6px; background-repeat: no-repeat;
}

/* ---- 字の列 ---- */
.chars {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px 6px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.chip {
  flex: none; width: 60px; min-height: 66px; padding: 4px 0 6px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; touch-action: manipulation;
}
.chip b { font-size: 30px; line-height: 1.1; font-weight: 500; }
.chip .dots { display: flex; gap: 4px; margin-top: 3px; }
.chip .dots i { width: 8px; height: 8px; border-radius: 50%; background: #e7e5e4; }
.chip .dots i.on { background: var(--ok); }
.chip[aria-current="true"] { border-color: var(--accent); background: var(--accent-bg); box-shadow: 0 2px 0 var(--accent); }

/* ---- 3つの段 ---- */
.modes { display: flex; gap: 8px; padding: 4px 14px 8px; }
.mode {
  flex: 1; min-height: var(--tap);
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
  font-weight: 700; font-size: 17px; cursor: pointer; touch-action: manipulation;
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 6px;
}
.mode { white-space: nowrap; }
.mode .n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #e7e5e4; font-size: 15px; }
.mode[aria-selected="true"] { border-color: var(--accent); background: var(--accent); color: #fff; }
.mode[aria-selected="true"] .n { background: #fff; color: var(--accent); }
.mode .done { color: var(--ok); font-size: 15px; }
.mode[aria-selected="true"] .done { color: #fff; }

/* ---- ならび（たて画面が基本） ---- */
.stage {
  display: grid; gap: 10px;
  padding: 4px 14px 16px;
  grid-template-columns: 1fr;
  grid-template-areas: "model" "write" "msg" "tools";
  justify-items: center;
}
.panel-model { grid-area: model; width: 100%; display: flex; gap: 12px; align-items: center; justify-content: center; }
.panel-write { grid-area: write; display: flex; justify-content: center; width: 100%; }
.msg { grid-area: msg; }
.tools { grid-area: tools; }

.prompt { font-size: 22px; line-height: 2; text-align: center; word-break: keep-all; overflow-wrap: anywhere; }
.prompt .tg { color: var(--accent); font-weight: 700; }
.prompt .blank { display: inline-block; min-width: 1.4em; border: 2px dashed var(--accent); border-radius: 6px; line-height: 1.2; vertical-align: baseline; }
.prompt ruby rt { color: var(--sub); }
.minfo { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.kaku { font-size: 15px; color: var(--sub); }

.mbox { width: 34vw; max-width: 200px; min-width: 120px; aspect-ratio: 1; position: relative; cursor: zoom-in; touch-action: manipulation; }
.mbox:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 8px; }
.zoom-ic { position: absolute; right: -6px; bottom: -6px; width: 30px; height: 30px; color: var(--accent); z-index: 1; }
.zoom-ic svg { width: 100%; height: 100%; }
.zbox { width: min(560px, 100%) !important; text-align: center; }
.zwrap { position: relative; width: min(100%, calc(100vh - 170px)); width: min(100%, calc(100svh - 170px)); aspect-ratio: 1; margin: 0 auto; }
.zwrap svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ztools { display: flex; gap: 10px; justify-content: center; margin: 12px 0 0; }
.mbox svg, .wbox svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#wsvg { z-index: 0; }
#ink { z-index: 1; }
#over { z-index: 2; }
.wbox {
  position: relative;
  width: min(92vw, calc(100vh - 380px), 560px);
  width: min(92vw, calc(100svh - 380px), 560px);
  min-width: 260px;
  aspect-ratio: 1;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.wbox canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; border-radius: 10px; }
.wbox .over { pointer-events: none; }

/* よこ画面（Chromebook など）：字の列と段を1行に。手本・お知らせ・ボタンを左、書く所を右。左ききは入れかえ */
@media (min-aspect-ratio: 5/4) and (min-width: 700px) {
  .bar { display: flex; align-items: center; gap: 8px; padding-right: 14px; }
  .bar .grp { margin: 0 0 0 14px; flex: none; }
  .bar .chars { flex: 0 1 auto; min-width: 0; padding-bottom: 10px; }
  .bar .modes { flex: 1 0 420px; padding: 0; }
  .stage {
    grid-template-columns: minmax(300px, 1fr) auto;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "model write" "msg write" "tools write";
    align-items: start; justify-items: stretch; column-gap: 20px;
    max-width: 1280px; margin: 0 auto;
  }
  body.lefty .stage { grid-template-columns: auto minmax(300px, 1fr); grid-template-areas: "write model" "write msg" "write tools"; }
  .panel-model { justify-content: center; }
  .mbox { width: min(22vw, calc(100vh - 480px), 280px); width: min(22vw, calc(100svh - 480px), 280px); min-width: 120px; max-width: none; }
  .wbox { width: min(58vw, calc(100vh - 170px), 680px); width: min(58vw, calc(100svh - 170px), 680px); }
  .stage .msg { width: 100%; }
  .tools { justify-content: flex-start; }
  .prompt { font-size: 23px; }
}

/* ---- 書く所の下 ---- */
.msg {
  width: min(92vw, 640px); min-height: 64px;
  word-break: keep-all; overflow-wrap: anywhere;
  padding: 10px 16px; border-radius: var(--r);
  background: var(--card); border: 2px solid var(--line);
  font-size: 19px; line-height: 1.6; text-align: center;
  display: flex; flex-direction: column; justify-content: center;
}
.msg.good { background: var(--ok-bg); border-color: #86efac; }
.msg.fix { background: var(--warn-bg); border-color: #fcd34d; }
.msg b { font-size: 21px; }
.msg .sub { font-size: 16px; color: var(--sub); }
.tools { display: flex; align-content: flex-start; flex-wrap: wrap; gap: 10px; justify-content: center; }
.hidden { display: none !important; }

/* ---- SVG の見た目 ---- */
.g-frame { fill: #fff; stroke: #d6cfc2; stroke-width: 1.2; }
.g-cross { stroke: var(--guide); stroke-width: .9; stroke-dasharray: 3 3; fill: none; }
.st { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.st-model { stroke: var(--model-strong); stroke-width: 6.5; }
.st-faint { stroke: var(--model); stroke-width: 7.5; }
.st-next { stroke: var(--next); stroke-width: 7.5; animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { stroke: #fdba74; } }
.st-overlay { stroke: #f87171; stroke-width: 11; opacity: .45; }
.st-miss { stroke: #ef4444; stroke-width: 7; opacity: .7; stroke-dasharray: 1 9; }
.st-hint { stroke: var(--model); stroke-width: 7; opacity: .9; }
.num circle { fill: #fff; stroke: currentColor; stroke-width: 1.1; }
.num text { font-size: 7.4px; font-weight: 700; fill: currentColor; text-anchor: middle; dominant-baseline: central; font-family: system-ui, sans-serif; }
.num { color: var(--accent); }
.num.user { color: var(--blue); }
.num.bad { color: var(--red); }
.start-dot { fill: var(--next); stroke: #fff; stroke-width: 1.4; }
.hanamaru { fill: none; stroke: #e11d48; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }

/* ---- 設定 ---- */
.sheet { position: fixed; inset: 0; background: rgba(28, 25, 23, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.sheet .box { background: var(--card); border-radius: 20px; padding: 18px 20px; width: min(440px, 100%); box-shadow: 0 10px 30px rgba(0, 0, 0, .2); }
.sheet h2 { margin: 0 0 10px; font-size: 20px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 18px; }
.opt:last-of-type { border-bottom: 0; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { min-height: 44px; min-width: 64px; border: 0; background: var(--card); font-weight: 700; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---- おとな向け ---- */
.adult { max-width: 860px; margin: 8px auto 0; padding: 0 14px 24px; font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif; font-size: 16px; line-height: 1.8; color: #292524; }
.adult details { background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 4px 16px; }
.adult summary { cursor: pointer; font-weight: 700; min-height: 48px; display: flex; align-items: center; }
.adult h3 { font-size: 16px; margin: 14px 0 4px; }
.adult p, .adult li { margin: 4px 0; }
.adult code { background: #f5f5f4; padding: 1px 5px; border-radius: 5px; word-break: break-all; }
.credit { font-size: 13px; color: var(--sub); text-align: center; padding: 8px 14px 24px; font-family: system-ui, sans-serif; }
.credit a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  .st-next, .btn.pulse { animation: none; }
}

/* ---- せまい たて画面（スマホ） ---- */
@media (max-width: 600px) and (max-aspect-ratio: 5/4) {
  body { font-size: 17px; }
  .top { padding-top: 6px; padding-bottom: 6px; }
  .top h1 { font-size: 18px; }
  .top h1 small { font-size: 13px; }
  #b-set .lbl { display: none; }
  .chars { padding: 8px 12px 4px; gap: 6px; }
  .bar { display: flex; flex-wrap: wrap; align-items: center; }
  .bar .grp { margin: 8px 0 0 12px; min-height: 44px; font-size: 15px; max-width: 34vw; flex: none; padding-right: 28px; background-position: calc(100% - 16px) 19px, calc(100% - 10px) 19px; }
  .bar .chars { flex: 1 1 0; min-width: 0; }
  .bar .modes { flex: 1 0 100%; }
  .chip { width: 48px; min-height: 50px; padding: 2px 0 4px; }
  .chip b { font-size: 24px; }
  .chip .dots i { width: 6px; height: 6px; }
  .modes { padding: 2px 12px 4px; gap: 6px; }
  .mode { font-size: 15px; min-height: 46px; padding: 2px 4px; }
  .mode .n { display: none; }
  .stage { grid-template-areas: "model" "msg" "write" "tools"; gap: 8px; padding: 2px 12px 0; }
  .panel-model { gap: 10px; }
  .prompt { font-size: 19px; line-height: 1.9; }
  .mbox { width: 24vw; min-width: 88px; max-width: 130px; }
  #b-anim { min-height: 40px; font-size: 14px; padding: 2px 10px; }
  .panel-model .minfo { gap: 4px; }
  .kaku { font-size: 14px; }
  body.mode-nazoru .panel-model .minfo:last-child { display: none; }
  .msg { min-height: 48px; padding: 5px 12px; font-size: 17px; }
  .msg b { font-size: 18px; }
  .tools { gap: 6px; flex-wrap: nowrap; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .wbox { width: min(92vw, calc(100vh - 410px)); width: min(92vw, calc(100svh - 410px)); min-width: 240px; }
  body.mode-nazoru .wbox { width: min(92vw, calc(100vh - 380px)); width: min(92vw, calc(100svh - 380px)); }
  .tools .btn { min-height: 48px; padding: 4px 8px; font-size: 15px; flex: 0 1 auto; min-width: 0; gap: 3px; }
  .tools .btn svg { width: 18px; height: 18px; }
}

/* たて画面で 手本が 出ている段（なぞる・みて かく）は、手本の高さぶん 書く所を 小さくして ボタンまで 1画面に入れる */
@media (max-aspect-ratio: 5/4), (max-width: 699px) { /* 古い Safari は「not (…)」を読まないので この書き方 */
  body.mode-nazoru .wbox, body.mode-mite .wbox { width: min(92vw, calc(100vh - 700px), 560px); width: min(92vw, calc(100svh - 700px), 560px); }
}
@media (max-width: 600px) and (orientation: portrait) {
  body.mode-mite .wbox { width: min(92vw, calc(100vh - 455px)); width: min(92vw, calc(100svh - 455px)); min-width: 200px; }
  body.mode-nazoru .wbox { width: min(92vw, calc(100vh - 380px)); width: min(92vw, calc(100svh - 380px)); }
}
@media (max-width: 600px) and (orientation: portrait) and (max-height: 760px) {
  body.mode-mite #b-anim { display: none; } /* 手本を さわると 大きく なり、そこで かきじゅんも 見られる */
}
