/* 色は役割ごと（docs/見た目の意図.md）。明るい・暗いの両方で字と地の差を測ってある。 */
:root {
  --paper: #FBF7F0;      /* 紙 */
  --surface: #FFFFFF;    /* マス */
  --text: #24211C;       /* 字 */
  --muted: #5E584E;      /* 小さな字 */
  --grid: #D8CFBF;       /* 十字の点線 */
  --guide: #D6CFC2;      /* お手本（うすい） */
  --ink: #1F2A44;        /* 指の線 */
  --done: #2C6E63;       /* 書けた画・進むボタン */
  --on-done: #FFFFFF;
  --hint: #C27C0E;       /* ずれたときの案内 */
  --chip: #EFE8DC;       /* 小さな札の地 */
  --target: #E4D9C6;     /* 単語の中で練習している文字の地 */
  --soft: color-mix(in srgb, var(--done) 12%, var(--surface)); /* もう一度ボタンの地 */
  --pic: #F4EEE3;        /* 絵の台 */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1B1A17;
    --surface: #24221E;
    --text: #F1ECE2;
    --muted: #B9B1A3;
    --grid: #4A453D;
    --guide: #4F4A42;
    --ink: #E9E4D8;
    --done: #6CC2B1;
    --on-done: #10211D;
    --hint: #F0B04A;
    --chip: #2E2B26;
    --target: #443E35;
    --soft: color-mix(in srgb, var(--done) 16%, var(--surface));
    --pic: #3A362F;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
body { overflow-y: auto; scrollbar-width: none; }
body::-webkit-scrollbar { display: none; }

.app {
  --box: min(90vw, 560px, max(260px, calc(100dvh - 300px)));
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--box);
  grid-template-areas: "header" "word" "steps" "stage" "actions" "credit";
  justify-content: center;
  align-content: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.header { grid-area: header; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
/* 音のオンオフ：戻るボタンと同じ高さ40px・同じ「うすい地＋緑」。オフのときは灰色の札と同じ見た目 */
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--done);
  background: var(--soft); color: var(--done); display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[aria-pressed="false"] { border-color: transparent; background: var(--chip); color: var(--muted); }
.icon-btn:focus-visible, .letters:focus-visible { outline: 3px solid var(--hint); outline-offset: 2px; }
.title { margin: 0; font-size: 22px; font-weight: 700; }

/* 戻るボタン：もう一度ボタンと同じ「うすい地＋緑の字」。札より一回り大きく、指で押しやすく */
.back {
  height: 40px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--done);
  background: var(--soft); color: var(--done); font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}

/* 練習する文字の並び：今の文字に緑の下線、終えた文字は緑の字 */
.word { grid-area: word; display: flex; align-items: center; gap: 14px; }
.pic { width: 72px; height: 72px; border-radius: 18px; background: var(--pic); display: grid; place-items: center; flex: 0 0 auto; }
.pic svg { width: 62px; height: 62px; }
.letters {
  display: flex; align-items: center; gap: 6px; font-size: 30px; font-weight: 700; line-height: 1.2;
  font-family: inherit; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer;
}
/* 押すと聞ける印：再生の三角（音のオンオフのスピーカーとは別の形） */
.play-mark { width: 26px; height: 26px; border-radius: 50%; background: var(--soft); color: var(--done); display: grid; place-items: center; margin-left: 4px; }
.play-mark svg { width: 14px; height: 14px; }
.letter { padding: 0 2px; border-bottom: 3px solid transparent; }
.letter.now { border-bottom-color: var(--done); }
.letter.is-done { color: var(--done); }
.letter.target { background: var(--target); border-radius: 8px; } /* 単語の中で練習している文字 */
.sub { font-size: 17px; color: var(--muted); margin-top: 2px; }

