/* ==========================================================================
   ドット絵コード — 見た目（配色・配置・部品）
   動きは motion.css。スマホ（幅 375 前後）を先に組み、幅 600・960 で広げる。
   色: 月電の緑 (40,117,76)、ミント (221,245,243)・(168,225,222)、クリーム。
   ========================================================================== */

:root {
  --green: #28754c;
  --green-deep: #1d5a39;
  --green-soft: #3d9466;
  --green-tint: #e4f3ea;
  --mint: #ddf5f3;
  --mint-2: #a8e1de;
  --mint-3: #74c6c0;
  --cream: #fff6db;
  --cream-hi: #fffaf0;
  --butter: #ffeaa6;
  --peach: #ffe4d6;
  --pink: #f7a4a0;
  --sun: #efad08;
  --orange: #e28c42;
  --ink: #213a2d;
  --ink-2: #4a6355;
  --ink-3: #5f7569;
  --danger: #b8402f;
  --danger-tint: #fde9e4;
  --warn-ink: #7a5300;
  --surface: #ffffff;
  --surface-2: #f5fbf9;
  --line: rgba(40, 117, 76, 0.14);
  --line-2: rgba(40, 117, 76, 0.26);
  --shadow-s: 0 1px 2px rgba(29, 90, 57, 0.07), 0 6px 16px -10px rgba(29, 90, 57, 0.32);
  --shadow-m: 0 2px 4px rgba(29, 90, 57, 0.05), 0 18px 36px -20px rgba(29, 90, 57, 0.42);
  --shadow-l: 0 4px 10px rgba(29, 90, 57, 0.06), 0 30px 60px -30px rgba(29, 90, 57, 0.55);
  --r-xl: 30px;
  --r-l: 24px;
  --r-m: 18px;
  --r-s: 12px;
  --r-pill: 999px;
  --font-body: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-dot: "DotGothic16", "M PLUS Rounded 1c", "Hiragino Sans", "Meiryo", monospace;
  --gutter: 16px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.7;
  color: var(--ink);
  background-color: var(--cream-hi);
  background-image:
    radial-gradient(ellipse 70% 40% at 0% 0%, rgba(168, 225, 222, 0.55), transparent 70%),
    radial-gradient(ellipse 60% 36% at 100% 4%, rgba(255, 234, 166, 0.6), transparent 70%),
    radial-gradient(rgba(40, 117, 76, 0.1) 1.2px, transparent 1.7px);
  background-size: 100% 900px, 100% 900px, 20px 20px;
  background-repeat: no-repeat, no-repeat, repeat;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

img,
svg,
canvas,
video {
  display: block;
}

a {
  color: var(--green-deep);
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.nowrap {
  display: inline-block;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wrap {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
}

/* --------------------------------------------------------------------------
   ヘッダー
   -------------------------------------------------------------------------- */
.site-header {
  position: relative;
  padding-block: 22px 6px;
  overflow: hidden;
}

.header-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  flex: none;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 10px rgba(29, 90, 57, 0.22));
}

.brand-text {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--font-dot);
  font-weight: 400;
  font-size: clamp(27px, 7.4vw, 42px);
  line-height: 1.15;
  letter-spacing: 0.04em;
  color: var(--green-deep);
}

.brand-lead {
  margin: 4px 0 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-2);
}

.brand-badge {
  align-self: flex-start;
  margin-left: auto;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--butter);
  color: var(--warn-ink);
  font-family: var(--font-dot);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(122, 83, 0, 0.18);
}

.header-dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.header-dots i {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--mint-2);
  opacity: 0.7;
}

.header-dots i:nth-child(1) { top: 16%; right: 18%; }
.header-dots i:nth-child(2) { top: 62%; right: 8%; width: 7px; height: 7px; background: var(--sun); }
.header-dots i:nth-child(3) { top: 30%; right: 34%; width: 6px; height: 6px; background: var(--green-soft); opacity: 0.45; }
.header-dots i:nth-child(4) { top: 74%; right: 28%; width: 8px; height: 8px; background: var(--pink); }
.header-dots i:nth-child(5) { top: 12%; right: 4%; width: 6px; height: 6px; background: var(--mint-3); }
.header-dots i:nth-child(6) { top: 46%; right: 46%; width: 5px; height: 5px; background: var(--orange); opacity: 0.5; }
.header-dots i:nth-child(7) { top: 84%; right: 52%; width: 7px; height: 7px; background: var(--mint-2); }

