html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a1c20;
  color: #fff;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
/* 検索エンジン・読み上げ用の説明：画面には出さない（文字としては、ページの中にある） */
.seo {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: normal;
}
canvas#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  white-space: nowrap;
}
button.on,
button.primary {
  background: #fff;
  color: #111;
  border-color: #fff;
}
button.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: none;
}

/* 上：題名のバー（1 行目）と、その下のボタン列（2 行目）。せまい画面でも、題名が切れない */
.ui.top {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  pointer-events: none;
}
.ui.top > * {
  pointer-events: auto;
}
.titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 14px 4px 4px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.titlebar .home {
  color: #fff;
  text-decoration: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  flex: none;
}
.titlebar .ttl {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar .grow {
  flex: 1;
}
/* PC（広い画面）：題名のバーにはせず、これまで通り、題名とボタンを 1 行に横並べ */
@media (min-width: 720px) {
  .ui.top {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .titlebar {
    flex: 1;
    min-width: 0;
    padding: 0;
    gap: 8px;
    background: none;
    border: 0;
    border-radius: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .titlebar .home {
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .titlebar .ttl {
    flex: none;
    max-width: 100%;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 400;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .toolbar {
    flex: none;
  }
  #toast {
    top: calc(max(10px, env(safe-area-inset-top)) + 52px);
  }
}
.sync .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #777;
  margin-right: 6px;
  vertical-align: middle;
}
.sync.on .dot {
  background: #3ddc84;
  box-shadow: 0 0 8px #3ddc84;
}
.sync b {
  font-weight: 700;
  margin-left: 2px;
}

/* 下のパネル */
#panels {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 56px);
  display: flex;
  justify-content: center;
  pointer-events: none;
}
#panels section {
  pointer-events: auto;
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(20, 22, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
}
#panels section[hidden],
#panels [hidden] {
  display: none;
}
#panels .row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#panels .row.end {
  justify-content: flex-end;
}
#panels .note {
  margin: 0;
  font-size: 11.5px;
  opacity: 0.75;
  line-height: 1.5;
}
#panels section {
  position: relative; /* 形の一覧を、パネルの上にひらくため */
}
/* 形を選ぶボタン（いまの形の名前を出す）と、ひらく一覧 */
button.pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button.pick svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s;
}
button.pick[aria-expanded="true"] svg {
  transform: rotate(180deg);
}
.shape-grid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
  padding: 10px;
  background: rgba(20, 22, 26, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 5;
}
.shape-grid[hidden] {
  display: none;
}
.shape-grid button {
  padding: 8px 6px;
}
/* PC（広い画面）：形は、たたまずに、最初から全部ならべる。パネルは、角を小さく丸め、余白を広めに */
@media (min-width: 720px) {
  #shapeBtn {
    display: none;
  }
  #panels .shape-grid,
  #panels .shape-grid[hidden] {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: auto;
  }
  .shape-grid button {
    padding: 7px 14px;
  }
  /* 物体のパネル：形・つまみの種類・もとに戻す、を、すきまなく折り返して並べる */
  #panels section[data-panel="object"] {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  #panels section[data-panel="object"] .shape-grid,
  #panels section[data-panel="object"] .note {
    flex: 1 0 100%;
  }
  #panels section[data-panel="object"] .row {
    display: contents;
  }
  #panels section {
    width: min(640px, 100%);
    padding: 14px 16px;
    border-radius: 12px;
  }
  /* 形が 11 個、1 行に入る幅 */
  #panels section[data-panel="object"] {
    width: min(830px, 100%);
  }
}
.seg {
  display: inline-flex;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  overflow: hidden;
}
.seg button {
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.3);
}
.seg button.on {
  background: #fff;
  color: #111;
}
.seg button + button {
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}
textarea {
  flex: 1;
  min-width: 120px;
  resize: none;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 7px 10px;
  line-height: 1.4;
  max-height: 80px;
}
/* アイコン（線の太さをそろえる） */
svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
/* 色・写真のボタン。本物の入力は、上に透明でかぶせる */
label.tool {
  position: relative;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  flex: none;
}
label.tool input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: 0;
}
label.tool input[type="file"] {
  font-size: 0;
}
/* いまの色を、右下の丸で見せる */
label.tool .swatch {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--ink, #1a1a1a);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
label.slider {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 150px;
  white-space: nowrap;
}
label.slider input[type="range"] {
  flex: 1;
  min-width: 80px;
  accent-color: #fff;
}
label.slider select {
  flex: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 5px 8px;
}
label.check {
  display: flex;
  align-items: center;
  gap: 8px;
}
label.check input {
  accent-color: #fff;
}

/* モード切り替え */
#modes {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(20, 22, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#modes button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 8px 16px;
}
#modes button.on {
  background: #fff;
  color: #111;
}

