* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  background: #141414;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, a {
  font-family: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

.viewport {
  position: relative;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  overflow: hidden;
  touch-action: none;
}

canvas#viewCanvas {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

video#cameraVideo {
  display: none;
}

.top-bar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  z-index: 10;
  min-width: 0;
  touch-action: manipulation;
}

.seed-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 6px 12px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
  flex: 0 1 auto;
  min-width: 0;
  max-width: 68%;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease, opacity 0.18s ease;
}

.seed-btn:hover {
  border-color: rgba(245, 158, 11, 0.7);
}

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

.seed-icon {
  flex-shrink: 0;
}

.seed-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-badges {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.shutter-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 25;
}

.shutter-flash.active {
  animation: shutter-flash-anim 0.3s ease-out forwards;
}

@keyframes shutter-flash-anim {
  0% { opacity: 0.92; }
  25% { opacity: 0.85; }
  100% { opacity: 0; }
}

.shutter-frame {
  position: absolute;
  inset: 8px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  z-index: 26;
}

.shutter-frame.active {
  animation: shutter-frame-anim 0.34s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes shutter-frame-anim {
  0% { opacity: 0.95; transform: scale(1.03); }
  45% { opacity: 0.9; transform: scale(0.975); }
  100% { opacity: 0; transform: scale(0.99); }
}

.shutter-toast {
  position: absolute;
  left: 50%;
  top: max(52px, calc(env(safe-area-inset-top) + 46px));
  transform: translate(-50%, -6px);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  z-index: 27;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.shutter-toast.active {
  animation: shutter-toast-anim 0.9s ease-out forwards;
}

@keyframes shutter-toast-anim {
  0% { opacity: 0; transform: translate(-50%, -6px) scale(0.94); }
  16% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  78% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -4px) scale(0.98); }
}

.camera-error {
  position: absolute;
  top: max(50px, calc(env(safe-area-inset-top) + 46px));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92%, 440px);
  text-align: center;
  color: #f6e7cf;
  background: rgba(38, 28, 16, 0.84);
  border: 1px solid rgba(245, 158, 11, 0.42);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 1.35;
  z-index: 19;
  pointer-events: none;
}

.camera-error[hidden] {
  display: none !important;
}

.zoom-hud {
  position: absolute;
  left: 50%;
  bottom: 54px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fde68a;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 16;
  backdrop-filter: blur(6px);
}

.zoom-hud.visible {
  opacity: 1;
}

.zoom-dock {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(14, 14, 14, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
  z-index: 18;
  max-width: calc(100% - 20px);
  touch-action: manipulation;
  transition: opacity 0.16s ease;
}

.zoom-dock[hidden] {
  display: none !important;
}

body.params-open .zoom-dock,
body.params-open .zoom-hud {
  opacity: 0;
  pointer-events: none;
}

.zoom-chip {
  min-width: 36px;
  height: 30px;
  padding: 0 8px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #e5e5e5;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, transform 0.1s ease;
  white-space: nowrap;
}

.zoom-chip:active {
  transform: scale(0.92);
}

.zoom-chip:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.zoom-chip.active {
  background: #f59e0b;
  color: #1a1408;
  box-shadow: 0 1px 6px rgba(245, 158, 11, 0.4);
}

.badge {
  background: rgba(0, 0, 0, 0.65);
  padding: 6px 10px;
  border-radius: 16px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
  white-space: nowrap;
  transition: opacity 0.18s ease;
}

.rec-badge {
  display: none;
  align-items: center;
  gap: 5px;
  background: rgba(220, 38, 38, 0.9);
  color: #fff;
  font-weight: bold;
}

.rec-badge.active {
  display: inline-flex;
}

.rec-dot {
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  animation: blink 1s infinite;
}

@keyframes blink {
  50% { opacity: 0.2; }
}

/* 下部（スマホ縦デフォルト）コントロール領域 */
.controls {
  position: relative;
  background: #1a1a1a;
  width: 100%;
  min-width: 0;
  border-top: 1px solid #2e2e2e;
  display: flex;
  flex-direction: column;
  z-index: 20;
  flex: 0 0 auto;
  overflow: visible;
}

.controls-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: visible;
}

