:root {
  --bg: #fffaf2;
  --surface: #ffffff;
  --text: #2d2a26;
  --muted: #6f6a63;
  --accent: #ff8a3d;
  --accent-ink: #ffffff;
  --ok: #2fa36b;
  --ng: #d9534f;
  --border: #eadfce;
  --radius: 16px;

  /* Play screen sizes. Phones / tablets override these in the media queries
     at the end of the play section, so the rules below never hard-code px. */
  --choice: 120px;        /* answer button */
  --choice-font: 3.4rem;
  --choice-sm: 72px;      /* answer button next to a row head (coding) */
  --cell: 96px;           /* matrix / symbol cell */
  --cell-font: 2.6rem;
  --picture: 200px;
  --picture-font: 8rem;
  --board-cell: 100px;    /* block design 2x2 */
  --board-cell-3: 80px;   /* block design 3x3 */
  --model-block: 72px;
  --model-block-3: 56px;
  --piece: 80px;          /* object assembly piece (one quarter of the picture) */
  --star: 2.4rem;         /* result screen star row / correct-answer burst */
  --logo-h: 48px;         /* header logo (img/logo.png is 3x this) */
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* Touch: no double-tap zoom delay or grey flash on buttons. */
button, .btn, a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.6;
}

header.site {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header.site a { color: inherit; text-decoration: none; font-weight: bold; }
header.site .logo { display: block; line-height: 0; }
header.site .logo img { display: block; height: var(--logo-h); width: auto; }
header.site nav a { margin-left: 16px; font-weight: normal; color: var(--muted); display: inline-block; padding: 8px 0; }

main { max-width: 880px; margin: 0 auto; padding: 24px 16px 64px; }

h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 32px 0 12px; }
.muted { color: var(--muted); font-size: 0.9rem; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 1.05rem;
  font-weight: bold;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
}
.btn.secondary { background: var(--surface); color: var(--text); border: 2px solid var(--border); }
.btn:disabled { opacity: 0.5; cursor: default; }

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 16px 0;
}

.notice.warn { border-color: #e0a100; background: #fff8e1; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: inherit;
  text-decoration: none;
}
@media (hover: hover) { .card:hover { border-color: var(--accent); } }
.card:active { border-color: var(--accent); }
.card .tag { font-size: 0.75rem; color: var(--muted); }

/* ---- play ---- */
main.play { max-width: 1180px; }
.play { text-align: center; }
/* Long presses on pictures should not start text selection or the iOS callout. */
#stage { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#stage .accept { -webkit-user-select: text; user-select: text; }
.parent-prompt { color: var(--muted); font-size: 0.95rem; min-height: 1.6em; }
.progress { color: var(--muted); font-size: 0.85rem; }
.speak-btn { font-size: 1.6rem; background: none; border: none; cursor: pointer; min-width: 48px; min-height: 48px; }

.timer { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 8px auto; max-width: 480px; }
.timer > div { height: 100%; background: var(--accent); width: 100%; transition: width 0.2s linear; }

.display { margin: 16px auto; display: flex; justify-content: center; gap: 24px; align-items: center; flex-wrap: wrap; }
.matrix { display: grid; grid-template-columns: repeat(2, var(--cell)); gap: 8px; }
.cell {
  width: var(--cell); height: var(--cell);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid var(--border); border-radius: 12px;
  font-size: var(--cell-font);
}
.cell svg { width: 66%; height: 66%; }
.cell.missing { border-style: dashed; color: var(--muted); }
.symbol-group { display: flex; gap: 8px; }
.symbol-target { border-color: var(--accent); }

