/* ==========================================================================
   KatakataLab Particle Lab / v3.0.0
   光の実験装置 - Stylesheet (Modern Museum & Atelier Aesthetic)
   ========================================================================== */

:root {
  --bg-deep: #030308;
  --panel-bg: rgba(8, 10, 18, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-soft: #cbd5e1;
  --text-muted: #64748b;

  /* 形態に応じて動的に切り替わるアクセント変数 */
  --accent-main: #38bdf8;
  --accent-sub: #818cf8;
  --accent-glow: rgba(56, 189, 248, 0.32);
  --accent-soft: rgba(56, 189, 248, 0.12);

  --shadow-strong: 0 24px 64px rgba(0, 0, 0, 0.75);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  background: var(--bg-deep);
}

body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 18% 14%, var(--accent-soft), transparent 36%),
    radial-gradient(circle at 82% 80%, rgba(129, 140, 248, 0.08), transparent 40%),
    #030308;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.6s ease;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

#webgl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
  background: #030308;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

#webgl:active {
  cursor: grabbing;
}

/* タップ時の2D波紋エフェクト */
.tap-ripple {
  --tap-x: -100px;
  --tap-y: -100px;
  position: fixed;
  top: 0;
  left: 0;
  width: 56px;
  height: 56px;
  margin-top: -28px;
  margin-left: -28px;
  border: 1.5px solid var(--accent-main);
  border-radius: 50%;
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 12px var(--accent-glow);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transform: translate3d(var(--tap-x), var(--tap-y), 0) scale(0.2);
  will-change: transform, opacity;
}

.tap-ripple.is-animating {
  animation: rippleExpand 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes rippleExpand {
  0% {
    opacity: 0.95;
    transform: translate3d(var(--tap-x), var(--tap-y), 0) scale(0.25);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--tap-x), var(--tap-y), 0) scale(2.6);
  }
}

/* カメラ撮影時のシャッターフラッシュ */
.shutter-flash {
  position: fixed;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  z-index: 99;
}

.shutter-flash.is-active {
  animation: shutterFlashAnim 0.35s cubic-bezier(0.1, 0.9, 0.2, 1);
}

@keyframes shutterFlashAnim {
  0% {
    opacity: 0.65;
  }
  100% {
    opacity: 0;
  }
}

.fallback {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at center, rgba(56, 189, 248, 0.12), transparent 34%),
    #030308;
  text-align: center;
}

.fallback.is-visible {
  display: grid;
}

.fallback-box {
  max-width: 520px;
  padding: 24px;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.page-shell {
  position: relative;
  z-index: 10;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
  padding: 24px 28px;
  pointer-events: none;
}

.brand,
.header-actions,
.hero-panel,
.control-panel,
.footer-copy,
.footer-link {
  pointer-events: auto;
}

.hero-panel,
.control-panel,
.site-footer {
  transition:
    opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0.35s;
}

/* 全画面没入モード */
body.is-hud-hidden .hero-panel,
body.is-hud-hidden .control-panel,
body.is-hud-hidden .site-footer {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
}

/* サイトヘッダー */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.brand {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.brand-logo {
  font-size: clamp(1.05rem, 3vw, 1.25rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  color: #ffffff;
  white-space: nowrap;
}

.brand-note {
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.art-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: var(--text-soft);
  background: rgba(12, 16, 26, 0.65);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease,
    box-shadow 0.2s ease;
}

.art-btn .art-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.art-btn:hover {
  border-color: var(--accent-main);
  color: #ffffff;
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.art-btn:focus-visible {
  outline: 2px solid var(--accent-main);
  outline-offset: 2px;
}

.art-btn[aria-pressed="true"] {
  border-color: var(--accent-main);
  color: #ffffff;
  background: var(--accent-soft);
  box-shadow: 0 0 16px var(--accent-glow);
}

.art-btn--capture:hover {
  border-color: #38bdf8;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.3);
}

/* ==========================================================================
   Unified Right Sidebar Layout (Left Canvas 100% Open)
   ========================================================================== */
.lab-layout {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  min-height: 0;
  width: 100%;
  pointer-events: none;
}

.control-panel {
  position: relative;
  pointer-events: auto;
  width: min(100%, 330px);
  padding: 18px 20px;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0) 55%),
    var(--panel-bg);
  box-shadow:
    var(--shadow-strong),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 120px);
  max-height: calc(100svh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.control-panel::-webkit-scrollbar {
  width: 4px;
}

.control-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}

.panel-section {
  display: flex;
  flex-direction: column;
}

.panel-section--header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  padding-bottom: 12px;
}

.panel-main-title {
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
  line-height: 1.2;
}

.panel-description {
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: 0.76rem;
  line-height: 1.6;
}

.lab-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.meta-card {
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.meta-label {
  display: block;
  margin-bottom: 1px;
  color: var(--text-muted);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
}

.meta-value {
  display: block;
  color: #f8fafc;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 7つの数理形態選択 */
.section-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.section-label-row .section-label {
  margin-bottom: 0;
}

.reset-link-btn {
  background: transparent;
  border: none;
  padding: 2px 6px;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.2s ease, background 0.2s ease;
}

.reset-link-btn:hover {
  color: var(--accent-main);
  background: rgba(255, 255, 255, 0.05);
}

.shape-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.shape-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 35px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.028);
  color: var(--text-soft);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease,
    box-shadow 0.2s ease;
  user-select: none;
}

.shape-button:nth-child(7) {
  grid-column: span 2;
}

.shape-name {
  white-space: nowrap;
}

.shape-key {
  font-size: 0.58rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease;
}

.shape-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent-main);
  background: var(--accent-soft);
  color: #ffffff;
}

