/* 水族館の解説パネル: 左に水槽（プレビュー）と名札、右にパーツ棚、下にガチャのトレー */
:root {
  --bg: #e7f2f5;
  --surface: #ffffff;
  --surface-2: #f2f8fa;
  --ink: #1e2c43;
  --muted: #5b6d84;
  --line: #d0dfe7;
  --accent: #d63864;
  --accent-soft: #ffe4ec;
  --on-accent: #ffffff;
  --sea: #2c6fa3;
  --check: #e3edf2;
  --shadow: 0 1px 0 rgba(30, 44, 67, 0.04), 0 10px 30px -18px rgba(30, 44, 67, 0.35);

  --font-display: "Mochiy Pop One", "Hiragino Maru Gothic ProN", "Arial Rounded MT Bold", system-ui, sans-serif;
  --font-body: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --font-data: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;

  --radius: 22px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1a29;
    --surface: #152437;
    --surface-2: #1b2d44;
    --ink: #e4edf6;
    --muted: #9cb0c5;
    --line: #2a3f59;
    --accent: #ff88a4;
    --accent-soft: #3a2233;
    --on-accent: #26101b;
    --sea: #82c3f0;
    --check: #1f334b;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 14px 34px -20px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1a29;
  --surface: #152437;
  --surface-2: #1b2d44;
  --ink: #e4edf6;
  --muted: #9cb0c5;
  --line: #2a3f59;
  --accent: #ff88a4;
  --accent-soft: #3a2233;
  --on-accent: #26101b;
  --sea: #82c3f0;
  --check: #1f334b;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 14px 34px -20px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

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

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  font-weight: 500;
  line-height: 1.7;
}

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

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

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding-inline: var(--gutter);
  padding-block: 20px 40px;
  display: grid;
  gap: 28px;
}

/* ---------------------------------------------------------------- 見出し */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-weight: 400;
}

.brand-mark {
  display: block;
  width: 64px;
  height: 46px;
}

.brand-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-name {
  font-family: var(--font-display);
  font-size: var(--step-3);
  line-height: 1.1;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: var(--step--1);
  line-height: 1.6;
  max-width: 34em;
}

/* ---------------------------------------------------------------- 作業台 */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  gap: 28px;
  align-items: start;
}

.stage-col {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  display: grid;
  gap: 14px;
  min-width: 0;
}

.stage {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background-color: var(--surface);
  background-image: conic-gradient(var(--check) 25%, transparent 0 50%, var(--check) 0 75%, transparent 0);
  background-size: 26px 26px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.stage-art {
  aspect-ratio: 1;
  max-width: 100%;
  display: grid;
  place-items: center;
  animation: bob 4.2s ease-in-out infinite;
}

.stage-art svg {
  display: block;
  width: 100%;
  height: auto;
}

.stage-art.is-pop {
  animation: pop 0.42s cubic-bezier(0.3, 1.6, 0.5, 1), bob 4.2s ease-in-out 0.42s infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.2%); }
}

@keyframes pop {
  0% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* 図鑑の名札（水族館の解説プレート） */
.plate {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 14px 22px 14px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
}

.plate::before,
.plate::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.7;
}

.plate::before { left: 9px; }
.plate::after { right: 9px; }

.plate-no {
  font-family: var(--font-data);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.plate-name {
  text-wrap: balance;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-1);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.plate-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 16px;
  font-size: var(--step--1);
  opacity: 0.8;
}

.plate-meta i {
  font-family: Georgia, "Times New Roman", serif;
}

.quick {
  display: flex;
  gap: 10px;
}

.quick .btn-dice {
  flex: 1;
}

.export {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.export-size {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.unit {
  color: var(--muted);
  font-size: var(--step--1);
}

.export-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ---------------------------------------------------------------- ボタン */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  font-size: var(--step-0);
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: var(--muted);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.btn-primary:hover {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--ink) 88%, var(--sea));
}

.btn-dice {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-size: var(--step-1);
  min-height: 52px;
}

.btn-dice:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 90%, var(--ink));
}

.btn-dice svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.btn-dice svg circle {
  fill: currentColor;
  stroke: none;
}

.btn-dice.is-rolling svg {
  animation: roll 0.5s ease;
}

@keyframes roll {
  to { transform: rotate(360deg); }
}

.btn-quiet {
  background: transparent;
}

/* ---------------------------------------------------------------- パーツ棚 */

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 8px 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1 0 auto;
  padding: 10px 16px 12px;
  border: 0;
  border-radius: 14px 14px 0 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  position: relative;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--surface);
}

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 18px;
  height: 4px;
  margin-left: -9px;
  border-radius: 4px;
  background: var(--accent);
}

.tabpanel {
  display: grid;
  gap: 22px;
  padding: 20px 20px 24px;
}