.rows { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.choices { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.choice {
  width: var(--choice); height: var(--choice);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--surface); border: 3px solid var(--border); border-radius: var(--radius);
  font-size: var(--choice-font); cursor: pointer; padding: 0;
  color: var(--text);
  transition: transform 0.08s ease-out;
}
.choice svg { width: 54%; height: 54%; }
.choice:not(:disabled):active { transform: scale(0.95); }
.choice.label { font-size: calc(var(--choice-font) * 0.48); font-weight: bold; }
.choice.selected { border-color: var(--accent); }
.choice.correct { border-color: var(--ok); background: #e8f6ee; }
.choice.wrong { border-color: var(--ng); background: #fbeaea; }
.choice:disabled { cursor: default; }

.picture {
  width: var(--picture); height: var(--picture);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 3px solid var(--border); border-radius: 24px;
  font-size: var(--picture-font);
}
.display:has(.picture) { flex-direction: column; gap: 12px; }
.judge { max-width: 520px; }
.judge-icon { font-size: 4rem; }
.judge-help { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.accept {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: left;
}
.choice.label { width: calc(var(--choice) * 1.34); }

.feedback { font-size: 2.4rem; min-height: 3.6rem; margin-top: 16px; }

/* ---- play: feedback effects (cheer.js) ---- */
.feedback.pop { animation: fb-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes fb-pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Stars fly from (left, top) by (--dx, --dy); positions are set from JS. */
.cheer-layer { position: fixed; inset: 0; z-index: 200; pointer-events: none; overflow: hidden; }
.cheer-star {
  position: absolute; font-size: var(--star); line-height: 1;
  transform: translate(-50%, -50%) scale(0.3); opacity: 0;
  animation: cheer-fly 1.1s ease-out forwards;
}
@keyframes cheer-fly {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(0deg); opacity: 0; }
  15% { opacity: 1; }
  70% { opacity: 1; }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2) rotate(180deg);
    opacity: 0;
  }
}

/* Result screen: one star per question. */
#score { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 1.4rem; }
.star-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: calc(var(--star) * 11); }
.star { font-size: var(--star); line-height: 1.1; color: var(--border); animation: star-in 0.4s ease-out backwards; }
.star.on { color: inherit; }
@keyframes star-in {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); }
}

/* "Next" is the one button a child taps alone: make it big and obvious. */
.play .btn.next-btn { display: block; margin: 12px auto 0; font-size: 1.4rem; padding: 14px 48px; }
.play .btn.next-btn > span { font-size: 1.1em; }

@media (prefers-reduced-motion: reduce) {
  .feedback.pop, .star, .cheer-star { animation: none; }
}