/* --------------------------------------------------------------------------
   タブ
   -------------------------------------------------------------------------- */
.main {
  flex: 1 0 auto;
  overflow-x: clip;
  padding-bottom: 12px;
}

.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 440px;
  margin: 16px 0 20px;
  padding: 6px;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-s), inset 0 0 0 1px var(--line);
}

.tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 10px 12px 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-3);
  font-size: 16.5px;
  font-weight: 800;
  cursor: pointer;
  transition: color 0.3s ease;
  touch-action: manipulation;
}

.tab[aria-selected="true"] {
  color: var(--green-deep);
}

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

.tab-indicator {
  position: absolute;
  z-index: 0;
  top: 6px;
  bottom: 6px;
  left: 0;
  width: var(--w, calc(50% - 6px));
  transform: translateX(var(--x, 6px));
  border-radius: var(--r-pill);
  background: var(--mint);
  box-shadow: inset 0 0 0 1px rgba(40, 117, 76, 0.1);
}

.tab-indicator::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 44px;
  height: 4px;
  margin-left: -22px;
  border-radius: 4px;
  background: var(--green);
}

/* --------------------------------------------------------------------------
   見出し・共通
   -------------------------------------------------------------------------- */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 12px;
  margin-bottom: 12px;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.4;
  color: var(--ink);
}

.section-note {
  margin: 0;
  font-size: 13px;
  color: var(--ink-3);
}

.step-no {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 9px;
  background: var(--green);
  color: #fff;
  font-family: var(--font-dot);
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  box-shadow: 0 3px 0 var(--green-deep);
}

.step-no--light {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.55);
}

/* --------------------------------------------------------------------------
   ボタン
   -------------------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--green-deep);
  --btn-edge: var(--line-2);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 11px 20px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--btn-edge), 0 12px 20px -14px rgba(29, 90, 57, 0.55);
  transition: transform 0.35s var(--spring), box-shadow 0.25s ease, background-color 0.3s ease, color 0.3s ease, opacity 0.2s ease;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--btn-edge), 0 16px 24px -14px rgba(29, 90, 57, 0.55);
}

.btn:active {
  transform: translateY(3px) scale(0.97);
  box-shadow: 0 1px 0 var(--btn-edge), 0 4px 10px -8px rgba(29, 90, 57, 0.5);
  transition-duration: 0.06s;
}

.btn:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}

.btn-primary {
  --btn-bg: var(--green);
  --btn-fg: #fff;
  --btn-edge: var(--green-deep);
}

.btn-primary:focus-visible {
  outline-color: var(--sun);
}

.btn-secondary {
  --btn-bg: var(--mint);
  --btn-fg: var(--green-deep);
  --btn-edge: var(--mint-3);
}

.btn-ghost {
  --btn-bg: var(--surface);
  --btn-fg: var(--green-deep);
  --btn-edge: var(--line-2);
  box-shadow: inset 0 0 0 2px var(--line-2), 0 4px 0 var(--line);
}

.btn-ghost:hover {
  box-shadow: inset 0 0 0 2px var(--green-soft), 0 6px 0 var(--line);
}

.btn-xl {
  min-height: 58px;
  padding: 14px 26px;
  font-size: 18px;
}

.btn-block {
  width: 100%;
}

.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn[aria-disabled="true"]:hover {
  transform: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}

.btn .icon {
  width: 1.3em;
  height: 1.3em;
}

/* --------------------------------------------------------------------------
   生成タブ
   -------------------------------------------------------------------------- */
.make-layout {
  display: grid;
  gap: 22px;
}