.quick-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px max(12px, env(safe-area-inset-right)) 5px max(12px, env(safe-area-inset-left));
  min-width: 0;
  background: #1c1c1c;
}

.style-bar {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: #262626;
  border: 1px solid rgba(255, 255, 255, 0.08);
  width: 100%;
  min-width: 0;
}

.style-btn {
  flex: 1 1 0;
  min-width: 0;
  border: none;
  background: transparent;
  color: #bcbcbc;
  border-radius: 999px;
  padding: 6px 8px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.style-btn:hover:not(.active) {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.style-btn.active {
  background: #f59e0b;
  color: #1a1408;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.palette-scroller {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
}

.palette-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(18, 18, 18, 0.88);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  transition: opacity 0.15s ease, transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.palette-nav-prev {
  left: 2px;
}

.palette-nav-next {
  right: 2px;
}

.palette-nav:hover {
  border-color: #f59e0b;
  background: rgba(34, 26, 12, 0.94);
  color: #fbbf24;
}

.palette-nav:active {
  transform: translateY(-50%) scale(0.9);
}

.palette-nav.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.palette-bar {
  display: flex;
  flex: 1 1 auto;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 4px;
  scrollbar-width: none;
  touch-action: pan-x;
  scroll-behavior: smooth;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.palette-bar.is-dragging {
  scroll-behavior: auto;
  cursor: grabbing;
}

.palette-bar::-webkit-scrollbar {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .palette-bar {
    cursor: grab;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.26) transparent;
    padding-bottom: 6px;
  }

  .palette-bar::-webkit-scrollbar {
    display: block;
    height: 5px;
  }

  .palette-bar::-webkit-scrollbar-track {
    background: transparent;
  }

  .palette-bar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 999px;
  }

  .palette-bar::-webkit-scrollbar-thumb:hover {
    background: rgba(245, 158, 11, 0.72);
  }
}

.palette-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  background: #282828;
  color: #e0e0e0;
  border: 1.5px solid #3c3c3c;
  padding: 6px 11px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease, transform 0.1s ease;
}

.palette-chip:hover:not(.active) {
  border-color: rgba(245, 158, 11, 0.6);
  background: #303030;
}

.palette-chip:active {
  transform: scale(0.96);
}

.palette-chip.active {
  background: #ffffff;
  color: #141414;
  border-color: #f59e0b;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

.chip-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  min-width: 0;
}

.chip-name,
.chip-artist {
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-artist {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  opacity: 0.72;
}

.swatch-dots {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
}

.swatch-dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

/* 質感・詳細パラメータパネル（スマホではデフォルト非表示、調整ボタンで展開） */
.params-panel {
  display: none;
  flex-direction: column;
  min-width: 0;
}

body.params-open .quick-bar,
body.params-open .actions {
  display: none;
}

body.params-open .params-panel {
  display: flex;
  position: static;
  width: 100%;
  max-height: min(46dvh, 310px);
  background: #1c1c1c;
  border-top: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

body.app-fullscreen.params-open .controls {
  background: rgba(20, 20, 20, 0.94);
  border-radius: 16px 16px 0 0;
}

body.app-fullscreen.params-open .params-panel {
  background: transparent;
}

.params-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  flex-shrink: 0;
}

.params-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.params-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #f3f3f3;
  white-space: nowrap;
}

.params-preset-name {
  font-size: 11px;
  color: #fbbf24;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.params-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.params-reset-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  color: #eaeaea;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease, opacity 0.14s ease;
}

.params-reset-btn:hover:not(:disabled) {
  border-color: #f59e0b;
  color: #fbbf24;
}