.shape-button:focus-visible {
  outline: 2px solid var(--accent-main);
  outline-offset: 2px;
}

.shape-button.is-active {
  color: #ffffff;
  border-color: var(--accent-main);
  background: var(--accent-soft);
  box-shadow: 0 0 18px var(--accent-glow);
}

.shape-button.is-active .shape-key {
  background: var(--accent-main);
  color: #030308;
  font-weight: 700;
}

/* 波紋ボタン (8秒スロー波紋) */
.action-btn--wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--accent-main);
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.18) 0%, rgba(79, 172, 254, 0.14) 100%);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 0 20px var(--accent-glow);
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.action-btn--wave:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.28) 0%, rgba(79, 172, 254, 0.22) 100%);
  box-shadow: 0 0 28px var(--accent-glow);
}

.action-btn--wave:active {
  transform: translateY(1px);
}

.action-btn--wave:focus-visible {
  outline: 2px solid var(--accent-main);
  outline-offset: 2px;
}

/* パラメータ微調整 */
.panel-section--params {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding-top: 12px;
}

.param-group {
  margin-bottom: 11px;
}

.param-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
  color: var(--text-soft);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

.param-value {
  color: var(--accent-main);
  font-size: 0.7rem;
  font-weight: 600;
  transition: color 0.3s ease;
}

input[type="range"] {
  --fill-pct: 50%;
  width: 100%;
  height: 4px;
  margin: 5px 0;
  border-radius: 999px;
  outline: none;
  background: linear-gradient(
    90deg,
    var(--accent-main) 0%,
    var(--accent-sub) var(--fill-pct),
    rgba(255, 255, 255, 0.1) var(--fill-pct),
    rgba(255, 255, 255, 0.1) 100%
  );
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: pan-y;
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent-main);
  outline-offset: 4px;
}

input[type="range"]::-webkit-slider-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent-main);
  box-shadow: 0 0 10px var(--accent-main);
  -webkit-appearance: none;
  appearance: none;
  transition: transform 0.15s ease, background 0.3s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent-main);
  box-shadow: 0 0 10px var(--accent-main);
  transition: transform 0.15s ease, background 0.3s ease;
}

input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.2);
}

.interaction-hint {
  margin: 4px 0 0;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.018);
  font-size: 0.66rem;
  line-height: 1.5;
  text-align: center;
}

/* フッター */
.site-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.footer-link {
  color: var(--text-soft);
  border-bottom: 1px solid rgba(203, 213, 225, 0.3);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.footer-link:hover {
  color: var(--accent-main);
  border-color: var(--accent-main);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 860px) {
  .page-shell {
    padding: 16px;
    gap: 12px;
  }

  .lab-layout {
    justify-content: center;
    align-items: flex-end;
  }

  .control-panel {
    width: 100%;
    max-height: 52vh;
    padding: 14px 16px;
    gap: 10px;
  }

  .panel-main-title {
    font-size: 1.15rem;
  }

  .panel-description {
    display: none;
  }

  .shape-key {
    display: none;
  }

  .shape-button {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 0.7rem;
    justify-content: center;
  }
}

@media (max-width: 520px) {
  .page-shell {
    padding: 12px;
    gap: 8px;
  }

  .brand-note {
    display: none;
  }

  .art-btn {
    font-size: 0.68rem;
    padding: 6px 11px;
  }

  .control-panel {
    padding: 12px 14px;
    border-radius: 16px;
  }

  .site-footer {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    font-size: 0.64rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .hero-panel,
  .control-panel,
  .site-footer,
  .shape-button,
  .footer-link,
  .action-btn,
  .art-btn,
  input[type="range"]::-webkit-slider-thumb,
  input[type="range"]::-moz-range-thumb {
    transition: none;
  }

  .shape-button:hover,
  .action-btn:hover,
  .art-btn:hover {
    transform: none;
  }

  .tap-ripple.is-animating,
  .shutter-flash.is-active {
    animation: none;
  }
}