.animal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.animal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 9px 7px 11px;
  border-radius: var(--r-m);
  background: var(--surface);
  box-shadow: var(--shadow-s), inset 0 0 0 1px var(--line);
  text-align: center;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.4s var(--spring), box-shadow 0.3s ease, background-color 0.3s ease;
  touch-action: manipulation;
}

.animal-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-m), inset 0 0 0 1px var(--line-2);
}

.animal-card:active {
  transform: scale(0.95);
  transition-duration: 0.08s;
}

.animal-card.is-focus {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}

.animal-art {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(40, 117, 76, 0.07);
  transition: background-color 0.35s ease;
}

.animal-art canvas {
  width: 80%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 6px;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.animal-name {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.animal-tagline {
  display: block;
  max-width: 100%;
  text-wrap: balance;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.animal-check {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  box-shadow: 0 3px 8px rgba(29, 90, 57, 0.35);
  transform: scale(0);
  transition: transform 0.3s var(--spring);
}

.animal-check .icon {
  width: 16px;
  height: 16px;
  stroke-width: 3;
}

.animal-card.is-selected {
  background: #fbfffd;
  box-shadow: 0 0 0 3px var(--green), 0 14px 28px -14px rgba(40, 117, 76, 0.6);
  transform: translateY(-2px);
}

.animal-card.is-selected .animal-art {
  background: var(--mint);
}

.animal-card.is-selected .animal-check {
  transform: scale(1);
}

.spark {
  position: absolute;
  top: 38%;
  left: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 1.5px;
  background: var(--c, var(--mint-3));
  opacity: 0;
  pointer-events: none;
}

.animal-card.is-skeleton {
  pointer-events: none;
  box-shadow: inset 0 0 0 1px var(--line);
}

.animal-card.is-skeleton .animal-art,
.skel-line {
  background: linear-gradient(90deg, var(--mint) 25%, #f3fcfb 40%, var(--mint) 60%);
  background-size: 300% 100%;
}

.skel-line {
  display: block;
  width: 64%;
  height: 12px;
  margin-top: 8px;
  border-radius: 6px;
}

.skel-line.short {
  width: 82%;
  height: 9px;
  margin-top: 6px;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 28px 18px;
  border: 2px dashed var(--line-2);
  border-radius: var(--r-l);
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
}

.empty-art {
  display: grid;
  grid-template-columns: repeat(5, 12px);
  gap: 3px;
}

.empty-art i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--mint-2);
}

.empty-art i:nth-child(odd) {
  background: var(--mint);
}

.empty-title {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 800;
}

.empty-text {
  margin: 0;
  max-width: 34em;
  text-wrap: balance;
  font-size: 14px;
  color: var(--ink-2);
}

.grid-note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

/* 作業台（プレビュー・URL・生成） */
.bench {
  display: grid;
  gap: 16px;
  padding: 16px;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-m), inset 0 0 0 1px var(--line);
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: var(--r-l);
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0) 62%),
    radial-gradient(rgba(40, 117, 76, 0.12) 1.1px, transparent 1.6px) 0 0 / 14px 14px,
    var(--mint);
  overflow: hidden;
  isolation: isolate;
}

.stage-canvas {
  width: min(100%, 320px);
  height: auto;
  aspect-ratio: 1;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  filter: drop-shadow(0 14px 16px rgba(29, 90, 57, 0.24));
  transition: opacity 0.4s ease;
}

.stage[data-mode="empty"] .stage-canvas {
  opacity: 0.55;
  filter: none;
}

.stage-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-s);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.stage:not([data-mode="empty"]) .stage-hint {
  display: none;
}

.stage-shine {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
  border-radius: inherit;
}

.stage-shine::before {
  content: "";
  position: absolute;
  top: -30%;
  bottom: -30%;
  left: 0;
  width: 26%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
  transform: translateX(-160%) rotate(18deg);
  opacity: 0;
}

.stage-caption {
  min-height: 1.5em;
  margin-top: -4px;
  text-align: center;
}

.stage-caption:empty {
  display: none;
}

.caption-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
}

.caption-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.caption-sub strong {
  color: var(--ink);
  font-weight: 700;
}

/* URL 入力 */
.url-field {
  display: grid;
  gap: 10px;
}