/* お知らせ */
#toast {
  position: fixed;
  left: 50%;
  top: calc(max(10px, env(safe-area-inset-top)) + 100px);
  transform: translateX(-50%);
  width: max-content; /* left: 50% だと、使える幅が半分になるので、文字の長さに合わせる */
  max-width: min(90vw, 480px);
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  transition: opacity 0.6s;
}
#toast[hidden] {
  display: none;
}
/* 警告（見えない・視点にできない）は、赤みのある色で、目立たせる */
#toast.warn {
  background: rgba(120, 36, 36, 0.92);
  border-color: rgba(255, 170, 170, 0.6);
  font-weight: 600;
}
/* 携帯：大きく、広く */
@media (max-width: 600px) {
  #toast {
    max-width: calc(100vw - 24px);
    padding: 14px 18px;
    font-size: 15.5px;
    line-height: 1.7;
    border-radius: 14px;
  }
}

/* 設定・使い方・保存：全画面。上に題名と閉じるボタン、まん中がスクロール、（保存は）下にボタン */
dialog {
  border: 0;
  border-radius: 0;
  margin: 0;
  padding: 0;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  background: #1a1c20;
  color: #fff;
  display: none;
  flex-direction: column;
  font-size: 13px;
}
dialog[open] {
  display: flex;
}
.dhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex: none;
}
dialog h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.08em;
}
.dbody {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 18px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
/* 縦にならべた項目は、のびずに、中身の高さのまま */
dialog .dbody > * {
  flex: none;
}
.dfoot {
  flex: none;
  padding: 10px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.dfoot button {
  display: block;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px;
  font-size: 14px;
}
dialog .row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
dialog .row.end {
  justify-content: flex-end;
}

dialog .note {
  margin: -6px 0 0;
  font-size: 11.5px;
  opacity: 0.7;
  line-height: 1.5;
}

/* 操作の説明は、指で使う画面と、マウスで使う画面で、出し分ける */
@media (hover: hover) and (pointer: fine) {
  .only-touch {
    display: none;
  }
}
@media (hover: none), (pointer: coarse) {
  .only-mouse {
    display: none;
  }
}

/* リンク：縦にならべて、外に出ることがわかるように */
dialog .links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding-top: 8px;
}
dialog .links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  text-decoration: none;
  padding: 9px 4px;
  font-size: 13px;
  border-radius: 8px;
}
dialog .links a:hover {
  background: rgba(255, 255, 255, 0.08);
}
dialog .links a svg {
  width: 15px;
  height: 15px;
  opacity: 0.7;
}

/* 使い方 */
.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.step {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
}
.step h3 {
  margin: 4px 0 0;
  font-size: 13.5px;
}
.step p {
  margin: 0;
  font-size: 12px;
  line-height: 1.65;
  opacity: 0.85;
}
.step .art {
  width: 100%;
  height: auto;
  background: #2b2f38;
  border-radius: 8px;
  stroke-width: 1;
}
.step .art .ink {
  fill: #1a1a1a;
  stroke: none;
}
.step .art .eye {
  fill: #fff;
  stroke: none;
}
.step .art .ray {
  stroke: #fff;
  stroke-dasharray: 3 3;
  fill: none;
}
.modes-art {
  display: flex;
  justify-content: space-around;
  padding: 14px 6px;
  background: #2b2f38;
  border-radius: 8px;
}
.modes-art span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}
.modes-art svg {
  width: 26px;
  height: 26px;
}
.sync-art {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.sync-art > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  background: #2b2f38;
  border-radius: 8px;
}
.sync-art .chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 11px;
  font-weight: 700;
}
.sync-art .chip i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #777;
}
.sync-art .chip.on {
  background: #fff;
  color: #111;
}
.sync-art .chip.on i {
  background: #3ddc84;
}
.sync-art b {
  display: block;
  width: 46px;
  height: 52px;
  line-height: 52px;
  text-align: center;
  font-size: 30px;
  background: #d8dade;
  color: #1a1a1a;
  border-radius: 8px;
}
.sync-art b.skew {
  transform: skewX(-18deg) scaleY(0.8) rotate(8deg);
}
.sync-art em {
  font-style: normal;
  font-size: 11px;
  opacity: 0.8;
}

/* 全画面：余計なものを出さない */
#exitFull {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  opacity: 0.55;
}
#exitFull[hidden] {
  display: none;
}
.full .ui.top,
.full #panels,
.full #modes,
.full #toast {
  display: none;
}

.err {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 120px;
  padding: 12px;
  background: #a22;
  font-size: 12px;
  white-space: pre-wrap;
  border-radius: 8px;
}