/* 小さな札（段階の表示と Easy/Normal）：高さ32px・文字14px でそろえる */
.chips { display: flex; gap: 6px; }
.chip {
  height: 40px; padding: 0 14px; border-radius: 20px;
  display: inline-flex; align-items: center;
  font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1;
  background: var(--chip); color: var(--muted); border: 1.5px solid transparent;
}
button.chip { cursor: pointer; }
.chip[aria-current="step"], .chip[aria-pressed="true"] { color: var(--done); border-color: var(--done); background: var(--soft); }
.steps { grid-area: steps; display: flex; justify-content: center; gap: 18px; list-style: none; margin: 0; padding: 0; }
/* 段階の表示は押せないので、札の形にせず「番号＋文字」にする */
.step { display: inline-flex; align-items: center; gap: 6px; height: 32px; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.step .num { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; background: var(--chip); color: var(--muted); }
.step[aria-current="step"] { color: var(--done); border-bottom-color: var(--done); }
.step[aria-current="step"] .num, .step.is-done .num { background: var(--done); color: var(--on-done); }

.stage { grid-area: stage; position: relative; }
.box {
  display: block; width: var(--box); height: var(--box);
  background: var(--surface); border-radius: 20px;
  box-shadow: 0 1px 0 var(--grid), 0 0 0 1.5px var(--grid) inset;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.grid-line { stroke: var(--grid); stroke-width: 0.6; stroke-dasharray: 2 2.5; }
.stroke { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tpl .stroke { stroke: var(--guide); stroke-width: 7; }
.watch .stroke { stroke: var(--ink); stroke-width: 7; }
.done .stroke { stroke: var(--done); stroke-width: 7; }
.ink { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.hint .stroke { stroke: var(--hint); stroke-width: 7; opacity: 0.45; }
.hint .arrow { fill: var(--hint); }
.hint .runner { fill: var(--hint); }
.start-dot { fill: var(--done); }
.done-group { transform-box: fill-box; transform-origin: center; }

.message { flex: 0 0 100%; margin: 0 0 2px; text-align: center; font-size: 24px; font-weight: 800; color: var(--done); }
.message:empty { display: none; }

/* ボタン：高さ48px・文字17px・角丸12px でそろえる。進む＝塗り、もう一度＝うすい地 */
.actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 48px; }
.btn {
  height: 48px; padding: 0 20px; border-radius: 12px; border: 1.5px solid var(--done);
  font-family: inherit; font-size: 17px; font-weight: 700; line-height: 1; cursor: pointer; flex: 1 1 0; max-width: 240px;
}
.btn.primary { background: var(--done); color: var(--on-done); }
.btn.secondary { background: var(--soft); color: var(--done); }
.btn:focus-visible, .chip:focus-visible { outline: 3px solid var(--hint); outline-offset: 2px; }

.credit { grid-area: credit; margin: 4px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; }

/* 横向きのスマホ：マスを左、ほかを右に */
@media (orientation: landscape) and (max-height: 600px) {
  .app {
    --box: min(calc(100dvh - 32px), 55vw);
    grid-template-columns: var(--box) minmax(220px, 320px);
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas: "stage header" "stage word" "stage steps" "stage actions" "stage credit";
    align-content: center; column-gap: 24px;
  }
  .steps { justify-content: flex-start; }
  .actions { flex-direction: column; flex-wrap: nowrap; justify-content: center; }
  .message { flex: 0 0 auto; text-align: left; }
  .btn { flex: 0 0 auto; max-width: none; }
  .credit { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---- 表の画面 ---- */
.chart {
  max-width: 560px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: grid; gap: 12px;
}
.chart-head { display: flex; align-items: baseline; justify-content: space-between; }
.chart-count { margin: 0; font-size: 15px; color: var(--muted); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 12px; }
.section-title { margin: 0; font-size: 18px; font-weight: 700; }
.section-count { font-size: 14px; color: var(--muted); }
.kana-grid { display: grid; gap: 6px; }
.kana-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.kana-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cell {
  position: relative; min-height: 60px; border-radius: 12px; text-decoration: none; color: var(--text);
  background: var(--surface); box-shadow: 0 0 0 1.5px var(--grid) inset;
  display: grid; place-content: center; justify-items: center; gap: 2px; padding: 6px 0;
}
.cell.empty { background: transparent; box-shadow: none; }
.cell-kana { font-size: 26px; font-weight: 700; line-height: 1.1; }
.cell-romaji { font-size: 12px; color: var(--muted); }
.cell.is-done, .word-row.is-done { background: var(--soft); }
.cell.is-done::after, .word-row.is-done::after {
  content: ""; position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--done);
}
.cell:focus-visible, .word-row:focus-visible { outline: 3px solid var(--hint); outline-offset: 2px; }
.word-list { display: grid; gap: 8px; }
.word-row {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 12px;
  border-radius: 14px; text-decoration: none; color: var(--text);
  background: var(--surface); box-shadow: 0 0 0 1.5px var(--grid) inset;
}
.pic.small { width: 44px; height: 44px; border-radius: 12px; }
.pic.small svg { width: 40px; height: 40px; }
.word-kana { font-size: 20px; }
.word-texts { display: grid; gap: 1px; min-width: 0; }
.word-line { display: flex; align-items: baseline; flex-wrap: wrap; }
.word-kana { line-height: 1.2; }
.word-romaji { font-size: 15px; color: var(--text); }
.word-meaning { font-size: 14px; color: var(--muted); line-height: 1.2; }
.reset { margin-top: 16px; justify-self: center; width: 100%; max-width: 280px; flex: none; }
.chart .credit { grid-area: auto; }   /* 練習の画面の配置名を表に持ちこまない */
.steps[hidden] { display: none; }      /* 言葉（なぞるだけ）では段階を出さない */
/* 鍵の文字・言葉（購入前）。字は読めるまま、地を変えて右上に小さな鍵 */
.cell.is-locked, .word-row.is-locked { background: var(--chip); }
.cell.is-locked::after, .word-row.is-locked::after {
  content: ""; position: absolute; top: 6px; right: 6px; width: 11px; height: 13px; background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 11 13'%3E%3Cpath d='M2.5 6V4a3 3 0 0 1 6 0v2' fill='none' stroke='%23000' stroke-width='1.6'/%3E%3Crect x='0.5' y='5.5' width='10' height='7.5' rx='1.6'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 11 13'%3E%3Cpath d='M2.5 6V4a3 3 0 0 1 6 0v2' fill='none' stroke='%23000' stroke-width='1.6'/%3E%3Crect x='0.5' y='5.5' width='10' height='7.5' rx='1.6'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---- 表の見出しの右（終えた数と設定） ---- */
.chart-head { align-items: center; }
.chart-head-right { display: flex; align-items: center; gap: 10px; }
a.icon-btn { text-decoration: none; }

/* ---- 鍵の画面・設定（表と同じ幅・同じ余白） ---- */
.page {
  max-width: 560px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: grid; gap: 14px; align-content: start;
}
.page-head { display: flex; }
.page-title { margin: 8px 0 0; font-size: 24px; font-weight: 800; line-height: 1.25; }
.page-text { margin: 0; font-size: 17px; line-height: 1.5; color: var(--text); }
.page .btn { flex: none; width: 100%; max-width: none; }
.link-btn { display: flex; align-items: center; justify-content: center; text-decoration: none; box-sizing: border-box; }
/* 購入コードの欄：ボタンと同じ高さ48px・角丸12px。地は白で、文字は大きめ */
.code-form { display: grid; gap: 8px; margin-top: 10px; padding-top: 18px; border-top: 1.5px solid var(--grid); }
.field-label { font-size: 15px; font-weight: 700; }
.code-input {
  height: 48px; box-sizing: border-box; width: 100%; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid var(--grid); background: var(--surface); color: var(--text);
  font: 600 17px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.02em;
}
.code-input:focus { outline: 3px solid var(--hint); outline-offset: 1px; border-color: var(--done); }
.field-hint { margin: 0; font-size: 14px; line-height: 1.45; color: var(--muted); }
.ios-hint { color: var(--text); }
.code-form .btn { margin-top: 6px; }
.btn:disabled { opacity: 1; background: var(--chip); border-color: var(--chip); color: var(--muted); cursor: default; }
.status { margin: 0; font-size: 15px; line-height: 1.45; color: var(--muted); }
.status:empty { display: none; }
.status.ok { font-size: 17px; font-weight: 700; color: var(--done); }
.status.note { color: var(--text); }  /* うまくいかないとき：赤にしない */

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1.5px solid var(--grid); }
.setting-label { margin: 0; font-size: 16px; font-weight: 700; }
.setting-controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.setting-value { font-size: 15px; color: var(--muted); }
.link-chip { text-decoration: none; color: var(--done); border-color: var(--done); background: var(--soft); }
.settings .reset { margin-top: 8px; }
.credits { display: grid; gap: 4px; margin-top: 8px; }
.credits .credit { grid-area: auto; text-align: left; margin: 0; }

/* ---- 保護者の確かめ（買うボタンの前） ---- */
.gate { display: grid; gap: 10px; padding: 16px; border-radius: 14px; background: var(--surface); box-shadow: 0 0 0 1.5px var(--grid) inset; }
.gate[hidden] { display: none; }
.gate-title { margin: 0; font-size: 18px; font-weight: 800; }
.gate .page-text { font-size: 15px; }
.gate-question { margin: 4px 0 0; font-size: 28px; font-weight: 800; text-align: center; }
.gate-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.page .gate-choices .btn { width: auto; }
.small-link { justify-self: center; font-size: 14px; color: var(--done); text-underline-offset: 3px; padding: 8px 4px; }
.credits .small-link { justify-self: start; padding-left: 0; }

/* ---- プライバシーと販売者の表記 ---- */
.legal-section { display: grid; gap: 6px; }
.legal-heading { margin: 8px 0 0; font-size: 17px; font-weight: 700; }
.legal-text { margin: 0; font-size: 15px; line-height: 1.55; color: var(--text); }
