:root {
  --blue: #2f80ed;
  --blue-d: #1c5fc4;
  --blue-l: #cfe6ff;
  --sky: #e6f3ff;
  --navy: #1b2a5c;
  --yellow: #ffd60a;
  --yellow-d: #d9a900;
  /* 絵の幅：PCでは画面の高さにおさまるように */
  --cw: min(100vw, 860px, calc((100dvh - 316px) * 1.25));
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-weight: 700;
  color: var(--navy);
  background-color: var(--sky);
  background-image: radial-gradient(#fff 2.5px, transparent 3px);
  background-size: 26px 26px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

header {
  width: 100%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  padding-top: calc(7px + env(safe-area-inset-top));
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ---- ボタン ---- */
.btn {
  font: inherit;
  color: var(--navy);
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 0 #b9cfee;
  min-height: 46px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b9cfee; }
.btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.btn.small { min-height: 36px; font-size: 13px; border-radius: 12px; box-shadow: 0 3px 0 var(--blue-d); }
.btn.small:active { box-shadow: 0 0 0 var(--blue-d); }
.btn.primary { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-d); }
.btn.primary:active { box-shadow: 0 1px 0 var(--blue-d); }
.btn.big { min-height: 54px; font-size: 18px; font-weight: 800; }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--blue-d); }

.ic { width: 22px; height: 22px; flex: none; }
.ic.line { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ic.fill { fill: currentColor; }

/* ---- お題タブ ---- */
#tabs {
  width: min(100%, var(--cw));
  display: flex;
  gap: 6px;
  padding: 8px 8px 6px;
}
#tabs button {
  flex: 1;
  font: inherit;
  font-size: 14px;
  color: var(--blue-d);
  background: #fff;
  border: 2px solid var(--blue-l);
  border-radius: 999px;
  min-height: 36px;
  padding: 0 4px;
  cursor: pointer;
}
#tabs button[aria-selected="true"] {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

#sharedBar {
  padding: 10px 12px 8px;
  font-size: 16px;
  color: var(--blue-d);
}

/* ---- 絵 ---- */
#stage { width: var(--cw); line-height: 0; }
#cv {
  width: 100%;
  height: auto;
  aspect-ratio: 5 / 4;
  display: block;
  background: #eef6ff;
  touch-action: none;
  cursor: crosshair;
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--blue-l);
}
body.view #cv { cursor: default; }

.row {
  width: min(100%, max(var(--cw), 420px));
  display: flex;
  gap: 8px;
  padding: 0 8px;
  margin-top: 10px;
}
#editUI { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* ---- 再生 ---- */
#transport { margin-top: 14px; }
.btn.play {
  flex: 2;
  min-height: 52px;
  font-size: 19px;
  font-weight: 800;
  background: var(--yellow);
  box-shadow: 0 4px 0 var(--yellow-d);
}
.btn.play:active { box-shadow: 0 1px 0 var(--yellow-d); }
.btn.play .icStop { display: none; }
body.playing .btn.play .icStop { display: block; }
body.playing .btn.play .icPlay { display: none; }
.btn.toggle { flex: 1; min-height: 52px; font-size: 14px; color: #6b7fae; }
.btn.toggle[aria-pressed="true"] { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-d); }

/* ---- パレット ---- */
#palette { gap: 6px; }
.swatch {
  flex: 1;
  min-width: 0;
  height: 62px;
  border: 0;
  border-radius: 14px;
  padding: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(27, 42, 92, 0.28);
  transition: transform 0.08s;
}
.swatch svg { width: 26px; height: 26px; }
.swatch[aria-checked="true"] {
  transform: translateY(-7px);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--navy), 0 10px 0 rgba(27, 42, 92, 0.18);
}
.swatch:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }

/* ---- 道具 ---- */
.btn.tool { flex: 1; min-width: 0; padding: 0 4px; font-size: 12px; gap: 4px; }
.btn.tool .ic { width: 20px; height: 20px; }
.btn.tool[aria-pressed="true"] { background: var(--navy); color: #fff; box-shadow: 0 4px 0 #0c1536; }
.sizeDots { display: inline-flex; align-items: center; gap: 2px; }
.sizeDots i { display: block; border-radius: 50%; background: #c3d0ea; }
.sizeDots i:nth-child(1) { width: 6px; height: 6px; }
.sizeDots i:nth-child(2) { width: 10px; height: 10px; }
.sizeDots i:nth-child(3) { width: 15px; height: 15px; }
#btnSize[data-size="0"] i:nth-child(1),
#btnSize[data-size="1"] i:nth-child(2),
#btnSize[data-size="2"] i:nth-child(3) { background: var(--navy); }

#viewUI { margin-top: 14px; }
#viewUI .btn { width: 100%; }

/* ---- かさねる画面 ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(47, 128, 237, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}
.card {
  width: min(100%, 400px);
  max-height: 100%;
  overflow: auto;
  background: #fff;
  border-radius: 26px;
  padding: 22px 20px 18px;
  text-align: center;
  box-shadow: 0 8px 0 var(--blue-d);
}
.card h2 { margin: 0 0 8px; font-size: 20px; font-weight: 800; }
.card .logo { font-size: 30px; color: var(--blue); letter-spacing: 0.04em; }
.lead { margin: 0 0 14px; font-size: 15px; line-height: 1.7; }
.note { margin: 10px 0 14px; font-size: 12.5px; line-height: 1.6; color: #55679a; text-align: left; }
.col { display: flex; flex-direction: column; gap: 10px; }

.legend { display: flex; justify-content: center; gap: 5px; margin-bottom: 14px; }
.legend div {
  width: 40px;
  height: 48px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: transform 0.1s;
}
.legend svg { width: 20px; height: 20px; }
.legend div.on { transform: translateY(-8px) scale(1.12); }

#shareImg {
  width: 100%;
  border-radius: 14px;
  border: 2px solid var(--blue-l);
  background: var(--sky);
  aspect-ratio: 1200 / 1170;
  -webkit-touch-callout: default;
}
#shareUrl {
  width: 100%;
  font: inherit;
  font-size: 13px;
  color: var(--navy);
  border: 2px solid var(--blue-l);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  background: #f4f9ff;
  -webkit-user-select: text;
  user-select: text;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  z-index: 20;
  max-width: calc(100vw - 32px);
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- スマホ（縦持ち）：絵は画面の幅いっぱい ---- */
@media (max-width: 600px) and (orientation: portrait) {
  :root { --cw: 100vw; }
  #cv { border-radius: 0; box-shadow: none; }
  header h1 { font-size: 18px; }
  #tabs { padding: 6px 6px 5px; }
  .row { margin-top: 8px; }
  #transport { margin-top: 10px; }
}

@media (max-width: 360px) {
  .btn.tool span:last-child { font-size: 10.5px; }
  .btn.small span { display: none; }
}
