/* けいさん かけっこ：うんどうかいの グラウンド。こい ふちどりと したの かげで、おせる ものを はっきり みせる。 */
:root {
  --ink: #24304A;
  --ink-soft: #56627C;
  --card: #FFFFFF;
  --line: #D3DCE8;
  --mute: #EEF2F7;
  --track: #E2774C;
  --grass: #7CC85A;
  --red: #E23B47;
  --blue: #2F7FF0;
  --green: #1E9457;
  --green-soft: #DDF4E6;
  --yellow: #FFC83D;
  --cream: #FFF3C4;
  --gold: #F6C032;
  --gold-edge: #B78300;
  --silver: #C9D1DB;
  --silver-edge: #7E8A99;
  --bronze: #DA9A63;
  --bronze-edge: #92582B;
  --f-display: "Mochiy Pop One", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", sans-serif;
  --f-body: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Meiryo", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.nowrap { white-space: nowrap; }
h1, h2, h3, p { margin: 0; }

html { background: #FFF7E8; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #D6EFFF 0, #EEF8FF 300px, #FFF7E8 640px) no-repeat;
  color: var(--ink);
  font-family: var(--f-body);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.6;
  /* こども むけの ぶんは ことばの あいだに スペースを いれて いるので、そこでだけ かいぎょうする */
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen { flex: 1; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* おせる もの（ふちどり＋したの かげ） */
.iconbtn, .friend-btn, .course, .big-btn, .friend, .choice, .qcard, .res-card, .unlock-card {
  border: 3px solid var(--ink);
  background: var(--card);
  box-shadow: 0 4px 0 var(--ink);
}

.friend-btn:active, .course:active, .big-btn:active, .friend:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

/* ---- うえの バー ---- */

.topbar { display: flex; align-items: center; gap: 8px; min-height: 48px; }

.topbar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-family: var(--f-display);
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconbtn {
  width: 46px;
  height: 46px;
  flex: none;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 var(--ink);
}

.iconbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.iconbtn svg { width: 22px; height: 22px; }

/* いま あそんで いる ひとの ボタン（../shared/users.css）を おく ところ。ホームだけで だす */
.user-slot { flex: 0 1 auto; min-width: 0; display: flex; }

.who { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: .95rem; }

/* ---- ホーム ---- */

.flags { margin: -10px -4px -14px; }
.flags svg { display: block; width: 100%; height: auto; }

.hero { display: flex; align-items: center; justify-content: center; gap: 10px; }

.hero-runner {
  font-size: clamp(3.4rem, 16vw, 4.4rem);
  line-height: 1;
  animation: hop .7s ease-in-out infinite alternate;
}

.hero h1 {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: clamp(3rem, 15vw, 4.2rem);
  line-height: 1.05;
}

.hero h1 .kicker {
  display: block;
  font-size: .42em;
  letter-spacing: .12em;
  color: var(--red);
}

.lead { text-align: center; font-weight: 800; color: var(--ink-soft); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--card);
  line-height: 1.2;
}

.stat b { font-family: var(--f-display); font-weight: 400; font-size: 1.7rem; line-height: 1.15; }
.stat b small { font-size: .55em; color: var(--ink-soft); }
.stat > span { font-size: .78rem; font-weight: 800; color: var(--ink-soft); }

.friend-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--cream);
  text-align: left;
}

.friend-now { font-size: 2.4rem; line-height: 1; }
.friend-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.friend-text b { font-weight: 800; font-size: 1.05rem; }
.friend-text small { font-weight: 800; font-size: .82rem; color: var(--ink-soft); }
.chev { width: 20px; height: 20px; flex: none; }

.sec { font-family: var(--f-display); font-weight: 400; font-size: 1.2rem; margin-top: 4px; }

.courses { display: grid; gap: 12px; }

.course {
  --c: #FFB357;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border-radius: 18px;
  text-align: left;
}

.c-num {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--c);
  font-family: var(--f-display);
  font-size: 1.35rem;
  line-height: 1;
}

.c-body { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.c-body b { font-weight: 800; font-size: 1.05rem; }
.c-body small { font-weight: 800; font-size: .8rem; color: var(--ink-soft); }

.c-rec {
  flex: none;
  min-width: 4em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-weight: 800;
  font-size: .78rem;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.2;
}

.c-rec .medal { font-size: .62rem; }
.c-time { font-family: var(--f-display); font-weight: 400; font-size: .95rem; color: var(--ink); }

.parents {
  padding: 12px 14px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .6);
  font-size: .8rem;
  line-height: 1.75;
  color: var(--ink-soft);
  word-break: normal;
}