.params-reset-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.params-close-btn {
  height: 28px;
  padding: 0 10px;
  gap: 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.09);
  color: #f0f0f0;
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
}

.params-close-btn:hover {
  border-color: #f59e0b;
  color: #fbbf24;
}

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

.params-scroll {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.sliders {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  width: 100%;
  min-width: 0;
}

.slider-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: #d6d6d6;
}

.slider-header label {
  line-height: 1.25;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slider-header span:last-child {
  color: #fbbf24;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  flex-shrink: 0;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: #3a3a3a;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f59e0b;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
  margin-top: -6.5px;
  transition: transform 0.1s ease;
}

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

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: #3a3a3a;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f59e0b;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
}

.camera-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #aaa;
  font-size: 11px;
  min-width: 0;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.camera-picker-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
}

.camera-picker select {
  flex: 1 1 130px;
  max-width: 100%;
  min-width: 0;
  border: 1px solid #444;
  border-radius: 12px;
  background: #2a2a2a;
  color: #eee;
  padding: 5px 9px;
  font: inherit;
}

.camera-status {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lens-info {
  font-size: 10.5px;
  color: #9ca3af;
  line-height: 1.35;
}

.lens-info:empty {
  display: none;
}

/* アクションバー */
.actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  padding: 7px max(14px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid #292929;
  background: #171717;
}

.actions-left {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 8px;
}

.actions-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cam-btn {
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}

.cam-btn:active {
  transform: scale(0.93);
}

.cam-btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.cam-btn-sub,
.cam-btn-video {
  background: transparent;
  flex-direction: column;
  gap: 3px;
  border-radius: 12px;
  padding: 2px 3px;
  color: #e5e5e5;
}

.cam-btn-circle {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.cam-btn-sub .cam-btn-circle {
  background: #2b2b2b;
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.cam-btn-sub:hover .cam-btn-circle {
  background: #363636;
  border-color: rgba(255, 255, 255, 0.28);
}

.cam-btn-caption {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  color: #b5b5b5;
  white-space: nowrap;
}

.cam-btn-sub.is-fullscreen .cam-btn-circle,
.cam-btn-sub.is-open .cam-btn-circle {
  background: #f59e0b;
  color: #1a1408;
  border-color: #fbbf24;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
}

.cam-btn-sub.is-fullscreen .cam-btn-caption,
.cam-btn-sub.is-open .cam-btn-caption {
  color: #fbbf24;
}

.cam-btn-dot {
  display: none;
  position: absolute;
  top: 1px;
  right: 1px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  border: 1.5px solid #171717;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.85);
}

.cam-btn-params.is-modified .cam-btn-dot {
  display: block;
}

.cam-btn-params.is-open.is-modified .cam-btn-dot {
  background: #1a1408;
  border-color: #fbbf24;
}

.cam-btn .icon-fs-exit {
  display: none;
}

.cam-btn.is-fullscreen .icon-fs-enter {
  display: none;
}

.cam-btn.is-fullscreen .icon-fs-exit {
  display: block;
}

.cam-btn-shutter {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #ffffff;
  color: #141414;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.24), 0 4px 14px rgba(0, 0, 0, 0.45);
}

.cam-btn-shutter.shutter-fired {
  animation: shutter-btn-pulse 0.28s ease-out;
}

@keyframes shutter-btn-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(0.84); box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.45); }
  100% { transform: scale(1); }
}

.cam-btn-video .cam-btn-circle {
  width: 42px;
  height: 42px;
  background: #ef4444;
  color: #fff;
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.35);
}

.cam-btn-video .icon-rec-stop {
  display: none;
}

.cam-btn-video.recording .cam-btn-circle {
  background: #b91c1c;
  box-shadow: 0 0 0 3px #fca5a5, 0 2px 12px rgba(239, 68, 68, 0.5);
}

.cam-btn-video.recording .icon-rec-start {
  display: none;
}

.cam-btn-video.recording .icon-rec-stop {
  display: block;
}