.input-wrap {
  position: relative;
}

.url-input {
  width: 100%;
  min-height: 54px;
  padding: 12px 48px 12px 16px;
  border: 2px solid var(--line-2);
  border-radius: var(--r-m);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 16px;
  font-weight: 500;
  transition: border-color 0.2s ease, box-shadow 0.25s ease, background-color 0.2s ease;
}

.url-input::placeholder {
  color: #93a69c;
}

.url-input:focus {
  outline: none;
  border-color: var(--green);
  background: #fff;
  box-shadow: 0 0 0 5px rgba(168, 225, 222, 0.65);
}

.url-input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 5px rgba(184, 64, 47, 0.12);
}

.input-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-top: -18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--mint);
  color: var(--green-deep);
  cursor: pointer;
  transition: transform 0.3s var(--spring), background-color 0.2s;
}

.input-clear:hover {
  background: var(--mint-2);
}

.input-clear:active {
  transform: scale(0.88);
}

.input-clear:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.input-clear .icon {
  width: 16px;
  height: 16px;
  stroke-width: 2.6;
}

.byte-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.byte-meter {
  display: grid;
  grid-template-columns: repeat(var(--cap, 42), minmax(0, 1fr));
  gap: 2px;
  min-width: 0;
}

.byte-meter i {
  display: block;
  aspect-ratio: 1;
  min-height: 4px;
  border-radius: 2px;
  background: #cfeeea;
  box-shadow: inset 0 0 0 1px rgba(40, 117, 76, 0.12);
  transform: scale(0.8);
  transition: transform 0.35s var(--spring), background-color 0.25s ease;
}

.byte-meter i.on {
  background: var(--mint-3);
  transform: scale(1);
}

.byte-meter.is-near i.on {
  background: var(--sun);
}

.byte-meter.is-over i {
  background: var(--danger);
  transform: scale(1);
}

.byte-count {
  margin: 0;
  font-family: var(--font-dot);
  font-size: 15px;
  line-height: 1.3;
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.byte-count.is-over {
  color: var(--danger);
}

.field-msg {
  min-height: 1.5em;
  margin: -2px 0 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-3);
}

.field-msg.is-error {
  color: var(--danger);
  font-weight: 700;
}

.field-msg.is-ok {
  color: var(--green-deep);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.result-actions .btn {
  flex: 1 1 140px;
}

#try-btn {
  flex-basis: 100%;
}

#save-btn .icon-done {
  display: none;
}

#save-btn.is-done {
  --btn-bg: var(--green);
  --btn-fg: #fff;
  --btn-edge: var(--green-deep);
}

#save-btn.is-done .icon-main {
  display: none;
}

#save-btn.is-done .icon-done {
  display: block;
  stroke-dasharray: 24;
  stroke-dashoffset: 0;
  stroke-width: 3;
}

/* --------------------------------------------------------------------------
   読み取りタブ
   -------------------------------------------------------------------------- */
.read-layout {
  display: grid;
  gap: 18px;
}

.viewer {
  position: relative;
  aspect-ratio: 3 / 4;
  max-height: 74vh;
  max-height: 74svh;
  min-height: 300px;
  margin-inline: calc(var(--gutter) * -1);
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 35%, rgba(61, 148, 102, 0.55), rgba(19, 38, 28, 0) 62%),
    radial-gradient(rgba(168, 225, 222, 0.16) 1.3px, transparent 1.8px) 0 0 / 18px 18px,
    #13261c;
  color: #fff;
  container-type: size;
  touch-action: manipulation;
}

.viewer-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.viewer-still {
  background: #13261c;
}

.viewer-still.is-contain {
  object-fit: contain;
  background:
    radial-gradient(rgba(168, 225, 222, 0.14) 1.3px, transparent 1.8px) 0 0 / 18px 18px,
    #1a3326;
}

.viewer[data-state="live"] .viewer-video,
.viewer[data-state="starting"] .viewer-video,
.viewer[data-state="still"] .viewer-still {
  display: block;
}