/* メダル。きん・ぎん・どうを いろで わける。 */
.medal {
  --m: var(--gold);
  --e: var(--gold-edge);
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 3em;
  height: 3em;
  border: .22em solid var(--e);
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, .75) 0 14%, transparent 15%), var(--m);
  box-shadow: 0 .15em 0 var(--e);
  color: #3A2A06;
  font-family: var(--f-body);
  font-weight: 800;
  font-size: .8rem;
  line-height: 1;
}

.medal.m2 { --m: var(--silver); --e: var(--silver-edge); color: #2D3540; }
.medal.m1 { --m: var(--bronze); --e: var(--bronze-edge); color: #3B2210; }
.medal.dim { --m: var(--mute); --e: #B7C2D3; border-style: dashed; background: var(--m); box-shadow: none; color: #7D899C; }

/* ---- コース ---- */

.course-head { --c: #FFB357; display: flex; align-items: center; gap: 14px; }
.c-num.big { width: 72px; height: 72px; font-size: 2.2rem; }
.course-head h2 { font-family: var(--f-display); font-weight: 400; font-size: 1.5rem; line-height: 1.25; }
.course-head p { font-weight: 800; font-size: .9rem; color: var(--ink-soft); }

.ex { font-weight: 800; color: var(--ink-soft); }
.ex b { margin-left: .6em; font-family: var(--f-display); font-weight: 400; font-size: 1.25rem; color: var(--ink); }

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--card);
}

.panel-title { font-weight: 800; font-size: .85rem; letter-spacing: .1em; color: var(--ink-soft); }

.goals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.goal-item { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.goal-item .medal { font-size: 1rem; }
.goal-item b { font-family: var(--f-display); font-weight: 400; font-size: 1.2rem; line-height: 1; }

.goal-item b small, .best-time small {
  margin-left: .15em;
  font-family: var(--f-body);
  font-weight: 800;
  font-size: .7em;
  color: var(--ink-soft);
}

.best-time b { font-family: var(--f-display); font-weight: 400; font-size: 2.4rem; line-height: 1; }
.best-note { font-weight: 800; font-size: .9rem; }

/* さいきんの タイム。みじかい ぼうほど はやい。 */
.hist { display: flex; align-items: flex-end; gap: 6px; height: 96px; }

.hist-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}

.hist-col i { display: block; width: 100%; max-width: 30px; border-radius: 6px 6px 2px 2px; background: #BFD6F2; }
.hist-col.best i { background: var(--green); }
.hist-col span { font-size: .68rem; font-weight: 800; color: var(--ink-soft); white-space: nowrap; }

.big-btn {
  width: 100%;
  min-height: 60px;
  padding: 12px 16px;
  border-radius: 18px;
  font-weight: 800;
  font-size: 1.1rem;
}

.big-btn.go { background: var(--red); color: #fff; font-family: var(--f-display); font-weight: 400; font-size: 1.4rem; }

.rule { text-align: center; font-weight: 800; font-size: .85rem; color: var(--ink-soft); }

/* ---- レース ---- */

.hud { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; color: var(--ink-soft); }
.hud-q b { margin-right: 2px; font-family: var(--f-display); font-weight: 400; font-size: 1.5rem; color: var(--ink); }
.hud-time { color: var(--ink); }
.hud-time b { display: inline-block; min-width: 1.3em; text-align: right; font-family: var(--f-display); font-weight: 400; font-size: 2rem; line-height: 1; }
.hud-time span { font-family: var(--f-display); font-size: 1.2rem; }
.hud-time small { margin-left: 4px; font-size: .85rem; color: var(--ink-soft); }

.track {
  position: relative;
  padding: 7px 0;
  border: 3px solid var(--ink);
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(var(--grass) 0 7px, var(--track) 7px calc(100% - 7px), var(--grass) calc(100% - 7px));
}

.lane { position: relative; height: 46px; }
.lane + .lane { border-top: 2px dashed rgba(255, 255, 255, .8); }

/* ひだりはしは レーンの なまえ。そのみぎの しろい せんが スタート */
.track::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 44px;
  width: 3px;
  background: rgba(255, 255, 255, .85);
}

.lane-tag, .lane-empty {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: .7rem;
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
}

.lane-tag { left: 0; width: 44px; text-align: center; }
.lane-empty { left: 60px; opacity: .85; }

/* --p は すすんだ もんだいの かず（0〜10） */
.runner {
  position: absolute;
  top: 3px;
  left: calc(48px + (100% - 100px) * var(--p, 0) / 10);
  z-index: 1;
  height: 40px;
  font-size: 32px;
  line-height: 40px;
  transition: left .35s cubic-bezier(.3, 1.3, .5, 1);
}

.ghost-runner { opacity: .45; transition: none; }

.bob { display: inline-block; animation: bob .36s ease-in-out infinite alternate; }
.trip .bob { animation: trip .5s ease-out; }

.goal-line {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 12px;
  width: 10px;
  background: repeating-conic-gradient(var(--ink) 0 25%, #fff 0 50%) 0 0 / 10px 10px;
}

.pips { display: flex; gap: 5px; }
.pips i { flex: 1; height: 8px; border: 2px solid var(--line); border-radius: 99px; background: var(--card); }
.pips i.now { border-color: var(--ink); }
.pips i.ok { background: var(--green); border-color: var(--green); }
.pips i.ng { background: var(--yellow); border-color: #D79F00; }

.qcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: clamp(160px, 26vh, 240px);
  padding: 16px 12px 14px;
  border-radius: 22px;
  box-shadow: 0 5px 0 var(--ink);
}

.qbody { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 84px; }
.ready { font-family: var(--f-display); font-size: 1.6rem; color: var(--ink-soft); }

.eq {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.8vw, 10px);
  font-family: var(--f-display);
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  line-height: 1;
  white-space: nowrap;
}

.eq.long { font-size: clamp(2.1rem, 9.5vw, 3rem); }
.eq .op { font-size: .78em; color: var(--ink-soft); }

.ansbox {
  display: inline-grid;
  place-items: center;
  min-width: 1.5em;
  height: 1.35em;
  padding: 0 .12em;
  border: .07em dashed var(--ink-soft);
  border-radius: .22em;
  color: var(--ink-soft);
}

/* いくつと いくつ（さくらんぼの ず） */
.bond { position: relative; width: min(210px, 58vw); aspect-ratio: 200 / 140; font-family: var(--f-display); }
.bond svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.bond path { fill: none; stroke: var(--ink-soft); stroke-width: 4; stroke-linecap: round; }

.bn {
  position: absolute;
  width: 30%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #FFF3D6;
  font-size: clamp(1.7rem, 8vw, 2.2rem);
  line-height: 1;
}

.bn.top { left: 50%; top: 22%; }
.bn.left { left: 22%; top: 76%; }
.bn.ans { left: 78%; top: 76%; border-style: dashed; border-color: var(--ink-soft); background: var(--card); color: var(--ink-soft); }
.bond-cap { font-weight: 800; font-size: .9rem; color: var(--ink-soft); }

/* こたえの はこ：あたり は みどり、まちがえた ときに みせる こたえ は あお */
.ansbox.is-ok, .bn.is-ok { border-style: solid; border-color: var(--green); background: var(--green-soft); color: var(--green); }
.ansbox.is-show, .bn.is-show { border-style: solid; border-color: var(--blue); background: #E3EEFF; color: var(--blue); }

.limit { width: 100%; height: 10px; border-radius: 99px; background: var(--mute); overflow: hidden; }
.limit i { display: block; height: 100%; background: var(--green); transform-origin: left center; }
.limit i.low { background: var(--red); }

.fb { min-height: 1.75em; text-align: center; font-weight: 800; font-size: 1.15rem; line-height: 1.5; }
.fb .yay { font-family: var(--f-display); font-weight: 400; font-size: 1.3rem; color: var(--green); }
.fb .oops { color: var(--red); }

.choices { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.choice {
  height: clamp(70px, 11.5vh, 96px);
  padding: 0;
  border-radius: 20px;
  box-shadow: 0 5px 0 var(--ink);
  font-family: var(--f-display);
  font-size: clamp(2rem, 9vw, 2.6rem);
  line-height: 1;
}

.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.choice:disabled { cursor: default; }
.choice:disabled:not(.ok):not(.ng) { opacity: .5; }
.choice.ok { background: var(--green); color: #fff; }
.choice.ng { background: var(--red); color: #fff; animation: shake .4s; }

@media (hover: hover) {
  .choice:hover:not(:disabled), .course:hover, .big-btn:not(.go):hover { background: #F3F8FF; }
}

/* ---- けっか ---- */

.res-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 16px;
  border-radius: 24px;
  box-shadow: 0 5px 0 var(--ink);
  text-align: center;
}

.res-runner { font-size: 3.4rem; line-height: 1; }
.res-runner.jump { animation: hop .5s ease-in-out infinite alternate; }
.res-kicker { font-family: var(--f-display); font-size: 1.5rem; color: var(--red); }
.res-time { line-height: 1; }
.res-time b { font-family: var(--f-display); font-weight: 400; font-size: clamp(3.6rem, 18vw, 4.6rem); }
.res-time span { font-family: var(--f-display); font-size: 1.8rem; }
.res-time small { margin-left: 4px; font-weight: 800; font-size: 1rem; color: var(--ink-soft); }
.res-sub { font-weight: 800; font-size: .92rem; color: var(--ink-soft); }
.res-medal { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.res-medal .medal { font-size: 1.1rem; }
.res-medal b { font-family: var(--f-display); font-weight: 400; font-size: 1.25rem; }
.res-msg { font-weight: 800; font-size: 1.05rem; }
.res-next { padding: 4px 14px; border-radius: 99px; background: var(--mute); font-weight: 800; font-size: .9rem; color: var(--ink-soft); }
.res-next:empty, .hint-friend:empty { display: none; }

.hint-friend {
  padding: 8px 12px;
  border: 2px dashed #E0B400;
  border-radius: 14px;
  background: var(--cream);
  text-align: center;
  font-weight: 800;
  font-size: .92rem;
}

.miss { display: flex; flex-direction: column; gap: 8px; }
.miss h3 { font-weight: 800; font-size: .85rem; letter-spacing: .1em; color: var(--ink-soft); }

.miss-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-left: 6px solid var(--yellow);
  border-radius: 12px;
  background: var(--card);
}

.miss-row b { font-family: var(--f-display); font-weight: 400; font-size: 1.15rem; }
.miss-row span { font-weight: 800; font-size: .82rem; color: var(--ink-soft); white-space: nowrap; }

.actions { display: flex; flex-direction: column; gap: 12px; margin-top: auto; }

/* ---- なかま ---- */

.friends { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.friend {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 4px 10px;
  border-radius: 18px;
}

.friend .fe { font-size: 2.6rem; line-height: 1.15; }
.friend b { font-weight: 800; font-size: .92rem; }
.friend small { min-height: 1.3em; font-weight: 800; font-size: .72rem; line-height: 1.3; color: var(--ink-soft); text-align: center; }
.friend.on { background: var(--cream); }
.friend.on small { color: var(--red); }
.friend:disabled { cursor: default; border-color: #B7C2D3; background: var(--mute); box-shadow: 0 4px 0 #B7C2D3; color: #6E7A8F; }
.friend:disabled .fe { filter: brightness(0); opacity: .22; }

/* きりかえ がめんに だす メダルの かず */
.u-medals { display: flex; gap: 14px; }
.u-medal { display: inline-flex; align-items: center; gap: 5px; }
.u-medal .medal { font-size: .6rem; }
.u-medal b { font-family: var(--f-display); font-weight: 400; font-size: 1.15rem; line-height: 1; }

/* ---- かさねて だす もの ---- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(36, 48, 74, .55);
}

.cd {
  font-family: var(--f-display);
  font-size: min(38vw, 9rem);
  line-height: 1;
  color: #fff;
  text-shadow: 0 6px 0 var(--ink);
  animation: pop .5s ease-out;
}

.cd.go { font-size: min(15vw, 4rem); color: var(--yellow); }

.unlock-card {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 18px;
  border-radius: 24px;
  box-shadow: 0 6px 0 var(--ink);
  text-align: center;
}

.ul-title { font-family: var(--f-display); font-size: 1.4rem; color: var(--red); }
.ul-emoji { font-size: 5rem; line-height: 1.1; animation: pop .6s ease-out; }
.ul-name { font-weight: 800; font-size: 1.3rem; }

#confetti { position: fixed; inset: 0; z-index: 30; overflow: hidden; pointer-events: none; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }

@keyframes bob { from { transform: translateY(3px); } to { transform: translateY(-3px) rotate(-5deg); } }
@keyframes trip { 30% { transform: rotate(-40deg) translateY(4px); } }
@keyframes hop { to { transform: translateY(-8px); } }
@keyframes pop { from { transform: scale(.3); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }
@keyframes fall { to { transform: translate(var(--x), 110vh) rotate(var(--r)); } }

@media (min-width: 520px) {
  .courses { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-runner, .bob, .trip .bob, .res-runner.jump, .cd, .ul-emoji, .choice.ng { animation: none; }
  .runner { transition: none; }
}