/* 全画面表示モード（スマホ縦ベース。横向き・PCは各メディアクエリで上書き） */
body.app-fullscreen .seed-btn,
body.app-fullscreen #fpsBadge {
  opacity: 0;
  pointer-events: none;
}

body.app-fullscreen .viewport {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
}

body.app-fullscreen .controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: auto;
  z-index: 30;
  background: rgba(16, 16, 16, 0.76);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

body.app-fullscreen .quick-bar {
  display: none;
}

body.app-fullscreen .actions {
  background: transparent;
  border-top: none;
}

body.app-fullscreen .zoom-dock {
  bottom: calc(92px + env(safe-area-inset-bottom));
}

body.app-fullscreen .zoom-hud {
  bottom: calc(136px + env(safe-area-inset-bottom));
}

/* モーダル & 汎用アクションボタン */
button.action-btn,
a.action-btn {
  border: none;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-width: 84px;
  white-space: nowrap;
}

button.action-btn:active,
a.action-btn:active {
  transform: scale(0.95);
}

.btn-sub {
  background: #383838;
  color: #fff;
  padding: 10px 12px;
}

.btn-photo {
  background: #fff;
  color: #111;
  padding: 11px 14px;
  font-size: 14.5px;
  box-shadow: 0 2px 10px rgba(255, 255, 255, 0.2);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  z-index: 100;
  gap: 12px;
}

.modal.open {
  display: flex;
}

.modal-content {
  max-width: 94%;
  max-height: 70dvh;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
}

.modal-content img,
.modal-content video {
  max-width: 100%;
  max-height: 70dvh;
  display: block;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 340px;
}

.modal-hint {
  font-size: 12px;
  color: #aaa;
  text-align: center;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 16, 14, 0.5);
  cursor: wait;
  touch-action: none;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 30px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  color: #3a302a;
  font-size: 15px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}