.scan-frame {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 64%;
  width: min(64cqw, 64cqh);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: none;
  pointer-events: none;
}

.viewer[data-state="live"] .scan-frame,
.viewer[data-state="starting"] .scan-frame {
  display: block;
}

.scan-box {
  position: absolute;
  inset: 0;
  border-radius: 26px;
  box-shadow: 0 0 0 200vmax rgba(9, 22, 15, 0.34);
}

.corner {
  position: absolute;
  width: 24%;
  aspect-ratio: 1;
  border: 5px solid var(--mint-2);
  filter: drop-shadow(0 0 6px rgba(168, 225, 222, 0.85));
}

.corner.tl { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 26px; }
.corner.tr { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 26px; }
.corner.br { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 26px; }
.corner.bl { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 26px; }

.scan-line {
  position: absolute;
  inset: 4% 5%;
  border-radius: 20px;
  overflow: hidden;
}

.scan-line::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 18%;
  background: linear-gradient(180deg, rgba(168, 225, 222, 0) 0%, rgba(168, 225, 222, 0.32) 82%, rgba(255, 255, 255, 0.95) 97%, rgba(168, 225, 222, 0) 100%);
}

.viewer[data-state="starting"] .scan-line {
  display: none;
}

.busy-sweep {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  overflow: hidden;
}

.busy-sweep::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 22%;
  background: linear-gradient(180deg, rgba(168, 225, 222, 0) 0%, rgba(168, 225, 222, 0.28) 85%, rgba(255, 255, 255, 0.9) 98%, rgba(168, 225, 222, 0) 100%);
}

.viewer.is-busy .busy-sweep {
  display: block;
}

.quad-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 0 7px rgba(168, 225, 222, 0.95));
}

.quad {
  fill: rgba(168, 225, 222, 0.14);
  stroke: var(--mint-2);
  stroke-width: 4;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.quad-dot {
  fill: #fff;
  stroke: var(--green);
  stroke-width: 3;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.viewer.is-found .quad,
.viewer.is-found .quad-dot {
  opacity: 1;
}

.viewer.is-near .quad-layer {
  filter: drop-shadow(0 0 6px rgba(239, 173, 8, 0.85));
}

.viewer.is-near .quad {
  fill: rgba(239, 173, 8, 0.1);
  stroke: var(--sun);
  stroke-dasharray: 12 9;
}

.viewer.is-near .quad-dot {
  stroke: var(--sun);
}

.viewer.is-locked .quad-layer {
  filter: drop-shadow(0 0 10px rgba(168, 225, 222, 1)) drop-shadow(0 0 3px rgba(255, 255, 255, 0.9));
}

.viewer.is-locked .quad {
  fill: none;
  stroke: #e9fffb;
  stroke-width: 6;
  stroke-dasharray: none;
}

.viewer.is-drop {
  box-shadow: inset 0 0 0 4px var(--mint-2);
}

.viewer-idle {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 16px;
  padding: 24px 20px 56px;
  text-align: center;
}

.viewer:not([data-state="idle"]) .viewer-idle {
  display: none;
}

.idle-art {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  gap: 5px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 2px rgba(168, 225, 222, 0.35);
}

.idle-art i {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--mint-2);
}

.idle-art i:nth-child(2n) {
  background: var(--mint);
}

.idle-art i:nth-child(5) {
  background: var(--sun);
}

.idle-note {
  margin: 0;
  max-width: 22em;
  text-wrap: balance;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.86);
}

.viewer-tools {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: calc(100% - 24px);
}

.viewer[data-state="idle"] .viewer-tools {
  display: none;
}

.viewer:not([data-state="live"]) #switch-btn,
.viewer:not([data-state="live"]):not([data-state="starting"]) #stop-btn,
.viewer:not([data-state="still"]) #recam-btn,
.viewer:not([data-state="still"]) #clear-btn {
  display: none;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.92);
  color: var(--green-deep);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
  transition: transform 0.35s var(--spring), background-color 0.2s;
  touch-action: manipulation;
}

.chip-btn:hover {
  background: #fff;
  transform: translateY(-1px);
}

