:root {
  --header-h: 52px;
  --ink: #2b3a55;
  --ink-soft: #7089aa;
  --line: #e3ecf7;
  --green: #22c55e;
  --green-dark: #16a34a;
  --orange: #ff9f1c;
  --orange-deep: #f97316;
  --red: #ef4444;
  --pink: #ff6b9d;
  --purple: #a855f7;
  --sky: #38bdf8;
  --yellow: #fbbf24;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  background: #f2f8ff;
  color: var(--ink);
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none; }
.hidden { display: none; }

/* ---------- 共通トップバー ---------- */
.top-bar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #eef6ff;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.icon-btn:active { background: #dceaf9; }
.icon-btn-spacer { width: 44px; flex: 0 0 auto; }
.region-title { font-size: 17px; font-weight: bold; color: var(--ink); }

/* ---------- ホーム画面 ---------- */
#screen-home {
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 159, 28, 0.18), transparent 38%),
    radial-gradient(circle at 88% 14%, rgba(168, 85, 247, 0.16), transparent 40%),
    radial-gradient(circle at 50% 100%, rgba(56, 189, 248, 0.18), transparent 45%),
    linear-gradient(180deg, #f2f8ff 0%, #ffffff 65%);
}
.home-title-wrap { flex: 1 1 auto; text-align: center; }
.home-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  /* 中身が画面より高くなったとき、justify-content:center だと上が見切れて
     スクロールでも たどりつけなくなるため、上ぞろえにする */
  justify-content: flex-start;
  gap: 16px;
  padding: 16px 20px 32px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}

.mastered-box {
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  text-align: center;
}
.mastered-label { font-size: 13px; color: var(--ink-soft); }
.mastered-count { font-size: 26px; font-weight: bold; color: var(--green-dark); margin: 2px 0 8px; }
.mastered-bar {
  height: 10px;
  background: #eef2f6;
  border-radius: 999px;
  overflow: hidden;
}
.mastered-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #fbbf24, #22c55e, #38bdf8, #a855f7);
  border-radius: 999px;
  transition: width 0.4s ease-out;
}

.voice-warning {
  background: #fff6e5;
  border: 1px solid #f5d79a;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #8a6320;
}

.start-btn {
  border: none;
  border-radius: 28px;
  padding: 24px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #ffffff;
  background: linear-gradient(135deg, #ffc95c, var(--orange-deep));
  box-shadow: 0 6px 0 #d97706, 0 10px 20px rgba(249, 115, 22, 0.3);
  animation: start-bob 2.6s ease-in-out infinite;
}
.start-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #d97706, 0 4px 10px rgba(249, 115, 22, 0.3);
  animation: none;
}
@keyframes start-bob {
  0%, 92%, 100% { transform: translateY(0) rotate(0deg); }
  95% { transform: translateY(-3px) rotate(-0.6deg); }
  98% { transform: translateY(-1px) rotate(0.6deg); }
}
.start-btn-icon { font-size: 40px; line-height: 1; }
.start-btn-title { font-size: 26px; font-weight: bold; }
.start-btn-sub { font-size: 13px; opacity: 0.95; text-align: center; }

