/* Overwrite Space — ステッカー & チャンキー。
   ほぼ黒のワークスペースに白いカードが浮かび、ボタンは厚みのある縁で
   ばねのように沈む。色はスウォッチとアクセントの朱 #FF3D20 に語らせる。 */
:root {
  --ws: #101013;
  --card: #ffffff;
  --ink: #18181b;
  --muted: #82828b;
  --faint: #ececef;
  --accent: #ff3d20;
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: "M PLUS Rounded 1c", "Hiragino Sans", system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--ws);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: grab;
}
#stage.drawing { cursor: crosshair; }
#stage.drawing.moving { cursor: move; }
#stage.panning { cursor: grabbing; }
#stage.linkable { cursor: pointer; }

.card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* ---------- 上部 ---------- */
#hudTop {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
#hudTop > * { pointer-events: auto; }

#brand {
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 14.5px;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 9px 15px;
  border-radius: 13px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}
#brand i {
  width: 9px;
  height: 9px;
  border-radius: 2.5px;
  background: var(--accent);
}

#hudRight {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 回る数取器 — さりげなく、でも回っているのがわかる */
#counter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
}
#cntLabel {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
}
#cntWin {
  display: inline-flex;
  gap: 2px;
  background: var(--ink);
  padding: 3px 4px;
  border-radius: 7px;
}
#cntWin span {
  display: block;
  width: 11px;
  overflow: hidden;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 17px;
  color: #fff;
  background: #2c2c31;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
#cntWin span.tick { animation: tick 0.3s var(--bounce); }
@keyframes tick {
  from { transform: translateY(60%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- ボタン(厚みのある縁 + ばね押し込み) ---------- */
button {
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 800;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--ink);
  border-bottom-width: 5px;
  border-radius: 13px;
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform 0.12s var(--bounce), border-bottom-width 0.12s ease, background 0.12s ease;
}
button:hover { background: #f5f5f7; }
button:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}
button:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
  border-bottom-width: 5px;
}

.primary {
  background: var(--accent);
  color: #fff;
}
.primary:hover { background: #ef3315; }
.primary.big { padding: 14px 40px; font-size: 16px; border-radius: 16px; }
.primary.busy { pointer-events: none; opacity: 0.75; }

.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.ghost:hover { background: rgba(24, 24, 27, 0.06); color: var(--ink); }
.ghost:active { transform: none; }

#langBtn { padding: 7px 12px; font-size: 12px; border-radius: 11px; }

/* ---------- 下部 HUD ---------- */
.hud {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 16px);
  transition: opacity 0.18s ease, transform 0.18s var(--bounce);
}
.hud.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(14px) scale(0.98);
}

/* ---------- ツールバー ---------- */
#toolbar {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 14px;
}

#palette {
  display: grid;
  grid-template-rows: repeat(2, 24px);
  grid-auto-flow: column;
  grid-auto-columns: 24px;
  gap: 5px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
}
#palette::-webkit-scrollbar { display: none; }

.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 2px solid rgba(24, 24, 27, 0.12);
  border-bottom-width: 2px;
  border-radius: 8px;
  transition: transform 0.12s var(--bounce), border-color 0.12s ease;
}
.swatch:hover { transform: scale(1.12); border-color: rgba(24, 24, 27, 0.4); }
.swatch:active { transform: scale(0.95); border-bottom-width: 2px; }
.swatch.sel {
  border-color: var(--ink);
  transform: scale(1.18);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent);
}

#pickBtn {
  font-size: 15px;
  line-height: 1;
  font-weight: 800;
  color: #fff;
  background: conic-gradient(#ff3d20, #ffd635, #00cc78, #3690ea, #b44ac0, #ff3d20);
  position: relative;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
#colorPick {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

#tools, #actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
}

#legalLinks {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}
#legalLinks a {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#legalLinks a:hover { color: var(--ink); }

.tool {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  color: var(--ink);
}
.tool.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.brush {
  width: 34px;
  height: 34px;
  padding: 0;
  border-width: 2px;
  border-radius: 10px;
  color: var(--ink);
}
.brush i {
  display: block;
  border-radius: 50%;
  background: currentColor;
}
.brush.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
#brushRow { display: inline-flex; gap: 5px; }