.chip-btn:active {
  transform: scale(0.92);
  transition-duration: 0.06s;
}

.chip-btn:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 2px;
}

.chip-btn .icon {
  width: 18px;
  height: 18px;
}

.viewer-status {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 3;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  background: rgba(9, 22, 15, 0.74);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: background-color 0.3s ease;
}

.viewer-status:empty {
  padding: 0;
  opacity: 0;
}

.viewer-status[data-tone="warn"] {
  background: rgba(122, 83, 0, 0.88);
}

.viewer-status[data-tone="ok"] {
  background: rgba(29, 90, 57, 0.92);
}

.viewer-status[data-tone="error"] {
  background: rgba(150, 44, 30, 0.9);
}

.read-side {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

.file-card {
  display: grid;
  gap: 8px;
}

.file-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-3);
}

@media (hover: none) and (pointer: coarse) {
  .pc-only {
    display: none;
  }
}

/* お試し用のコード（月電ソフトウェアのホームページ入りの見本） */
.sample-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px 14px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: linear-gradient(160deg, var(--cream-hi), var(--surface-2));
  box-shadow: var(--shadow-s);
}

.sample-kicker {
  grid-column: 1 / -1;
  margin: 0;
  font-family: var(--font-dot);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--green);
}

.sample-kicker span {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--green-tint);
}

.sample-img {
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
  transition: transform 0.35s var(--spring);
}

.sample-card:hover .sample-img {
  transform: translateY(-3px) rotate(-2deg) scale(1.03);
}

.sample-body {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.sample-title {
  margin: 0;
  font-weight: 800;
  color: var(--ink);
}

.sample-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-3);
}

.sample-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sample-actions .btn {
  text-decoration: none;
}

@media (max-width: 380px) {
  .sample-card {
    grid-template-columns: 1fr;
    justify-items: start;
  }
}

/* 案内（カメラが使えないとき） */
.guide {
  padding: 18px;
  border-radius: var(--r-l);
  background: var(--surface);
  box-shadow: var(--shadow-m), inset 0 0 0 2px rgba(239, 173, 8, 0.45);
}

.guide-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.guide-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 13px;
  background: var(--butter);
  color: var(--warn-ink);
}

.guide-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.45;
}

.guide-list {
  margin: 10px 0 0;
  padding-left: 1.2em;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
}

.guide-list li + li {
  margin-top: 4px;
}

.guide-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.guide-actions .btn {
  flex: 1 1 150px;
  min-height: 46px;
  font-size: 15px;
}

/* 結果 */
.result {
  position: relative;
  padding: 20px 18px 16px;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-l), inset 0 0 0 1px var(--line);
  overflow: hidden;
  outline: none;
}

.result::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, var(--mint-2) 0 12px, var(--mint) 12px 24px);
}

.result--external::before {
  background: repeating-linear-gradient(90deg, var(--sun) 0 12px, var(--butter) 12px 24px);
}

.result-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 15px;
  background: var(--mint);
  color: var(--green-deep);
}

.result-icon .icon {
  width: 24px;
  height: 24px;
}

.result--external .result-icon {
  background: var(--butter);
  color: var(--warn-ink);
}

.result-title {
  margin: 0;
  font-size: 18.5px;
  font-weight: 800;
  line-height: 1.35;
}

.result-sub {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-3);
}

.result-domain {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: var(--r-m);
  background: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(239, 173, 8, 0.35);
}

.result-domain-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--warn-ink);
}

.result-domain strong {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.35;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.result-url {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--r-s);
  background: var(--surface-2);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink-2);
  overflow-wrap: anywhere;
  word-break: break-all;
}

.result-url .url-host {
  padding: 0 3px;
  border-radius: 4px;
  background: var(--mint);
  color: var(--ink);
  font-weight: 800;
}

.result--external .result-url .url-host {
  background: var(--butter);
}

.result-text {
  margin: 14px 0 0;
  padding: 12px 14px;
  max-height: 40vh;
  overflow: auto;
  border-radius: var(--r-m);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.result-hex {
  font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
  font-size: 13px;
}

.opening {
  margin-top: 14px;
}

.opening-bar {
  height: 10px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--mint);
}

