:root {
  --bg: #1d2b53;
  --bg2: #2b4a8b;
  --card: #fffdf6;
  --ink: #3a2a20;
  --muted: #6b5a4e;
  --accent: #ff8a3d;
  --accent2: #ff5a8a;
  --ok: #2f9e5a;
  --line: #f1dcc2;
  --err-bg: #fff0f0;
  --err-line: #f2a3a3;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --card: #22263a;
    --ink: #f4efe8;
    --muted: #c9c0b6;
    --line: #3b4160;
    --err-bg: #3a2228;
    --err-line: #8a4a55;
  }
}
:root[data-theme="dark"] {
  --card: #22263a;
  --ink: #f4efe8;
  --muted: #c9c0b6;
  --line: #3b4160;
  --err-bg: #3a2228;
  --err-line: #8a4a55;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) fixed;
  color: var(--ink);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Meiryo", sans-serif;
  font-weight: 500;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
#cam { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: -10px; top: -10px; }

/* ---------- はじめの画面 ---------- */
#start {
  min-height: 100%;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px 40px;
}
.card {
  width: 100%; max-width: 720px;
  background: var(--card);
  border-radius: 24px;
  padding: 24px 22px 18px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.kicker { margin: 0 0 4px; color: var(--accent); font-weight: 800; font-size: 14px; letter-spacing: .05em; }
h1 { margin: 0 0 10px; font-size: clamp(24px, 6vw, 34px); font-weight: 900; line-height: 1.25; }
h1 span { display: inline-block; background: var(--accent); color: #fff; font-size: .6em; padding: 2px 10px; border-radius: 999px; vertical-align: middle; }
.lead { margin: 0 0 14px; font-size: 16px; line-height: 1.7; }
.privacy {
  border: 2px solid var(--ok); border-radius: 16px; padding: 12px 14px;
  font-size: 14px; line-height: 1.7; margin-bottom: 16px;
}
.privacy b { display: block; color: var(--ok); font-size: 15px; margin-bottom: 2px; }
.actions { display: flex; flex-direction: column; gap: 10px; }
button, .big, .sub { font-family: inherit; cursor: pointer; }
.big {
  display: block; width: 100%; border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #ff9f4d, #ff6a3d); color: #fff;
  font-size: 22px; font-weight: 900; padding: 16px 20px; text-align: center; text-decoration: none;
  box-shadow: 0 5px 0 #c94a20;
}
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #c94a20; }
.big:disabled { opacity: .6; cursor: progress; }
.sub {
  display: block; width: 100%; border: 2px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink); font-size: 16px; font-weight: 800; padding: 11px 16px;
}
.lite { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 14px; color: var(--muted); margin: 12px 4px 4px; line-height: 1.5; font-weight: 800; }
.lite select { font: inherit; font-size: 15px; min-height: 40px; max-width: 100%; padding: 4px 8px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
.litenow { font-size: 12.5px; font-weight: 700; }
.rothint { display: none; margin: 12px 4px 0; font-size: 14px; line-height: 1.6; color: var(--muted); }
@media (orientation: portrait) and (pointer: coarse) { .rothint { display: block; } }
.err {
  margin: 14px 0 4px; padding: 12px 14px; border-radius: 14px;
  background: var(--err-bg); border: 2px solid var(--err-line); font-size: 15px; line-height: 1.7;
}
.err b { display: block; font-size: 17px; margin-bottom: 4px; }
details { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 10px; }
summary { cursor: pointer; font-weight: 800; font-size: 15px; padding: 4px 0; }
details ul { margin: 8px 0 0; padding-left: 20px; font-size: 14px; line-height: 1.75; }
details li { margin-bottom: 6px; }
.file { display: inline-block; border: 2px solid var(--line); border-radius: 10px; padding: 2px 10px; cursor: pointer; font-weight: 800; }
.file input { display: none; }
.product { margin: 18px 0 6px; font-size: 15px; text-align: center; }
.product a { color: var(--accent2); }
.fine { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; }

/* ---------- あそぶ画面 ---------- */
#stage { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud {
  position: absolute; right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom));
  display: flex; gap: 6px; align-items: center; opacity: .55; transition: opacity .2s;
}
#hud:hover, #hud:focus-within { opacity: 1; }
.hb {
  min-width: 38px; height: 38px; border-radius: 999px; border: 2px solid rgba(255,255,255,.7);
  background: rgba(20,30,60,.55); color: #fff; font-size: 17px; font-weight: 900; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; text-decoration: none;
  font-family: inherit;
}
.hb.off { text-decoration: line-through; opacity: .6; }
.hb.wide { font-size: 13px; }
#loadchip {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  background: rgba(20,30,60,.75); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 800;
  white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis;
}
#debug {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #8f8; font: 12px/1.4 monospace;
  padding: 6px 8px; border-radius: 6px; white-space: pre; pointer-events: none;
}