.field {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field-label {
  padding: 0;
  font-size: var(--step--1);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.field-value {
  font-family: var(--font-data);
  font-size: var(--step--1);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* 見本つきの選択肢 */
.chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.chips.is-square {
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
}

.chip {
  position: relative;
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 6px 6px 7px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.12s ease;
}

.chip:hover {
  border-color: var(--muted);
}

.chip:active {
  transform: scale(0.97);
}

.chip input,
.swatch input[type="radio"],
.seg input,
.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.chip-art {
  display: block;
  width: 100%;
  aspect-ratio: 150 / 104;
  border-radius: 9px;
  background: var(--surface-2);
  overflow: hidden;
}

.is-square .chip-art {
  aspect-ratio: 1;
}

.chip-art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chip-label {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.chip:has(input:focus-visible) {
  outline: 3px solid var(--sea);
  outline-offset: 2px;
}

/* 色えらび */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}

.swatch-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--ink) 18%, transparent);
  transition: transform 0.12s ease;
}

.swatch:hover .swatch-dot {
  transform: scale(1.08);
}

.swatch:has(input:checked),
.swatch.is-on {
  box-shadow: 0 0 0 2.5px var(--accent);
}

.swatch:has(input:focus-visible) {
  outline: 3px solid var(--sea);
  outline-offset: 3px;
}

.swatch-none .swatch-dot {
  background:
    linear-gradient(135deg, transparent calc(50% - 1.5px), var(--accent) calc(50% - 1.5px) calc(50% + 1.5px), transparent calc(50% + 1.5px)),
    var(--surface);
}

.swatch-custom .swatch-dot {
  background: conic-gradient(#ff8fa6, #ffd25e, #8ddbc3, #8ec8ec, #b8a7ec, #ff8fa6);
}

.swatch-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.swatch-custom .swatch-dot.has-color {
  background: var(--picked);
  box-shadow: inset 0 0 0 3px var(--surface);
  border-style: dashed;
}

/* スライダー */
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 8px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), var(--line) var(--fill, 50%));
}

.range::-moz-range-track {
  height: 8px;
  border-radius: 8px;
  background: var(--line);
}

.range::-moz-range-progress {
  height: 8px;
  border-radius: 8px;
  background: var(--accent);
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
}

.range:focus-visible {
  outline: none;
}

.range:focus-visible::-webkit-slider-thumb {
  outline: 3px solid var(--sea);
  outline-offset: 2px;
}

.range-ends {
  display: flex;
  justify-content: space-between;
  margin-top: -6px;
  color: var(--muted);
  font-size: 0.75rem;
}

/* 二択・数択 */
.seg {
  justify-self: start;
  display: inline-flex;
  flex-wrap: wrap;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.seg label {
  position: relative;
  cursor: pointer;
}

.seg span {
  display: block;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: var(--step--1);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.seg input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

.seg input:focus-visible + span {
  outline: 3px solid var(--sea);
  outline-offset: 1px;
}

.toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.toggle-text {
  display: grid;
}

.toggle-text small {
  color: var(--muted);
  font-size: var(--step--1);
}

.toggle-track {
  flex: none;
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  transition: background-color 0.15s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s ease;
}

.toggle input:checked + .toggle-text + .toggle-track {
  background: var(--accent);
}

.toggle input:checked + .toggle-text + .toggle-track::after {
  transform: translateX(22px);
}

.toggle input:focus-visible + .toggle-text + .toggle-track {
  outline: 3px solid var(--sea);
  outline-offset: 2px;
}

.hint {
  margin: -12px 0 0;
  color: var(--muted);
  font-size: var(--step--1);
}

/* ---------------------------------------------------------------- ガチャ */

.gacha {
  display: grid;
  gap: 16px;
}

.gacha-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px 20px;
}

.gacha-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-2);
  line-height: 1.3;
  text-wrap: balance;
}

.gacha-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: var(--step--1);
}

.gacha-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.capsule {
  display: grid;
  gap: 4px;
  padding: 8px 8px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
  animation: drop 0.45s cubic-bezier(0.3, 1.5, 0.5, 1) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.capsule:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.capsule-art {
  display: block;
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
}

.capsule-art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.capsule-name {
  text-wrap: balance;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

@keyframes drop {
  from { transform: translateY(-10px) scale(0.96); }
  to { transform: none; }
}

/* ---------------------------------------------------------------- ほか */

.foot {
  color: var(--muted);
  font-size: var(--step--1);
  border-top: 1px dashed var(--line);
  padding-top: 16px;
}

.foot p {
  margin: 0;
  max-width: 60em;
}

.foot b {
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  font-size: var(--step--1);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------- せまい画面 */

@media (max-width: 860px) {
  .workbench {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  /* プレビューをパーツ棚の上に貼りつけたまま編集できるよう、列の箱をほどく */
  .stage-col {
    display: contents;
  }

  /* 端から端までの帯にして、下をスクロールしていく棚が横から透けないようにする */
  .stage {
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 2;
    margin-inline: calc(-1 * var(--gutter));
    border-width: 0 0 1px;
    border-radius: 0 0 var(--radius) var(--radius);
    order: 1;
  }

  .stage-art {
    width: min(100%, 36vh);
    margin-inline: auto;
  }

  .tab {
    padding: 10px 6px 12px;
    font-size: var(--step--1);
  }

  .plate { order: 2; }
  .quick { order: 3; }
  .panel { order: 4; }
  .export { order: 5; }

  .gacha-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand-name {
    font-size: var(--step-2);
  }
}

@media (min-width: 861px) and (max-width: 1040px) {
  .gacha-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

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