.opening-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green-soft), var(--green));
  transform: scaleX(0);
  transform-origin: left center;
}

.opening.is-cancelled .opening-bar {
  display: none;
}

.opening-text {
  margin: 8px 0 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--green-deep);
}

.opening.is-cancelled .opening-text {
  color: var(--ink-2);
  font-weight: 700;
}

.result-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.result-row .btn {
  flex: 1 1 140px;
}

.result-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-2);
  font-size: 13px;
  color: var(--ink-3);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--green-deep);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.3s var(--spring);
}

.link-btn:hover {
  background: var(--mint);
}

.link-btn:active {
  transform: scale(0.94);
}

.link-btn:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.link-btn .icon {
  width: 18px;
  height: 18px;
}

.tips {
  border-radius: var(--r-l);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 0 0 1px var(--line);
}

.tips summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.tips summary::-webkit-details-marker {
  display: none;
}

.tips summary::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--mint-3);
  transition: transform 0.3s var(--spring);
}

.tips[open] summary::before {
  transform: rotate(45deg);
  background: var(--green);
}

.tips summary:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: -3px;
  border-radius: var(--r-l);
}

.tips ul {
  margin: 0;
  padding: 0 18px 16px 2.2em;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
}

/* --------------------------------------------------------------------------
   トースト・花火・フッター
   -------------------------------------------------------------------------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 11px 18px 11px 14px;
  border-radius: var(--r-pill);
  background: rgba(33, 58, 45, 0.95);
  color: #fff;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.45;
  box-shadow: 0 14px 30px -12px rgba(0, 0, 0, 0.5);
}

.toast-dot {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 3px;
  background: var(--mint-2);
  box-shadow: 0 0 0 3px rgba(168, 225, 222, 0.25);
}

.toast--ok .toast-dot {
  background: #7fe0a8;
  box-shadow: 0 0 0 3px rgba(127, 224, 168, 0.25);
}

.toast--warn .toast-dot {
  background: var(--sun);
  box-shadow: 0 0 0 3px rgba(239, 173, 8, 0.28);
}

.toast--error .toast-dot {
  background: #ff8f7d;
  box-shadow: 0 0 0 3px rgba(255, 143, 125, 0.28);
}

.fx-canvas {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.site-footer {
  padding: 26px 16px max(34px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
}

.site-footer p {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--font-dot);
  letter-spacing: 0.05em;
}

.site-footer p::before,
.site-footer p::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--mint-2);
}

.site-footer p::after {
  background: var(--green);
}

.noscript {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  margin: 0;
  padding: 14px 18px;
  border-radius: var(--r-m);
  background: var(--danger);
  color: #fff;
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   広い画面
   -------------------------------------------------------------------------- */
@media (min-width: 560px) {
  .animal-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }

  .bench {
    padding: 20px;
  }
}

@media (min-width: 600px) {
  .viewer {
    aspect-ratio: 4 / 3;
    max-height: none;
    margin-inline: 0;
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-l);
  }

  .brand-mark {
    width: 60px;
    height: 60px;
  }

  .brand-lead {
    font-size: 14.5px;
  }
}

@media (min-width: 960px) {
  .site-header {
    padding-top: 30px;
  }

  .tabs {
    margin: 20px 0 26px;
  }

  .make-layout {
    grid-template-columns: minmax(0, 1.12fr) minmax(380px, 1fr);
    gap: 28px;
    align-items: start;
  }

  .make-bench {
    position: sticky;
    top: 16px;
  }

  .animal-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .animal-name {
    font-size: 16px;
  }

  .animal-tagline {
    font-size: 12.5px;
  }

  .stage-canvas {
    width: min(100%, 300px);
  }

  .read-layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr);
    gap: 28px;
    align-items: start;
  }
}

@media (min-width: 1140px) {
  .animal-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-height: 760px) and (min-width: 960px) {
  .stage {
    padding: 14px;
  }

  .stage-canvas {
    width: min(100%, 240px);
  }
}