/* ---------- おしらせ・あそびかた・おとなの人へ ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 10; overflow-y: auto;
}
.overlay[hidden], #stage[hidden], #start[hidden] { display: none; }
.mbox {
  width: 100%; max-width: 520px; background: var(--card); color: var(--ink); border-radius: 22px; padding: 22px 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,.4); font-size: 16px; line-height: 1.7; margin: auto;
}
.mbox.wide { max-width: 640px; }
.mbox .mt { font-size: 24px; font-weight: 900; margin: 0 0 8px; line-height: 1.4; }
.mbox .mt b { color: var(--accent2); }
.mbox h3 { font-size: 17px; margin: 18px 0 6px; padding-top: 12px; border-top: 1px dashed var(--line); }
.mbox ul { padding-left: 20px; margin: 0 0 6px; }
.mbtns { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.mbtns .big { font-size: 18px; }
.small { font-size: 13.5px; color: var(--muted); line-height: 1.65; margin: 6px 0; }
.warn { color: #b0571a; }
textarea#codeInput {
  width: 100%; font: 700 15px/1.5 ui-monospace, "Consolas", "Menlo", monospace; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--line); background: #fff; color: #2a2a2a; resize: vertical; letter-spacing: .02em;
}
.rowbtns { margin-top: 8px; }
.rowbtns .big { font-size: 18px; padding: 12px 16px; }
.status { margin: 10px 0 4px; padding: 10px 12px; border-radius: 12px; font-size: 14px; line-height: 1.6; border: 2px solid var(--line); }
.status b { display: block; font-size: 15.5px; }
.status.ok { border-color: var(--ok); background: rgba(47,158,90,.08); }
.status.ok b { color: var(--ok); }
.status.warn { border-color: #e0a030; background: rgba(224,160,48,.10); }
.status.err { border-color: var(--err-line); background: var(--err-bg); }
.status.info b { color: var(--ink); }
.buy { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .buy { grid-template-columns: 1fr; } }
.plan { border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.plan b { font-size: 16px; }
.buybtn { font-size: 16px !important; padding: 10px 12px !important; }
a.sub.buybtn { text-align: center; text-decoration: none; }
.todo { display: inline-block; background: #ffe45c; color: #4a3b00; border: 2px dashed #c9a400; border-radius: 8px; padding: 4px 8px; font-weight: 800; font-size: 12.5px; }
.todo[hidden] { display: none; }
.pending { display: inline-block; background: #eef1f6; color: #555; border-radius: 8px; padding: 4px 8px; font-weight: 700; font-size: 12.5px; }
.pending[hidden] { display: none; }
.mini { display: inline-block; font: inherit; font-size: 13px; font-weight: 800; color: var(--accent2); background: none; border: 0; padding: 2px 0; cursor: pointer; text-decoration: underline; }
.mini[hidden] { display: none; }
.soonlist { list-style: none; padding: 0 !important; margin: 8px 0 0 !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 50vh; overflow-y: auto; }
.soonlist li { border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; font-size: 14px; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.chip { font-size: 11px; font-weight: 800; background: #ffe45c; color: #4a3b00; border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.licbadge { display: inline-block; margin: 0 0 10px; padding: 4px 12px; border-radius: 999px; font-weight: 900; font-size: 14px; }
.licbadge.trial { background: #fff1c2; color: #6b4f00; }
.licbadge.full { background: #d5f5e0; color: #1f6b3d; }
.licbadge.warn { background: #ffe0b8; color: #8a4a00; }

/* 長押しボタン（子どもが うっかり押しても ひらかない） */
.hold { position: relative; overflow: hidden; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: none; }
.holdfill { position: absolute; inset: 0; background: rgba(255,138,61,.35); transform: scaleX(0); transform-origin: left center; pointer-events: none; }
.hold.holding { outline: 3px solid var(--accent); }
.parentrow { margin-top: 14px; }
.holdbig {
  display: block; width: 100%; border: 2px dashed var(--line); border-radius: 14px; background: transparent; color: var(--ink);
  font: inherit; font-weight: 800; font-size: 15px; padding: 10px 14px; text-align: center; cursor: pointer;
}
.holdbig small { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }

/* ---------- 縦持ちの案内（「よこに してね」） ---------- */
#rotate {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); text-align: center; color: #fff;
  background: rgba(20,30,60,.82);
}
#rotate[hidden] { display: none; }
.rotsvg { width: min(56vw, 260px); height: auto; }
.rotdev { transform-origin: 100px 80px; animation: rotdev 2.4s ease-in-out infinite; }
.rotarrow { animation: rotarrow 2.4s ease-in-out infinite; }
@keyframes rotdev { 0%, 25% { transform: rotate(0deg); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0deg); } }
@keyframes rotarrow { 0%, 20% { opacity: 1; } 50%, 90% { opacity: 0; } 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .rotdev, .rotarrow { animation: none; } }
.rottitle { margin: 6px 0 0; font-size: clamp(30px, 9vw, 52px); font-weight: 900; text-shadow: 0 3px 0 #1d2b53; }
.rotsub { margin: 0; font-size: 16px; font-weight: 800; opacity: .9; }
.rotok { width: auto !important; margin-top: 18px; color: #fff !important; border-color: rgba(255,255,255,.7) !important; padding: 12px 26px !important; min-height: 48px; }

/* ---------- タッチの端末: 指で押しやすい大きさ（48px 以上） ---------- */
@media (pointer: coarse) {
  .hb { min-width: 48px; height: 48px; font-size: 19px; }
  .hb.wide { font-size: 14px; }
  #hud { gap: 10px; opacity: .7; }
  .sub, .mbtns .big { min-height: 48px; }
  summary { padding: 10px 0; }
  .holdbig { padding: 14px; }
}
/* あそぶ画面で 長押しの 文字選択・虫めがね・コピーの メニューを出さない（iPad Safari） */
#stage, #stage * { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
html, body { overscroll-behavior: none; }
