/* =====================================================================
   style.css（子ども用・保護者用の共通スタイル）
   ・子ども用は「大きなボタン」「明るい色」「縦横どちらでも見やすい」
   ===================================================================== */

/* ----- 色や大きさの基本設定 ----- */
:root {
  --bg: #fff8e7;
  --card: #ffffff;
  --text: #2b2d42;
  --muted: #6c757d;
  --primary: #ff8c42;
  --primary-dark: #e86f1f;
  --secondary: #4cc9f0;
  --ok: #2a9d8f;
  --danger: #e63946;
  --radius: 20px;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ----- 全体 ----- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: var(--safe-bottom);
}
body.kid {
  /* 明るい水玉もようの背景 */
  background:
    radial-gradient(circle at 10% 20%, #ffe5b4 0 40px, transparent 41px),
    radial-gradient(circle at 90% 80%, #c8f7dc 0 60px, transparent 61px),
    radial-gradient(circle at 80% 15%, #d6ecff 0 50px, transparent 51px),
    var(--bg);
  background-attachment: fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ----- 上のバー ----- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 20px 10px;
  background: #ffb703;
  color: #3d2c00;
  box-shadow: var(--shadow);
}
.topbar-title { font-weight: 800; font-size: 1.15rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.child-chip { background: #fff; padding: 4px 14px; border-radius: 999px; font-weight: 700; }
.badge { background: var(--danger); color: #fff; padding: 4px 12px; border-radius: 999px; font-size: 0.9rem; }

/* ----- 画面 ----- */
main#app { max-width: 1100px; margin: 0 auto; padding: 20px; }
.screen { animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.big-title { font-size: clamp(2rem, 5vw, 3rem); text-align: center; margin: 16px 0 4px; }
.lead { font-size: 1.3rem; text-align: center; margin: 4px 0 20px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ----- カード ----- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card.center { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.card.narrow { max-width: 480px; margin: 40px auto; }

/* ----- ボタン ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 16px;
  padding: 12px 22px;
  min-height: 48px;
  font-weight: 700;
  font-size: 1rem;
  background: #e9ecef;
  cursor: pointer;
  touch-action: manipulation; /* ダブルタップで拡大しない */
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, filter 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.6; }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark); }
.btn.primary:active { box-shadow: 0 2px 0 var(--primary-dark); transform: translateY(3px); }
.btn.secondary { background: var(--secondary); color: #08324a; box-shadow: 0 5px 0 #2a9fc4; }
.btn.ghost { background: rgba(255, 255, 255, 0.85); border: 2px solid #ddd; }
.btn.danger { background: #ffe3e5; color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 0.9rem; border-radius: 12px; }
.btn.large { min-height: 64px; font-size: 1.3rem; padding: 14px 28px; }
.btn.huge { min-height: 88px; font-size: 1.7rem; padding: 18px 36px; border-radius: 26px; }
.btn.icon { min-width: 48px; padding: 0; }
.file-label { cursor: pointer; }

/* ----- 入力欄 ----- */
.input {
  width: 100%;
  border: 2px solid #ddd;
  border-radius: 14px;
  padding: 10px 14px;
  min-height: 52px;
  font-size: 1.2rem; /* 16px 以上にすると iPad で勝手に拡大しない */
  background: #fff;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(255, 140, 66, 0.2); }
.input.big { font-size: 1.6rem; text-align: center; max-width: 420px; }
.input.num { width: 5.2em; text-align: center; }
textarea.input { resize: vertical; }
.field { display: block; margin-bottom: 18px; }
.field-label { display: block; font-weight: 800; font-size: 1.2rem; margin-bottom: 6px; }
.time-inputs { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; flex-wrap: wrap; }

/* ----- だれ？画面 ----- */
.child-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin: 20px 0;
}
.child-btn { min-height: 120px; font-size: 2rem; border-radius: 28px; color: #fff; }
.color0 { background: #ff6b6b; box-shadow: 0 6px 0 #d64545; }
.color1 { background: #4dabf7; box-shadow: 0 6px 0 #1c7ed6; }
.color2 { background: #51cf66; box-shadow: 0 6px 0 #2f9e44; }
.color3 { background: #fcc419; box-shadow: 0 6px 0 #e67700; color: #3d2c00; }
.color4 { background: #b197fc; box-shadow: 0 6px 0 #7950f2; }
.color5 { background: #ff922b; box-shadow: 0 6px 0 #e8590c; }

/* ----- ホーム画面 ----- */
.home-buttons { display: flex; flex-direction: column; align-items: center; gap: 22px; margin: 30px 0; }
.home-buttons .huge { width: min(560px, 100%); }
.home-buttons .large { width: min(420px, 100%); }
.help summary { font-size: 1.3rem; font-weight: 800; cursor: pointer; }
.help-steps { font-size: 1.25rem; padding-left: 1.6em; }
.help-steps li { margin: 8px 0; }

/* ----- 進捗バー ----- */
.progress-wrap { max-width: 640px; margin: 30px auto; }
.progress { width: 100%; height: 34px; background: #eee; border-radius: 999px; overflow: hidden; }
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: repeating-linear-gradient(45deg, #ffb703 0 20px, #ff8c42 20px 40px);
  background-size: 56px 56px;
  animation: stripes 1s linear infinite;
  transition: width 0.3s ease;
}
@keyframes stripes { to { background-position: 56px 0; } }

/* ----- 確認画面 ----- */
.warnings { background: #fff3cd; color: #7a5b00; border-radius: 14px; padding: 12px 16px; margin-bottom: 16px; font-size: 1.05rem; }
.confirm-grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
.confirm-grid .card { margin-bottom: 0; }
.preview { display: block; max-height: 220px; max-width: 100%; margin: 0 auto 16px; border-radius: 12px; border: 2px solid #eee; }
.app-rows { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.app-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding-bottom: 12px; border-bottom: 1px dashed #ddd; }
.confirm-actions { display: flex; justify-content: space-between; gap: 16px; align-items: center; flex-wrap: wrap; }
.confirm-actions .huge { flex: 1; }

/* 横向き（画面が広い）ときは2列にする */
@media (min-width: 900px) and (orientation: landscape) {
  .confirm-grid { grid-template-columns: 1fr 1.3fr; }
  .confirm-actions { grid-column: 1 / -1; }
  .home-buttons { flex-direction: row; justify-content: center; flex-wrap: wrap; }
}
/* 狭い画面ではアプリの行を2段にする */
@media (max-width: 600px) {
  .app-row { grid-template-columns: 1fr auto; }
  .app-row .app-name { grid-column: 1 / -1; }
}

/* ----- できた！画面 ----- */
.celebrate { position: relative; text-align: center; padding: 20px 0 40px; overflow: hidden; }
.hanamaru { width: min(320px, 70vw); height: auto; display: block; margin: 10px auto; }
.hanamaru .petals circle { fill: #ffd6e0; stroke: #ff6b9a; stroke-width: 4; transform-origin: 100px 100px; }
.hanamaru .ring { fill: none; stroke: #ff3366; stroke-width: 8; stroke-linecap: round; stroke-dasharray: 440; stroke-dashoffset: 440; }
.hanamaru.play .petals { animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1) both; transform-origin: 100px 100px; }
.hanamaru.play .ring1 { animation: draw 0.6s 0.3s ease forwards; }
.hanamaru.play .ring2 { animation: draw 0.6s 0.6s ease forwards; }
.hanamaru.play .ring3 { animation: draw 0.6s 0.9s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti span {
  position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; opacity: 0.9;
  animation-name: fall; animation-timing-function: linear; animation-fill-mode: forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) {
  .hanamaru .ring { stroke-dashoffset: 0; }
  .confetti { display: none; }
  .screen { animation: none; }
}

/* ----- お知らせ ----- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: 90vw; padding: 14px 22px; border-radius: 16px;
  background: #343a40; color: #fff; font-size: 1.1rem; font-weight: 700; box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.install-hint {
  display: flex; align-items: center; gap: 14px; justify-content: space-between;
  margin: 12px auto 0; max-width: 1060px; padding: 14px 18px; border-radius: 16px;
  background: #e7f5ff; border: 2px solid #74c0fc; font-size: 1.1rem;
}
.install-hint p { margin: 0; }

/* =====================================================================
   保護者用ページ
   ===================================================================== */
body.parent { background: #f1f5f9; }
.parent-bar { background: #264653; color: #fff; }
.parent-bar .btn.ghost { color: var(--text); }
.parent-main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.parent .input { font-size: 1rem; min-height: 44px; }
.parent .btn { min-height: 44px; }
.parent h1 { font-size: 1.4rem; margin-top: 0; }
.parent h2 { font-size: 1.15rem; margin: 0 0 12px; }
#form-login { display: flex; gap: 10px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.toolbar label { display: flex; flex-direction: column; font-weight: 700; font-size: 0.9rem; gap: 4px; }
.toolbar select { min-width: 160px; }
.dash-grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: 1.6fr 1fr; } }
.dash-grid .card { margin-bottom: 0; }
.dash-grid + .card { margin-top: 20px; }
.chart-box { position: relative; height: 320px; }
.ranking { margin: 0; padding-left: 1.6em; }
.ranking li { display: grid; grid-template-columns: 1fr 1.2fr auto; gap: 8px; align-items: center; margin: 6px 0; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 12px; background: #e9ecef; border-radius: 999px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; background: #2a9d8f; }
.rank-time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid #e9ecef; text-align: left; vertical-align: top; }
.table th { background: #f8f9fa; white-space: nowrap; }
.table td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; }
.pre { white-space: pre-wrap; word-break: break-all; background: #f8f9fa; padding: 10px; border-radius: 8px; }
.test-list { list-style: none; padding: 0; }
.test-list li { padding: 6px 0; border-bottom: 1px solid #eee; }
.test-list li.fail { color: var(--danger); }
.icon-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.icon-links a { text-decoration: none; color: var(--text); }
