:root {
  --ink: #27445a;
  --muted: #617789;
  --cream: #fff9e9;
  --paper: #ffffff;
  --yellow: #ffd95a;
  --coral: #ff786f;
  --blue: #43b8e8;
  --green: #70c98a;
  --purple: #9b83df;
  --shadow: 0 10px 0 rgba(39, 68, 90, .08), 0 14px 30px rgba(39, 68, 90, .08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 217, 90, .2) 0 9%, transparent 9.5%),
    radial-gradient(circle at 90% 22%, rgba(67, 184, 232, .12) 0 8%, transparent 8.5%),
    var(--cream);
  font-family: "UD Digi Kyokasho NP-R", "UD デジタル 教科書体 N-R", "BIZ UDPGothic", "Yu Gothic", sans-serif;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

button:focus-visible, dialog:focus-visible {
  outline: 4px solid #245fdd;
  outline-offset: 3px;
}

button { touch-action: manipulation; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  color: white;
  background: var(--ink);
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 10px clamp(14px, 4vw, 54px);
  border-bottom: 1px solid rgba(39, 68, 90, .09);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 3px;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
}
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand b { display: block; color: #ee6c5f; font-size: 16px; line-height: 1.1; }
.brand small { display: block; margin-top: 3px; font-size: 13px; }
.header-actions { display: flex; gap: 8px; }
.round-button {
  min-height: 46px;
  padding: 8px 13px;
  border: 2px solid #e1e9ec;
  border-radius: 16px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
.round-button:hover { border-color: var(--blue); transform: translateY(-1px); }

main { width: min(1180px, calc(100% - 28px)); margin: 0 auto; }
.home-screen { padding: clamp(30px, 5vw, 64px) 0 70px; }
.hero {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  align-items: center;
  gap: 30px;
  margin-bottom: 38px;
  padding: clamp(22px, 5vw, 50px);
  overflow: hidden;
  border: 3px solid #fff;
  border-radius: 36px;
  background: linear-gradient(135deg, #fff 0 55%, #fff1b8 55% 100%);
  box-shadow: var(--shadow);
}
.eyebrow {
  display: inline-block;
  margin: 0 0 12px;
  padding: 7px 14px;
  border-radius: 999px;
  color: #c75549;
  background: #ffe7df;
  font-size: clamp(13px, 2vw, 16px);
}
.hero h1 { margin: 0; font-size: clamp(38px, 7vw, 72px); line-height: 1.08; letter-spacing: .02em; }
.hero h1 span { color: #e66057; }
.hero-copy { margin: 18px 0 0; color: var(--muted); font-size: clamp(16px, 2.4vw, 22px); }
.video-only-hero {
  grid-template-columns: 1fr;
  background: linear-gradient(135deg, #fff 0 68%, #fff1b8 68% 100%);
}
.mini-abacus {
  display: grid;
  gap: 15px;
  padding: 28px 18px;
  border: 10px solid #b87845;
  border-radius: 24px;
  background: repeating-linear-gradient(#f2c997 0 2px, transparent 2px 46px), #fff9e9;
  box-shadow: inset 0 0 0 3px #814d2b, 0 14px 30px rgba(80, 54, 32, .16);
  transform: rotate(2deg);
}
.mini-abacus span { color: var(--coral); font-size: clamp(18px, 3vw, 33px); letter-spacing: .12em; text-shadow: 0 3px rgba(0,0,0,.1); white-space: nowrap; }
.mini-abacus span:nth-child(2) { color: var(--blue); transform: translateX(5%); }
.mini-abacus span:nth-child(3) { color: var(--green); }

.lesson-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.lesson-card {
  position: relative;
  display: grid;
  grid-template-columns: 66px 1fr auto;
  align-items: center;
  gap: 15px;
  min-height: 152px;
  padding: 22px;
  overflow: hidden;
  border: 3px solid rgba(255,255,255,.82);
  border-radius: 28px;
  background: var(--card-bg, #fff);
  box-shadow: var(--shadow);
}
.lesson-card::after {
  content: "";
  position: absolute;
  right: -35px;
  bottom: -55px;
  width: 145px;
  height: 145px;
  border-radius: 50%;
  background: rgba(255,255,255,.28);
  pointer-events: none;
}
.lesson-number {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 20px;
  color: #fff;
  background: var(--card-accent, var(--coral));
  font-size: 31px;
  box-shadow: inset 0 -5px rgba(0,0,0,.08);
}
.lesson-card h2 { margin: 0 0 6px; font-size: clamp(20px, 2.4vw, 27px); }
.lesson-card p { margin: 0; color: var(--muted); font-size: 14px; }
.lesson-card button {
  position: relative;
  z-index: 2;
  min-height: 50px;
  padding: 10px 18px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  background: var(--card-accent, var(--coral));
  box-shadow: inset 0 -4px rgba(0,0,0,.11);
  cursor: pointer;
}
.lesson-card button:hover { filter: brightness(1.05); transform: translateY(-2px); }
.multi-card { grid-template-columns: 66px 1fr; }
.sub-lessons, .table-buttons { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sub-lessons button { padding: 9px; font-size: 14px; }
.table-buttons { grid-template-columns: repeat(9, 1fr); }
.table-buttons button { min-height: 46px; padding: 6px; font-size: 18px; }
.theme-yellow { --card-bg:#fff3bd; --card-accent:#eaa615; }
.theme-pink { --card-bg:#ffe3e1; --card-accent:#eb6f71; }
.theme-blue { --card-bg:#dff4ff; --card-accent:#2c9fcf; }
.theme-green { --card-bg:#e1f6e3; --card-accent:#4da96a; }
.theme-orange { --card-bg:#ffe7ce; --card-accent:#ee8a38; }
.theme-purple { --card-bg:#ece6ff; --card-accent:#8064ce; }
.theme-mint { --card-bg:#dff7f1; --card-accent:#35a98b; }
.theme-red { --card-bg:#ffe2e6; --card-accent:#df5967; }
.theme-sky { --card-bg:#dff6f9; --card-accent:#2aa3b3; }
.theme-rainbow { --card-bg:linear-gradient(135deg,#fff1b5,#dff5ff 48%,#f0e5ff); --card-accent:#675acb; }

.lesson-screen { padding: 24px 0 60px; }
.lesson-topbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; margin-bottom: 20px; }
.back-button, .video-button {
  min-height: 48px;
  padding: 9px 16px;
  border: 2px solid #dbe6e9;
  border-radius: 15px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
.video-button { color: #c75549; border-color: #ffd3c8; background: #fff5f2; }
.lesson-heading { display: flex; align-items: center; gap: 13px; }
.lesson-heading > span { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 18px; color: white; background: var(--coral); font-size: 25px; }
.lesson-heading h1 { margin: 0; font-size: clamp(23px, 3.6vw, 34px); }
.lesson-heading p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.activity-shell {
  padding: clamp(14px, 3vw, 28px);
  border: 3px solid #fff;
  border-radius: 30px;
  background: rgba(255,255,255,.72);
  box-shadow: var(--shadow);
}
.media-activity-shell { min-height: 420px; }
.media-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 1000px);
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 22px;
  background: #fff;
}
.main-video,
.quiz-image {
  display: block;
  width: 100%;
  height: 100%;
  max-height: min(72vh, 720px);
  object-fit: contain;
  background: #fff;
}
.main-video { background: #fff; }
.video-value {
  position: absolute;
  top: clamp(10px, 2.2vw, 22px);
  right: clamp(10px, 2.2vw, 22px);
  z-index: 4;
  display: grid;
  place-items: center;
  min-width: 1.65em;
  min-height: 1.35em;
  padding: .08em .28em;
  border: 4px solid rgba(255, 255, 255, .95);
  border-radius: .35em;
  color: #e34f43;
  background: rgba(255, 248, 205, .94);
  box-shadow: 0 6px 18px rgba(39, 68, 90, .2);
  font-size: clamp(42px, 8vw, 86px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.video-value.formula { font-size: clamp(28px, 5.6vw, 62px); }
.quiz-challenge { min-height: 90px; padding-top: 16px; }
.challenge-panel { min-height: 126px; text-align: center; }
.challenge-kicker { margin: 0; color: var(--muted); font-size: 14px; }
.big-number { margin-top: -2px; color: #e75f55; font-size: clamp(60px, 11vw, 100px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.equation { margin: 4px 0 8px; font-size: clamp(38px, 7vw, 64px); font-weight: 800; letter-spacing: .04em; }
.equation .blank { display: inline-grid; place-items: center; min-width: 1.2em; height: 1.08em; margin: 0 .08em; border: 4px solid #f0a735; border-radius: 13px; color: #e66057; background: #fff9d7; }
.answer-preview { margin: 4px auto 10px; color: #6657c5; font-size: clamp(26px, 5vw, 43px); }
.feedback { min-height: 32px; color: #d2574e; font-size: 21px; }
.feedback.correct { color: #278557; font-size: 25px; }

.abacus-wrap { position: relative; width: min(820px, 100%); margin: 0 auto; }
.abacus {
  position: relative;
  display: grid;
  grid-template-rows: repeat(10, 1fr);
  gap: clamp(2px, .6vw, 6px);
  padding: clamp(12px, 2vw, 20px);
  overflow: hidden;
  border: clamp(8px, 1.6vw, 14px) solid #b6723c;
  border-radius: 25px;
  background: #fffdf3;
  box-shadow: inset 0 0 0 3px #7f4927, 0 12px 24px rgba(65, 48, 30, .14);
}
.abacus-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  align-items: center;
  min-height: clamp(28px, 5.1vw, 47px);
}
.abacus-row::before {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  top: 50%;
  height: 3px;
  border-radius: 3px;
  background: #c69365;
  box-shadow: 0 1px #7f5a3a;
}
.bead-slot { position: relative; display: grid; place-items: center; min-width: 0; }
.bead {
  position: relative;
  z-index: 2;
  width: clamp(26px, 5.1vw, 44px);
  height: clamp(23px, 4.25vw, 37px);
  padding: 0;
  border: 2px solid rgba(85, 41, 35, .22);
  border-radius: 50%;
  background: linear-gradient(135deg, #ffaaa3 0 20%, #f2615c 55%, #d84646 100%);
  box-shadow: inset 4px 4px 4px rgba(255,255,255,.34), inset -4px -5px 5px rgba(116,32,32,.17), 0 3px 3px rgba(67,44,31,.2);
  transform: translateX(-18%);
  transition: transform .2s cubic-bezier(.2,.9,.3,1.25), filter .2s;
  cursor: pointer;
}
.bead.group-b { background: linear-gradient(135deg, #88dcf5 0 20%, #36add9 55%, #1684bd 100%); }
.bead.moved { transform: translateX(18%); filter: saturate(1.08) brightness(1.04); }
.bead:hover { filter: brightness(1.08); }
.abacus.quiz-locked .bead { cursor: default; }
.abacus.quiz-locked .bead:focus { outline: none; }

.bird-cover {
  position: absolute;
  top: 4%;
  left: 1.5%;
  z-index: 8;
  width: var(--bird-width, 66%);
  height: 10%;
  min-height: 36px;
  overflow: hidden;
  border-radius: 16px;
  background: white;
  box-shadow: 0 5px 12px rgba(39,68,90,.18);
  animation: birdArrive .55s ease-out both;
  transition: transform 1.05s ease-in, opacity .8s;
}
.bird-cover img { position: absolute; left: 0; top: -40%; width: 155%; height: 190%; object-fit: cover; object-position: left center; }
.bird-cover.fly-away { transform: translateX(120vw) rotate(-6deg); opacity: 0; }
@keyframes birdArrive { from { transform: translateX(-110%); opacity: 0; } to { transform: none; opacity: 1; } }

.answer-area { width: min(900px, 100%); margin: 20px auto 0; text-align: center; }
.answer-area > p { margin: 0 0 10px; color: var(--muted); }
.answer-buttons, .digit-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.answer-buttons button, .digit-buttons button {
  min-width: 54px;
  min-height: 52px;
  padding: 8px 14px;
  border: 2px solid #dbe6e9;
  border-radius: 16px;
  color: var(--ink);
  background: #fff;
  font-size: 21px;
  box-shadow: 0 4px 0 #dce6e8;
  cursor: pointer;
}
.answer-buttons button:hover, .digit-buttons button:hover, .digit-buttons button.selected { color: #fff; border-color: #695bc7; background: #7466d2; transform: translateY(-2px); box-shadow: 0 5px 0 #4e43a1; }
.answer-buttons button.wrong { color: #fff; border-color: #df5b55; background: #ef6b64; animation: shake .35s; }
.answer-buttons button.right { color: #fff; border-color: #2f9866; background: #43ad78; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.place-value-input { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 15px; }
.place-value-input strong { display: block; margin-bottom: 9px; }
.plus-sign { color: #e66057; font-size: 40px; }
.check-button, .new-question-button {
  display: block;
  min-width: 190px;
  min-height: 56px;
  margin: 18px auto 0;
  padding: 10px 24px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: #5d51bb;
  box-shadow: inset 0 -5px rgba(0,0,0,.12), 0 6px 0 #d8d1ff;
  font-size: 20px;
  cursor: pointer;
}

.play-controls { display: flex; justify-content: center; gap: 12px; margin: 23px auto 0; }
.play-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 125px;
  min-height: 56px;
  padding: 10px 18px;
  border: 2px solid #dce6e8;
  border-radius: 18px;
  color: var(--ink);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
}
.play-controls button span { font-size: 15px; }
.play-controls .primary-control { color: #fff; border-color: #ee7b69; background: #ee7b69; box-shadow: inset 0 -5px rgba(0,0,0,.1); }
.play-controls button:disabled { opacity: .35; cursor: default; }

.modal {
  width: min(620px, calc(100% - 28px));
  padding: 28px;
  border: 0;
  border-radius: 25px;
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(20,37,52,.28);
}
.modal::backdrop { background: rgba(28, 48, 64, .55); backdrop-filter: blur(4px); }
.modal h2 { margin: 0 44px 18px 0; font-size: 30px; }
.modal li { margin: 12px 0; line-height: 1.7; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border: 0; border-radius: 50%; color: var(--ink); background: #eef3f4; font-size: 25px; cursor: pointer; }
.keyboard-note { padding: 12px 15px; border-radius: 13px; background: #fff6d1; }
.video-modal video { width: 100%; max-height: 70vh; border-radius: 16px; background: #17242d; }

.confetti { position: fixed; inset: 0; z-index: 80; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -30px; width: 12px; height: 22px; border-radius: 3px; animation: fall 1.7s ease-in forwards; }
@keyframes fall { to { transform: translate3d(var(--drift), 110vh, 0) rotate(780deg); } }

[hidden] { display: none !important; }

@media (max-width: 820px) {
  .lesson-grid { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .mini-abacus { display: none; }
  .lesson-card { min-height: 140px; }
  .lesson-topbar { grid-template-columns: auto 1fr; }
  .video-button { grid-column: 1 / -1; justify-self: stretch; }
  .place-value-input { grid-template-columns: 1fr; }
  .plus-sign { line-height: .6; }
}

@media (max-width: 560px) {
  .site-header { min-height: 66px; padding: 8px 10px; }
  .brand-mark { width: 44px; height: 44px; border-radius: 14px; }
  .brand small { font-size: 11px; }
  .button-label { display: none; }
  .round-button { min-width: 45px; padding: 8px; }
  main { width: min(100% - 18px, 1180px); }
  .home-screen { padding-top: 18px; }
  .hero { padding: 24px 20px; border-radius: 25px; }
  .lesson-card { grid-template-columns: 54px 1fr; gap: 11px; padding: 17px; border-radius: 23px; }
  .lesson-card > button { grid-column: 1 / -1; }
  .lesson-number { width: 52px; height: 52px; border-radius: 16px; font-size: 25px; }
  .sub-lessons { grid-template-columns: 1fr; }
  .table-buttons { grid-template-columns: repeat(5, 1fr); }
  .lesson-screen { padding-top: 13px; }
  .lesson-topbar { gap: 10px; }
  .lesson-heading > span { display: none; }
  .lesson-heading h1 { font-size: 21px; }
  .lesson-heading p { font-size: 12px; }
  .back-button { padding: 8px 10px; font-size: 13px; }
  .activity-shell { padding: 12px 8px 20px; border-radius: 22px; }
  .challenge-panel { min-height: 107px; }
  .feedback { font-size: 17px; }
  .abacus { gap: 2px; padding: 9px 5px; border-width: 8px; border-radius: 18px; }
  .abacus-row { min-height: 31px; }
  .bead { width: min(8vw, 31px); height: min(6.8vw, 27px); border-width: 1px; }
  .answer-buttons button, .digit-buttons button { min-width: 48px; min-height: 48px; padding: 6px 10px; font-size: 18px; }
  .play-controls { gap: 7px; }
  .play-controls button { min-width: 0; flex: 1; min-height: 54px; padding: 8px 6px; }
  .bird-cover { min-height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}


/* Go Up Kids 100だまそろばん：動画をスマホで最大表示 */
.media-stage.video-mode {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(100%, 1180px);
  aspect-ratio: auto;
  overflow: visible;
  background: transparent;
}

.media-stage.video-mode .video-value {
  position: static;
  order: 1;
  align-self: center;
  min-width: 2.2em;
  min-height: 1.2em;
  margin: 0 auto 8px;
  padding: .04em .24em;
  border-width: 3px;
  font-size: clamp(44px, 9vw, 92px);
}

.media-stage.video-mode .video-value.formula {
  min-width: min(100%, 11em);
  padding: .08em .3em;
  font-size: clamp(30px, 6.2vw, 68px);
  white-space: nowrap;
}

.media-stage.video-mode .main-video {
  order: 2;
  width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
  border-radius: 18px;
}

.media-stage.quiz-mode {
  display: grid;
  width: min(100%, 1000px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

@media (max-width: 560px) {
  .media-activity-shell {
    padding-left: 2px;
    padding-right: 2px;
  }

  .media-stage.video-mode {
    width: calc(100vw - 18px);
    margin-left: calc(50% - 50vw + 9px);
    margin-right: calc(50% - 50vw + 9px);
  }

  .media-stage.video-mode .video-value {
    margin-bottom: 4px;
    font-size: clamp(46px, 15vw, 76px);
  }

  .media-stage.video-mode .video-value.formula {
    width: calc(100% - 12px);
    font-size: clamp(29px, 9vw, 48px);
  }

  .media-stage.video-mode .main-video {
    border-radius: 10px;
  }
}


/* v2：数字とそろばんを同じ視界に収める */
.lesson-screen.video-active {
  padding-top: 4px;
}

.lesson-screen.video-active .lesson-topbar {
  margin-bottom: 4px;
}

.lesson-screen.video-active .lesson-heading p {
  display: none;
}

.lesson-screen.video-active .media-activity-shell {
  min-height: 0;
  padding-top: 2px;
}

.media-stage.video-mode {
  gap: 0;
}

.media-stage.video-mode .video-value {
  margin: 0 auto -2px;
  min-height: 1em;
  padding: 0 .18em;
  border-width: 2px;
  line-height: 1;
}

.media-stage.video-mode .video-value.formula {
  margin-bottom: -1px;
  padding-top: 0;
  padding-bottom: 0;
}

@media (max-width: 560px) {
  .lesson-screen.video-active {
    padding-top: 0;
  }

  .lesson-screen.video-active .lesson-topbar {
    margin-bottom: 1px;
  }

  .lesson-screen.video-active .lesson-heading h1 {
    font-size: 17px;
    line-height: 1.1;
  }

  .lesson-screen.video-active .back-button {
    min-height: 38px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .lesson-screen.video-active .media-activity-shell {
    padding-top: 0;
    padding-bottom: 4px;
  }

  .media-stage.video-mode .video-value {
    margin-bottom: -3px;
    font-size: clamp(38px, 12vw, 62px);
  }

  .media-stage.video-mode .video-value.formula {
    font-size: clamp(24px, 7.3vw, 39px);
  }
}

/* Cloudflare版：動画中央を拡大し、そろばん左右の余白を最小化 */
.media-stage.video-mode {
  overflow: hidden;
}

.media-stage.video-mode .main-video {
  flex: 0 0 auto;
  align-self: center;
  width: 175%;
  max-width: none;
}

/* クイズ画像も動画と同じ比率で中央を拡大 */
.media-stage.quiz-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  background: #fff;
}

.media-stage.quiz-mode .quiz-image {
  flex: 0 0 auto;
  width: 175%;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
}

/* スマホで最初のフレームが表示できるまで暗い画面を見せない */
.main-video.mobile-clean-player.video-loading {
  visibility: hidden;
}

.main-video.mobile-clean-player {
  cursor: pointer;
}