/* ---- account ---- */
table.stats { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
table.stats th, table.stats td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.table-scroll { overflow-x: auto; }
.trend { display: flex; align-items: flex-end; gap: 3px; height: 32px; min-width: 70px; }
.trend .bar { display: block; width: 8px; background: var(--accent); border-radius: 2px 2px 0 0; }
.hidden { display: none !important; }

/* ---- boards (block design / object assembly) ---- */
.block-grid { display: grid; grid-template-columns: repeat(2, auto); gap: 0; justify-content: center; }
.block-grid.model { border: 3px solid var(--accent); border-radius: 8px; overflow: hidden; }
.block-grid.model svg { display: block; width: var(--model-block); height: var(--model-block); }
.block-grid.model.cols-3 svg { width: var(--model-block-3); height: var(--model-block-3); }
.block-grid.board { gap: 4px; margin: 8px auto; }
.board-cell {
  width: var(--board-cell); height: var(--board-cell); padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 3px dashed var(--border); border-radius: 8px; cursor: pointer;
}
.board-cell svg { width: 100%; height: 100%; display: block; }
.board.cols-3 .board-cell { width: var(--board-cell-3); height: var(--board-cell-3); }
.board-cell.correct { border: 3px solid var(--ok); }
.board-cell.wrong { border: 3px solid var(--ng); }
.tray { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.tray-piece:disabled { opacity: 0.2; }
.draggable { touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.draggable.dragging { opacity: 0.3; }
.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none;
  transform: translate(-50%, -50%) scale(1.1);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}
.board-cell.drop-over { border-style: solid; border-color: var(--accent); background: #fff6d6; }

/* A piece shows one quarter of a 2x --piece emoji in a --piece window. */
.piece { position: relative; display: block; width: var(--piece); height: var(--piece); overflow: hidden; }
.piece .whole {
  position: absolute; width: calc(var(--piece) * 2); height: calc(var(--piece) * 2);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--piece) * 1.6); line-height: 1;
}
.piece.tl .whole { left: 0; top: 0; }
.piece.tr .whole { left: calc(var(--piece) * -1); top: 0; }
.piece.bl .whole { left: 0; top: calc(var(--piece) * -1); }
.piece.br .whole { left: calc(var(--piece) * -1); top: calc(var(--piece) * -1); }
.board.puzzle { gap: 0; }
.board.puzzle .board-cell { width: calc(var(--piece) + 6px); height: calc(var(--piece) + 6px); border-radius: 0; }
.tray .choice { width: calc(var(--piece) + 40px); height: calc(var(--piece) + 40px); }

/* ---- coding ---- */
.code-key { display: flex; gap: 12px; padding: 8px 12px; border: 3px solid var(--accent); border-radius: 12px; background: var(--surface); }
.code-pair { display: flex; flex-direction: column; align-items: center; }
.code-pair svg { width: calc(var(--choice-sm) * 0.66); height: calc(var(--choice-sm) * 0.66); }
.code-pair .mark { font-size: 2rem; font-weight: bold; line-height: 1.2; }
.row-head { border-color: transparent; background: none; }
.row-head svg { width: 78%; height: 78%; }
.choices .row-head { width: var(--choice-sm); height: var(--choice-sm); }
.choices:has(.row-head) .choice { width: var(--choice-sm); height: var(--choice-sm); font-size: calc(var(--choice-sm) * 0.36); }
.drawing { width: calc(var(--picture) * 1.2); height: calc(var(--picture) * 1.2); }
.drawing svg { width: 92%; height: 92%; }

/* ---- play: screen sizes (tablet first) ---- */

/* Phones */
@media (max-width: 480px) {
  :root {
    --choice: 84px; --choice-font: 2.4rem; --choice-sm: 60px;
    --cell: 72px; --cell-font: 2rem;
    --picture: 170px; --picture-font: 6.4rem;
    --board-cell: 96px; --board-cell-3: 76px;
    --model-block: 60px; --model-block-3: 46px;
    --piece: 72px;
    --star: 2rem;
    --logo-h: 36px;
  }
}

/* Tablets (iPad mini portrait 744px and up). Bigger targets for small fingers. */
@media (min-width: 700px) and (min-height: 640px) {
  :root {
    --choice: 148px; --choice-font: 4.4rem; --choice-sm: 92px;
    --cell: 116px; --cell-font: 3.2rem;
    --picture: 260px; --picture-font: 10.5rem;
    --board-cell: 132px; --board-cell-3: 104px;
    --model-block: 92px; --model-block-3: 70px;
    --piece: 104px;
    --star: 3rem;
  }
  .play .btn { padding: 16px 40px; font-size: 1.25rem; }
  .parent-prompt { font-size: 1.1rem; }
  .speak-btn { font-size: 2rem; }
  .choices { gap: 16px; }
  .tray { gap: 16px; }
}

/* Large tablets (iPad Pro 12.9" etc.) */
@media (min-width: 1000px) and (min-height: 1000px) {
  :root {
    --choice: 172px; --choice-font: 5.2rem; --choice-sm: 104px;
    --cell: 136px; --cell-font: 3.8rem;
    --picture: 300px; --picture-font: 12rem;
    --board-cell: 156px; --board-cell-3: 120px;
    --model-block: 108px; --model-block-3: 80px;
    --piece: 124px;
    --star: 3.4rem;
  }
}

/* Landscape tablets: the screen is short, so put the stimulus (display) and
   the answers (rows) side by side instead of stacking them. */
@media (orientation: landscape) and (min-width: 900px) and (max-height: 999px) {
  #stage .stage-main:has(.display:not(:empty)) {
    display: flex; align-items: center; justify-content: center; gap: 40px;
  }
  #stage .stage-main:has(.display:not(:empty)) > .display { margin: 0; flex: 0 1 auto; max-width: 50%; }
  #stage .stage-main:has(.display:not(:empty)) > .rows { margin: 0; flex: 0 1 auto; max-width: 55%; }
  .play h1 { font-size: 1.3rem; margin: 0; }
  .play #description { display: none; }
  main.play { padding-top: 12px; }
  .feedback { margin-top: 8px; }
  .play .btn.next-btn { margin-top: 4px; }
}