.loading-text {
  margin: 0;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 4px solid rgba(120, 100, 90, 0.25);
  border-top-color: #c0504d;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

button.action-btn:disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* スマホ横向き（自動回転）：全面プレビュー＋下端に1行フローティング画材バー＋右端にスリム縦アクションバー */
@media (orientation: landscape) and (max-height: 560px) {
  html, body {
    flex-direction: row;
  }

  .viewport {
    width: auto;
    height: 100%;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
  }

  .top-bar {
    left: max(10px, env(safe-area-inset-left));
    right: 10px;
  }

  body.app-fullscreen .top-bar {
    right: calc(84px + env(safe-area-inset-right));
  }

  .zoom-dock {
    bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .zoom-hud {
    bottom: calc(108px + env(safe-area-inset-bottom));
  }

  .controls {
    position: static;
    width: auto;
    height: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    border-top: none;
    border-left: 1px solid #2b2b2b;
    background: #171717;
  }

  .controls-body {
    width: 0;
    padding: 0;
    overflow: visible;
  }

  .quick-bar {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: calc(86px + env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 22;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 16px;
    background: rgba(18, 18, 18, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  }

  .style-bar {
    width: auto;
    flex: 0 0 auto;
  }

  .style-btn {
    flex: 0 0 auto;
    padding: 5px 9px;
    font-size: 11.5px;
  }

  .palette-scroller {
    flex: 1 1 0;
    min-width: 0;
  }

  .palette-bar {
    padding: 1px 0;
  }

  .palette-chip {
    padding: 5px 9px;
    font-size: 11.5px;
  }

  body.params-open .quick-bar,
  body.params-open .actions {
    display: none;
  }

  body.params-open .camera-error {
    opacity: 0;
  }

  body.params-open .controls-body {
    width: auto;
    flex: 1 1 auto;
    height: 100%;
    overflow: hidden;
  }

  body.params-open .params-panel {
    position: static;
    width: min(350px, 50vw);
    height: 100%;
    max-height: none;
    border-radius: 0;
    border-top: none;
    border-left: none;
    box-shadow: none;
    background: #1a1a1a;
    padding-right: env(safe-area-inset-right);
  }

  body.app-fullscreen.params-open .controls {
    border-radius: 16px 0 0 16px;
    background: rgba(20, 20, 20, 0.94);
  }

  body.app-fullscreen.params-open .params-panel {
    background: transparent;
  }

  .params-header {
    padding: 8px 12px 6px;
  }

  .params-scroll {
    padding: 8px 12px 10px;
    gap: 8px;
  }

  .sliders {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px 10px;
  }

  .slider-header {
    font-size: 10.5px;
  }

  .actions {
    width: calc(76px + env(safe-area-inset-right));
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) 8px;
    border-top: none;
    background: transparent;
  }

  .cam-btn-caption {
    display: none;
  }

  .actions-right {
    order: 1;
    justify-self: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .cam-btn-shutter {
    order: 2;
    width: 54px;
    height: 54px;
  }

  .actions-left {
    order: 3;
    justify-self: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .cam-btn-circle {
    width: 36px;
    height: 36px;
  }

  .cam-btn-video .cam-btn-circle {
    width: 40px;
    height: 40px;
  }

  .cam-btn-sub .cam-btn-circle svg {
    width: 17px;
    height: 17px;
  }

  body.app-fullscreen .controls {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: auto;
    height: 100%;
    border-top: none;
    border-left: 1px solid rgba(255, 255, 255, 0.14);
  }

  body.app-fullscreen .zoom-dock {
    bottom: max(10px, env(safe-area-inset-bottom));
    left: calc((100% - 76px - env(safe-area-inset-right)) / 2);
  }

  body.app-fullscreen .zoom-hud {
    bottom: calc(54px + env(safe-area-inset-bottom));
    left: calc((100% - 76px - env(safe-area-inset-right)) / 2);
  }
}

/* タブレット・PC横長画面：右サイドバーにパレット2列グリッド＆質感パラメータカードを常時表示 */
@media (min-width: 840px) and (min-height: 561px) {
  html, body {
    flex-direction: row;
  }

  .viewport {
    width: auto;
    height: 100%;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
  }

  .top-bar {
    left: max(12px, env(safe-area-inset-left));
    right: 12px;
  }

  .controls {
    width: clamp(340px, 31vw, 420px);
    flex: 0 0 auto;
    height: 100%;
    max-height: none;
    flex-direction: column;
    border-top: none;
    border-left: 1px solid #2e2e2e;
    overflow: hidden;
  }

  .controls-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px 14px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  }

  .controls-body::-webkit-scrollbar {
    width: 6px;
  }

  .controls-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
  }

  .quick-bar {
    padding: 0;
    gap: 10px;
    background: transparent;
  }

  .palette-nav {
    display: none !important;
  }

  .palette-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    overflow: visible;
    padding: 0;
    cursor: default;
  }

  .palette-chip {
    width: 100%;
    min-height: 42px;
    justify-content: flex-start;
    padding: 6px 10px;
    border-radius: 14px;
  }

  .params-panel {
    display: flex;
    position: static;
    max-height: none;
    background: #222222;
    border: 1px solid #303030;
    border-radius: 14px;
    box-shadow: none;
    flex-shrink: 0;
  }

  .params-header {
    padding: 10px 12px 8px;
  }

  .params-close-btn {
    display: none;
  }

  .params-scroll {
    overflow: visible;
    padding: 10px 12px 12px;
  }

  .cam-btn-params {
    display: none;
  }

  body.params-open:not(.app-fullscreen) .quick-bar {
    display: flex;
  }

  body.params-open:not(.app-fullscreen) .actions {
    display: grid;
  }

  body.params-open:not(.app-fullscreen) .params-panel {
    display: flex;
    position: static;
    width: auto;
    max-height: none;
    background: #222222;
    border: 1px solid #303030;
    border-radius: 14px;
    box-shadow: none;
    flex-shrink: 0;
  }

  body.params-open .zoom-dock,
  body.params-open .zoom-hud {
    opacity: 1;
    pointer-events: auto;
  }

  body.app-fullscreen.params-open .zoom-dock,
  body.app-fullscreen.params-open .zoom-hud {
    opacity: 0;
    pointer-events: none;
  }

  body.app-fullscreen .controls {
    top: auto;
    left: 50%;
    right: auto;
    bottom: 16px;
    transform: translateX(-50%);
    width: 390px;
    height: auto;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 28px;
    overflow: visible;
  }

  body.app-fullscreen .controls-body {
    padding: 0;
    overflow: visible;
  }

  body.app-fullscreen .cam-btn-params {
    display: inline-flex;
  }

  body.app-fullscreen .params-panel {
    display: none;
  }

  body.app-fullscreen.params-open .actions {
    display: none;
  }

  body.app-fullscreen.params-open .controls {
    width: min(410px, calc(100vw - 32px));
    border-radius: 20px;
    overflow: hidden;
  }

  body.app-fullscreen.params-open .params-panel {
    display: flex;
    position: static;
    max-height: min(62vh, 430px);
    background: rgba(22, 22, 22, 0.94);
    backdrop-filter: blur(14px);
    border: none;
    border-radius: 20px;
    box-shadow: none;
    overflow: hidden;
    z-index: 35;
  }

  body.app-fullscreen.params-open .params-scroll {
    overflow-y: auto;
  }

  body.app-fullscreen.params-open .params-close-btn {
    display: inline-flex;
  }

  body.app-fullscreen .zoom-dock {
    bottom: 112px;
  }

  body.app-fullscreen .zoom-hud {
    bottom: 156px;
  }
}

/* 極めて狭い縦画面でもはみ出さないよう調整 */
@media (max-width: 360px) and (orientation: portrait) {
  .actions {
    gap: 4px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .actions-left,
  .actions-right {
    gap: 5px;
  }

  .cam-btn-circle {
    width: 38px;
    height: 38px;
  }

  .cam-btn-video .cam-btn-circle {
    width: 38px;
    height: 38px;
  }

  .cam-btn-shutter {
    width: 54px;
    height: 54px;
  }

  .sliders {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px 8px;
  }

  .slider-header {
    font-size: 10.5px;
    gap: 4px;
  }

  button.action-btn,
  a.action-btn {
    min-width: 72px;
    font-size: 13px;
    padding: 9px 10px;
  }
}

/* ホーム画面への追加（アプリ化）案内バナー */
.a2hs-banner {
  position: fixed;
  top: max(48px, calc(env(safe-area-inset-top) + 42px));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  max-width: 420px;
  margin: 0 auto;
  z-index: 85;
  background: rgba(28, 26, 25, 0.94);
  color: #f5f5f5;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
}

.a2hs-banner[hidden] {
  display: none !important;
}

.a2hs-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.a2hs-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.a2hs-body {
  flex: 1 1 auto;
  min-width: 0;
}

.a2hs-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

.a2hs-sub {
  font-size: 11px;
  color: #cfcfcf;
  line-height: 1.3;
  margin-top: 2px;
}

.a2hs-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.a2hs-btn {
  border: none;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 11px;
  cursor: pointer;
  white-space: nowrap;
}

.a2hs-btn:active {
  transform: scale(0.95);
}

.a2hs-btn-primary {
  background: #f59e0b;
  color: #1a1408;
}

.a2hs-btn-dismiss {
  background: #333;
  color: #ddd;
}

.a2hs-guide {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.a2hs-guide[hidden] {
  display: none !important;
}

.a2hs-guide-text {
  font-size: 11.5px;
  line-height: 1.45;
  color: #fde68a;
}

@media (max-width: 380px) {
  .a2hs-row {
    flex-wrap: wrap;
  }

  .a2hs-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