.sep {
  width: 2px;
  height: 24px;
  border-radius: 1px;
  background: var(--faint);
  margin: 0 3px;
}

#urlInput {
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: #f4f4f6;
  border: 2px solid transparent;
  border-radius: 11px;
  padding: 10px 13px;
  width: 190px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
  transition: border-color 0.12s ease, background 0.12s ease;
}
#urlInput::placeholder { color: var(--muted); }
#urlInput:focus { background: #fff; border-color: var(--ink); }

/* ---------- 一時保存パネル ---------- */
#drafts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(170px + env(safe-area-inset-bottom));
  width: min(420px, calc(100vw - 16px));
  max-height: 44vh;
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: opacity 0.15s ease, transform 0.15s var(--bounce);
}
#drafts.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(8px) scale(0.98);
}

#draftsHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 2px solid var(--faint);
  font-size: 14px;
  font-weight: 800;
}
#stashBtn { font-size: 12px; padding: 7px 11px; border-radius: 10px; }

#draftsList { overflow-y: auto; }

#draftsEmpty {
  padding: 22px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}

.draft {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 14px;
}
.draft + .draft { border-top: 2px solid var(--faint); }
.draft canvas {
  width: 88px;
  height: 50px;
  border: 2px solid var(--faint);
  border-radius: 8px;
  background: #fff;
  image-rendering: pixelated;
  flex-shrink: 0;
}
.draft .meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.draft .meta b {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.draft .meta span { font-size: 11px; font-weight: 700; color: var(--muted); }
.draft .load { font-size: 12px; padding: 7px 12px; border-radius: 10px; }
.draft .del {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.draft .del:hover { color: var(--accent); background: transparent; }
.draft .del:active { transform: scale(0.9); }

/* ---------- リンク先の吹き出し(サイト情報の事前表示) ---------- */
#chip {
  position: fixed;
  z-index: 30;
  background: var(--ink);
  color: #fff;
  padding: 10px 13px 9px;
  border-radius: 13px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  width: max-content;
  max-width: 270px;
  transition: opacity 0.12s ease, transform 0.12s var(--bounce);
}
#chip::after { /* 吹き出しのしっぽ */
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: var(--ink);
  border-radius: 2px;
  transform: translateX(-50%) rotate(45deg);
}
#chip.hidden { opacity: 0; transform: translateY(5px) scale(0.96); }
#chipTop {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
}
#chipIcon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: #2c2c31;
  flex-shrink: 0;
}
#chipHost {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chipUrl {
  font-size: 10.5px;
  font-weight: 500;
  color: #a3a3ab;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chipHint {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 800;
  color: #d8d8de;
  margin-top: 6px;
}
#chip .arr { color: var(--accent); }

/* ---------- トースト ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(180px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--card);
  color: var(--ink);
  border-radius: 13px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  padding: 11px 18px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  transition: opacity 0.18s ease, transform 0.18s var(--bounce);
  pointer-events: none;
}
#toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px) scale(0.97);
}

/* ---------- スプラッシュ ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--ws);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  transition: opacity 0.3s ease;
}
#splash.hidden { opacity: 0; pointer-events: none; }
#splash .mark {
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#splash .mark i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
}
#splash .dots { display: flex; gap: 7px; }
#splash .dots i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  animation: hop 0.9s var(--bounce) infinite;
}
#splash .dots i:nth-child(1) { background: #ff3d20; }
#splash .dots i:nth-child(2) { background: #ffd635; animation-delay: 0.12s; }
#splash .dots i:nth-child(3) { background: #3690ea; animation-delay: 0.24s; }
@keyframes hop { 30% { transform: translateY(-7px); } 60% { transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 620px) {
  #urlInput { width: 140px; }
  .primary.big { padding: 13px 30px; }
  #brand { font-size: 15px; }
  #toolbar { padding: 10px; }
  .tool { width: 37px; height: 37px; }
}