/* ---- footer / legal ---- */
footer.site { text-align: center; padding: 24px 16px; border-top: 1px solid var(--border); font-size: 0.85rem; }
footer.site a { color: var(--muted); margin: 0 8px; display: inline-block; }
.legal h2 { font-size: 1.05rem; margin-top: 24px; }
.legal table.stats th { vertical-align: top; width: 32%; }

/* ---- landing sections ---- */
.features { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.feature p { margin: 6px 0 0; font-size: 0.9rem; color: var(--muted); }
.feature-icon { font-size: 2rem; }
.price-card { background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius); padding: 20px; text-align: center; }
.price { font-size: 1.2rem; }
.price strong { font-size: 2.4rem; color: var(--accent); }
.price-card ul { text-align: left; display: inline-block; margin: 12px 0 16px; padding-left: 1.2em; }
/* Top page hero: the big logo (img/logo-hero.png is 2x its widest size). */
.hero { text-align: center; margin: 8px 0 24px; }
.hero img { display: inline-block; width: 100%; max-width: 480px; height: auto; }

.lp details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.lp summary { cursor: pointer; font-weight: bold; }
.lp details p { margin: 8px 0 0; }

/* Sign-in (login.html, account.html) */
.login-box { max-width: 420px; }
.login-box .btn { display: block; width: 100%; text-align: center; margin: 8px 0; }
.login-box form { margin-top: 16px; }
.login-box label { display: block; font-weight: bold; margin-bottom: 4px; }
.login-box input[type="email"] {
  width: 100%;
  box-sizing: border-box;
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.login-box .or { text-align: center; color: var(--muted); margin: 16px 0 0; }
.account-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }

/* ---- Admin pages (admin.html) ---- */
.admin main { max-width: 1100px; }
.admin-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 20px; }
.admin-q-list {
  display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  /* Smaller than the play screen: many questions on one page. */
  --choice: 56px; --choice-font: 1.6rem; --choice-sm: 44px; --cell: 52px; --cell-font: 1.4rem;
  --picture: 110px; --picture-font: 4rem; --board-cell: 56px; --board-cell-3: 44px;
  --model-block: 40px; --model-block-3: 32px; --piece: 44px;
}
.admin-q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow: hidden; }
.admin-q .prompt { font-weight: bold; margin: 6px 0; }
.admin-q .display { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }
.admin-q .choices { gap: 6px; margin: 6px 0; }
.admin-q .choice { cursor: default; }
.admin-q-head { font-size: 0.8rem; word-break: break-all; }
.badge { display: inline-block; margin: 0 4px; padding: 0 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.75rem; }
.admin-oral textarea { width: 100%; min-width: 220px; font: inherit; padding: 6px; border: 1px solid var(--border); border-radius: 8px; resize: vertical; }
.admin-oral tr.changed td { background: #fff4d6; }
.admin-oral tr.added td { background: #e8f6ee; }
.admin-oral td:first-child { white-space: nowrap; }
.admin select, .admin-search input { font: inherit; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.admin-search { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.admin-search input { flex: 1; min-width: 240px; }

/* ---- Guide pages (/guide/, server-rendered) ---- */
.guide .breadcrumb { margin-bottom: 8px; }
.guide .breadcrumb a { color: inherit; }
.guide .lead { font-size: 1.05rem; }
.guide h2 { margin-top: 28px; }
.guide li { margin: 4px 0; }
.guide .card strong, .guide .card .muted { display: block; }
.guide-list { padding-left: 1.2em; }
.guide-list p { margin: 2px 0 10px; }
.guide-related { display: flex; flex-wrap: wrap; gap: 6px 16px; padding-left: 0; list-style: none; }
.guide-cta { margin-top: 40px; background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius); padding: 16px 20px; }
.guide-cta h2 { margin-top: 0; }
header.site nav a + a { margin-left: 12px; }

/* ---- Share / invite ---- */
.share { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.share.compact .btn { padding: 8px 16px; font-size: 0.95rem; }
.share-status { word-break: break-all; }
.share-parent { margin-top: 24px; text-align: left; }
.share-parent summary { cursor: pointer; }