.category-label { font-size: 13px; color: var(--ink-soft); text-align: center; }
.category-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}
.category-btn {
  border: 2px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 16px;
  padding: 10px 6px;
  min-height: 72px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.category-btn-icon { font-size: 24px; }
.category-btn:active { transform: translateY(2px); }
/* カテゴリごとに色を変えて、絵本のように にぎやかに見せる */
.category-btn:nth-child(7n+1) { background: #fff4e0; border-color: #ffd89b; }
.category-btn:nth-child(7n+2) { background: #ffe9f0; border-color: #ffbcd4; }
.category-btn:nth-child(7n+3) { background: #e8f7ff; border-color: #a8dcf5; }
.category-btn:nth-child(7n+4) { background: #eafbef; border-color: #a5e7bd; }
.category-btn:nth-child(7n+5) { background: #f3ecff; border-color: #d3bcf8; }
.category-btn:nth-child(7n+6) { background: #fffbe0; border-color: #f5e08f; }
.category-btn:nth-child(7n+7) { background: #ffeee8; border-color: #ffc0ab; }
.category-btn.active {
  border-color: var(--green);
  background: #e9fbf1;
  color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}

/* ---------- クイズ画面 ---------- */
.quiz-progress-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.quiz-progress { font-size: 16px; font-weight: bold; color: var(--ink); }
.quiz-score { font-size: 12px; color: var(--ink-soft); }

.quiz-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 18px;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}
/* ---------- こたえの画面 ---------- */
.answer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.answer-overlay.hidden { display: none; }
.answer-card {
  background: #ffffff;
  border-radius: 26px;
  padding: 22px;
  width: min(360px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  animation: pop-in 0.22s ease-out;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@keyframes pop-in {
  0% { transform: scale(0.9); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}
.answer-badge {
  font-size: 24px;
  font-weight: bold;
  border-radius: 999px;
  padding: 8px 0;
}
.answer-badge-correct { color: var(--green-dark); background: #e9fbf1; }
.answer-badge-wrong { color: #b34a3a; background: #fdeeeb; }
.answer-illust {
  width: min(48vw, 150px);
  height: min(48vw, 150px);
  object-fit: contain;
  margin: 2px auto 0;
}
.answer-en {
  font-size: 20px;
  font-weight: bold;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.answer-ja { font-size: 26px; font-weight: bold; color: var(--ink); }
.replay-btn {
  border: 2px solid var(--line);
  background: #eef6ff;
  color: var(--ink);
  border-radius: 14px;
  padding: 12px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  min-height: 48px;
}
.replay-btn:active { background: #dceaf9; }

/* ---------- 結果画面 ---------- */
.completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.completion-overlay.hidden { display: none; }
.completion-card {
  background: #ffffff;
  border-radius: 22px;
  padding: 24px;
  text-align: center;
  width: min(380px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: pop-in 0.3s ease-out;
}
.completion-title { font-size: 23px; font-weight: bold; color: var(--ink); margin-bottom: 6px; }
.completion-sub { font-size: 16px; color: var(--green-dark); font-weight: bold; margin-bottom: 14px; }
.result-list { margin-bottom: 14px; }
.result-list-heading { font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; text-align: left; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.result-item {
  border: 2px solid var(--line);
  background: #ffffff;
  border-radius: 14px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ink);
  cursor: pointer;
}
.result-item:active { background: #f2f8ff; }
.result-item img { width: 44px; height: 44px; object-fit: contain; }
.completion-buttons { display: flex; flex-direction: column; gap: 10px; }
.completion-btn {
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 17px;
  font-weight: bold;
  color: #ffffff;
  background: var(--green);
  cursor: pointer;
  min-height: 52px;
}
.completion-btn:active { background: var(--green-dark); }
.completion-btn-secondary { background: #eef6ff; color: var(--ink); }
.completion-btn-wrong { background: var(--orange); }

/* ---------- せってい画面 ---------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2100;
}
.settings-overlay.hidden { display: none; }
.settings-card {
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.settings-title { font-size: 18px; font-weight: bold; }
.settings-body { overflow-y: auto; padding: 8px 16px 28px; }
.settings-group { padding: 14px 0; border-bottom: 1px solid #f0f5fa; }
.settings-group-label { font-size: 14px; color: var(--ink-soft); margin-bottom: 8px; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-option {
  border: 2px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
}
.settings-option.active {
  border-color: var(--green);
  background: #e9fbf1;
  color: var(--green-dark);
  font-weight: bold;
}
.settings-option-danger { border-color: #f3c9c2; color: #b34a3a; }
.settings-note { font-size: 12px; color: #9aabbe; margin-top: 8px; line-height: 1.5; }

/* ---------- よこ長の画面（ノートPC・iPad横向き） ---------- */
/* ノートPCは たてが せまいので、絵とキーを小さめにして
   「絵・ことば・キーボード」が いちどに見えるようにする */
@media (orientation: landscape) and (max-height: 820px) {
  .type-illust, .type-illust-hidden { font-size: 44px; width: 84px; height: 84px; }
  .type-ja { font-size: 18px; }
  .type-body { gap: 8px; padding-top: 8px; }
}

/* ==================== プロフィール ==================== */
.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: center;
  border: 2px solid var(--line);
  background: #ffffff;
  border-radius: 999px;
  padding: 6px 8px 6px 6px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(43, 58, 85, 0.08);
}
.profile-chip:active { transform: translateY(2px); box-shadow: none; }
.profile-chip-icon { font-size: 24px; line-height: 1; }
.profile-chip-name { font-size: 15px; font-weight: bold; color: var(--ink); }
.profile-chip-switch {
  font-size: 11px;
  color: var(--ink-soft);
  background: #f1f6fc;
  border-radius: 999px;
  padding: 3px 8px;
}

.profile-title {
  font-size: 17px;
  font-weight: bold;
  text-align: center;
  margin: 8px 0 16px;
  color: var(--ink);
}
.profile-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.profile-card {
  border: 3px solid var(--line);
  background: #ffffff;
  border-radius: 20px;
  padding: 14px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--ink);
}
.profile-card:active { transform: translateY(2px); }
.profile-card.is-active {
  border-color: var(--green);
  background: #eafbef;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}
.profile-card-icon { font-size: 40px; line-height: 1.1; }
.profile-card-name { font-size: 15px; font-weight: bold; }
.profile-card-sub { font-size: 11px; color: var(--ink-soft); }

.profile-input {
  width: 100%;
  border: 3px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  font-size: 18px;
  font-family: inherit;
  color: var(--ink);
  margin-bottom: 14px;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.profile-input:focus { outline: none; border-color: var(--sky); }
.profile-icon-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.profile-icon {
  border: 3px solid var(--line);
  background: #ffffff;
  border-radius: 14px;
  font-size: 26px;
  padding: 6px 0;
  cursor: pointer;
  min-height: 48px;
}
.profile-icon.is-active {
  border-color: var(--green);
  background: #eafbef;
  transform: scale(1.06);
}
.profile-add-btn,
.profile-manage-btn {
  width: 100%;
  border: 2px dashed #c7d7ea;
  background: #ffffff;
  color: var(--ink-soft);
  border-radius: 16px;
  padding: 14px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  margin-top: 8px;
  min-height: 48px;
}
.profile-manage-btn { border-style: solid; border-color: var(--line); }
.profile-manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #f0f5fa;
}
.profile-manage-name { flex: 1 1 auto; font-size: 15px; font-weight: bold; }

/* ==================== ホームの がんばり表示 ==================== */
.home-stats {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.home-stat {
  flex: 1 1 0;
  background: #f7fbff;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.home-stat-icon { font-size: 18px; }
.home-stat-value { font-size: 20px; font-weight: bold; color: var(--ink); }
.home-stat-label { font-size: 11px; color: var(--ink-soft); }

.goal-row { margin-top: 12px; }
.goal-bar {
  height: 12px;
  background: #eef2f6;
  border-radius: 999px;
  overflow: hidden;
}
.goal-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: repeating-linear-gradient(
    45deg, var(--orange), var(--orange) 8px, #ffc95c 8px, #ffc95c 16px
  );
  transition: width 0.4s ease-out;
}
.goal-text { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }

/* ==================== 紙吹雪（正解・クリアの演出） ==================== */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3000;
}
.confetti-piece {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}


/* ==================== ホームの レベルえらび ==================== */
.level-label { font-size: 13px; color: var(--ink-soft); text-align: center; }
.level-picker { display: flex; gap: 8px; }
.level-btn {
  flex: 1 1 0;
  min-height: 48px;
  border: 2px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 14px;
  padding: 10px 4px;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
}
.level-btn:active { transform: translateY(2px); }
.level-btn.active {
  border-color: var(--green);
  background: #e9fbf1;
  color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}
.blind-line { font-size: 12px; color: var(--ink-soft); margin-top: 8px; }

/* ==================== タイピング画面 ==================== */
.type-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 12px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}
.type-prompt {
  /* キーボードを 下にとどめつつ、絵と ことばが 上に片よらないように、
     あまった たてのスペースを 上下で 半分ずつに分ける */
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.type-illust {
  width: clamp(76px, 16vh, 130px);
  height: clamp(76px, 16vh, 130px);
  object-fit: contain;
}
.type-illust.hidden { display: none; }
.type-illust-hidden {
  width: clamp(76px, 16vh, 130px);
  height: clamp(76px, 16vh, 130px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(46px, 10vh, 72px);
  opacity: 0.55;
}
.type-illust-hidden.hidden { display: none; }
.type-ja { font-size: 20px; font-weight: bold; color: var(--ink); }

.type-tools { display: flex; gap: 10px; }
.type-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border: 2px solid var(--line);
  background: #eef6ff;
  color: var(--ink);
  border-radius: 999px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
}
.type-tool-btn:active { background: #dceaf9; transform: translateY(2px); }
.type-tool-btn.hidden { display: none; }
.type-tool-btn.playing { animation: play-pulse 0.7s ease-in-out infinite; }
@keyframes play-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.5); }
  50% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
}

/* 1文字ずつの わく。打てた文字は みどり、つぎに打つ文字は 水色に光る */
.type-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.type-slot {
  width: clamp(32px, 7vw, 56px);
  height: clamp(44px, 9vh, 70px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--ink-soft);
  font-size: clamp(22px, 4.4vh, 38px);
  font-weight: bold;
  line-height: 1;
}
.type-slot:empty::after { content: "_"; color: #cdd9e8; }
.type-slot.is-done {
  border-color: var(--green);
  background: #e9fbf1;
  color: var(--green-dark);
}
.type-slot.is-next {
  border-color: var(--sky);
  color: var(--ink);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.22);
}
.type-slot.is-miss {
  border-color: var(--red);
  background: #fdeeeb;
  animation: slot-shake 0.32s ease-in-out;
}
@keyframes slot-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ==================== キーボードの絵 ==================== */
.keyboard {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
}
.keyboard.hidden { display: none; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
/* 本物のキーボードと同じように、下の段ほど 右に ずらす */
.kb-row-2 { padding-left: clamp(16px, 3.4vw, 26px); }
.kb-row-3 { padding-left: clamp(42px, 9vw, 70px); }
.kb-key {
  position: relative;
  width: clamp(28px, 6.6vw, 54px);
  height: clamp(30px, 5.6vh, 52px);
  border: 2px solid var(--line);
  border-radius: 9px;
  background: #ffffff;
  color: var(--ink-soft);
  font-size: clamp(11px, 1.6vh, 16px);
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(43, 58, 85, 0.12);
}
/* F と J の ぽっち（本物と同じ目印） */
.kb-key-home::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 10px;
  height: 2px;
  margin-left: -5px;
  background: #c3d3e5;
  border-radius: 2px;
}
.kb-key.is-next {
  background: linear-gradient(135deg, #ffc95c, var(--orange));
  border-color: var(--orange-deep);
  color: #ffffff;
  animation: key-next-pulse 1.1s ease-in-out infinite;
}
.kb-key.is-next::after { background: rgba(255, 255, 255, 0.7); }
@keyframes key-next-pulse {
  0%, 100% { box-shadow: 0 2px 0 rgba(190, 110, 25, 0.5), 0 0 0 0 rgba(255, 159, 28, 0.55); }
  50% { box-shadow: 0 2px 0 rgba(190, 110, 25, 0.5), 0 0 0 9px rgba(255, 159, 28, 0); }
}
.kb-key.is-hit {
  background: #e9fbf1;
  border-color: var(--green);
  color: var(--green-dark);
  animation: key-press 0.2s ease-out;
}
.kb-key.is-miss {
  background: #fdeeeb;
  border-color: var(--red);
  color: #b34a3a;
  animation: key-press 0.2s ease-out;
}
@keyframes key-press {
  0% { transform: translateY(2px); box-shadow: none; }
  100% { transform: translateY(0); }
}
.keyboard-note { font-size: 12px; color: var(--ink-soft); text-align: center; }
.keyboard-note.hidden { display: none; }

/* ==================== こたえの画面（つづりを主役にする） ==================== */
.answer-en {
  font-size: 34px;
  color: var(--ink);
  letter-spacing: 0.06em;
}
.answer-stats { font-size: 14px; color: var(--ink-soft); }
