:root {
  --bg: #0f1117;
  --panel: #171b23;
  --panel-2: #1e2430;
  --panel-3: #232b39;
  --line: #323a49;
  --text: #eef2ff;
  --muted: #96a2bb;
  --accent: #e7c045;
  --accent-2: #66a8ff;
  --accent-soft: rgba(231, 192, 69, 0.16);
  --danger: #ff7286;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, #0b0d12, #121721 34%, #0e121b 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow: hidden;
}
button, select, input { font: inherit; }
button {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}
button:active { transform: translateY(1px); }

.app-shell-mobile {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.app-header-mobile {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(14, 18, 27, 0.96);
}
.title-stack h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.15;
}
.copyright-mini {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
}
.header-right-cluster {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.header-links {
  display: flex;
  gap: 6px;
}
.header-links a,
.save-top-btn {
  min-width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid #44608f;
  background: rgba(27, 36, 50, 0.98);
  color: #d8e6ff;
  font-weight: 800;
}
.save-top-btn {
  min-width: 54px;
  border-color: #8b7420;
  background: #332a0b;
  color: #ffe79d;
}

.main-mobile {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(200px, 38dvh);
  overflow: hidden;
}
.main-mobile.workspace-closed {
  grid-template-rows: minmax(0, 1fr);
}
.workspace-panel-mobile[hidden] {
  display: none;
}
.preview-stage-mobile {
  position: relative;
  min-height: 0;
  margin: 8px 12px 6px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
  background: #11161f;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage-mobile canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.preview-meta-overlay {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  pointer-events: none;
}
.canvas-info-badge {
  display: inline-flex;
  max-width: 100%;
  padding: 5px 10px;
  background: rgba(9, 12, 18, 0.72);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  color: #d8e0f2;
  font-size: 0.72rem;
  line-height: 1.25;
}

.workspace-panel-mobile {
  margin: 0 12px 8px;
  background: rgba(23, 27, 35, 0.96);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 18px 18px 0 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.workspace-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.workspace-title {
  font-weight: 800;
  font-size: 0.92rem;
}
.workspace-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}
.workspace-mode-badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #53431c;
  background: rgba(231, 192, 69, 0.1);
  color: #ffdf7a;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.workspace-block {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.workspace-block[hidden] {
  display: none !important;
}
.filter-rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 12px 8px;
  scrollbar-width: thin;
}
.filter-card {
  flex: 0 0 112px;
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
  background: #1d2330;
  border: 1px solid rgba(255,255,255,0.08);
  text-align: left;
}
.filter-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(231, 192, 69, 0.3);
}
.filter-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
  background: #0f131a;
}
.filter-thumb-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #18212f, #242d3b);
  color: #b7c0d7;
  font-size: 0.72rem;
}
.filter-card-body {
  padding: 8px 9px 9px;
}
.filter-card-title {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}
.filter-card-note {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.63rem;
}
.preset-info-box {
  margin: 0 12px 8px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.18);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}
.param-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 12px 12px;
  scrollbar-width: thin;
}
.param-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 8px 10px 10px;
  margin-bottom: 8px;
}
.param-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.param-name { font-size: 0.76rem; font-weight: 700; }
.param-value { color: var(--accent-2); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent-2); }

.settings-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 7px 10px 9px;
}
.settings-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 7px;
}
.settings-card-compact { padding-bottom: 7px; }
.settings-card-title {
  font-size: 0.72rem;
  font-weight: 800;
  margin-bottom: 6px;
}
.detection-radio-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}
.detection-radio {
  position: relative;
  min-width: 0;
  margin: 0;
  cursor: pointer;
}
.detection-radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.detection-radio span {
  min-height: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 5px 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #1b2230;
  color: #dce4f7;
  font-size: 0.69rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
}
.detection-radio small {
  color: var(--muted);
  font-size: 0.54rem;
  font-weight: 600;
  white-space: nowrap;
}
.detection-radio input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #ffe79d;
}
.detection-radio input:checked + span small { color: #d6c47d; }
.detection-radio input:focus-visible + span { outline: 2px solid var(--accent-2); }
.settings-help,
.status-box,
.meta-box {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}
.settings-help { margin: 5px 0 0; font-size: 0.62rem; }
.settings-toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 8px;
}
.settings-toggle-grid label {
  font-size: 0.68rem;
  color: #d8def0;
}
.settings-button-row {
  display: flex;
  gap: 8px;
}
.settings-button-row > button {
  flex: 1 1 0;
  padding: 10px 12px;
}
.status-box,
.meta-box {
  background: rgba(0,0,0,0.18);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 9px 10px;
}
.meta-box { margin-top: 8px; }
.error-text { color: #ff9db0; }

.bottom-dock-mobile {
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(13, 17, 24, 0.98);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}
.bottom-dock-scroll,
.category-rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.bottom-dock-scroll { align-items: center; }
.category-rail { padding-right: 8px; }
.dock-btn,
.category-btn {
  flex: 0 0 auto;
  min-width: 74px;
  padding: 10px 12px;
  border-radius: 999px;
  background: #1b2230;
  border: 1px solid var(--line);
  color: #e5ebff;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.dock-btn-primary { border-color: #7f6923; color: #ffe596; background: #31280e; }
.category-btn.is-active,
.dock-btn.is-active {
  border-color: var(--accent);
  background: rgba(231, 192, 69, 0.14);
  color: #ffe79d;
}

.top-link-buttons,
.site-footer-hidden,
.legacy-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 10, 16, 0.55);
  backdrop-filter: blur(3px);
}
.progress-overlay[hidden] { display: none; }
.progress-dialog {
  width: min(320px, calc(100vw - 32px));
  padding: 18px 16px;
  background: rgba(18, 22, 30, 0.98);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0,0,0,0.42);
}
.detect-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: #dce6ff;
  font-size: 0.88rem;
  font-weight: 700;
}
.detect-progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,0.08);
}
.detect-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 120ms ease;
}

.checkerboard {
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.06) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
}

@media (min-width: 860px) {
  body { overflow: auto; }
  .app-shell-mobile { max-width: 480px; margin: 0 auto; border-left: 1px solid rgba(255,255,255,0.06); border-right: 1px solid rgba(255,255,255,0.06); }
}

/* 2026-07-02 mobile width/compactness correction */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
}
body { touch-action: pan-y; }

.app-shell-mobile,
.app-header-mobile,
.main-mobile,
.preview-stage-mobile,
.workspace-panel-mobile,
.workspace-section-head,
.workspace-block,
.settings-scroll,
.param-scroll,
.filter-rail,
.bottom-dock-mobile,
.bottom-dock-scroll {
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.app-shell-mobile {
  max-width: 100vw;
}

.app-header-mobile {
  padding: 8px 10px 7px;
  overflow: hidden;
}
.title-stack {
  flex: 1 1 auto;
  min-width: 0;
}
.title-stack h1 {
  font-size: 1rem;
  white-space: nowrap;
}
.copyright-mini {
  font-size: 0.56rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-right-cluster {
  flex: 0 0 auto;
  min-width: 0;
  gap: 4px;
}
.header-links { gap: 3px; }
.header-links a,
.save-top-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  font-size: 0.68rem;
}
.save-top-btn { min-width: 42px; }

.main-mobile {
  grid-template-rows: minmax(0, 1fr) clamp(174px, 33dvh, 250px);
}
.main-mobile.workspace-closed {
  grid-template-rows: minmax(0, 1fr);
}
.preview-stage-mobile {
  width: calc(100% - 16px);
  margin: 6px 8px 4px;
  border-radius: 14px;
}
.preview-stage-mobile canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.preview-meta-overlay {
  left: 7px;
  right: 7px;
  bottom: 7px;
}
.canvas-info-badge {
  padding: 3px 7px;
  font-size: 0.58rem;
}

.workspace-panel-mobile {
  width: calc(100% - 16px);
  margin: 0 8px 4px;
  border-radius: 14px 14px 0 0;
}
.workspace-section-head {
  padding: 6px 8px 5px;
}
.workspace-section-head > div:first-child {
  min-width: 0;
}
.workspace-title {
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-subtitle {
  font-size: 0.55rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-mode-badge {
  padding: 2px 5px;
  font-size: 0.5rem;
}

.workspace-block {
  overflow: hidden;
}
.param-scroll {
  order: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 7px 2px;
}
.preset-info-box {
  order: 2;
  flex: 0 0 auto;
  min-width: 0;
  margin: 2px 7px 4px;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 0.52rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-rail {
  order: 3;
  flex: 0 0 auto;
  gap: 6px;
  padding: 4px 7px 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
}
.filter-card {
  flex: 0 0 76px;
  width: 76px;
  min-width: 76px;
  border-radius: 9px;
}
.filter-thumb,
.filter-thumb-placeholder {
  width: 76px;
  height: 60px;
  aspect-ratio: auto;
  object-fit: cover;
}
.filter-thumb-placeholder { font-size: 0.52rem; }
.filter-card-body { padding: 3px 5px 4px; }
.filter-card-title {
  font-size: 0.58rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-card-note { display: none; }

.param-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 5px;
  min-width: 0;
  margin: 0 0 3px;
  padding: 3px 5px;
  border-radius: 7px;
}
.param-head { display: contents; }
.param-name {
  min-width: 0;
  font-size: 0.56rem;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.param-value {
  min-width: 0;
  font-size: 0.54rem;
  line-height: 1;
  text-align: right;
}
.param-card input[type="range"] {
  width: 100%;
  min-width: 0;
  height: 14px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent-2);
}

.param-card-text {
  grid-template-columns: 24px minmax(0, 1fr);
}
.param-text-input {
  width: 100%;
  min-width: 0;
  height: 20px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(10,18,34,0.9);
  color: var(--text-main);
  font-size: 0.52rem;
  padding: 0 5px;
}
.param-text-input::-webkit-calendar-picker-indicator {
  filter: invert(0.88);
  opacity: 0.72;
}

.settings-scroll {
  overflow-x: hidden;
  padding: 4px 7px 6px;
}
.settings-card {
  min-width: 0;
  margin-bottom: 4px;
  padding: 5px 6px;
  border-radius: 8px;
}
.settings-card-title {
  margin-bottom: 3px;
  font-size: 0.58rem;
}
.detection-radio-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
}
.detection-radio {
  position: static;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  color: #dce4f7;
  font-size: 0.6rem;
  line-height: 1;
  cursor: pointer;
}
.detection-radio input {
  position: static;
  opacity: 1;
  pointer-events: auto;
  appearance: auto;
  -webkit-appearance: radio;
  width: 14px;
  height: 14px;
  min-width: 14px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}
.detection-radio span {
  min-height: 0;
  display: inline;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: 600;
  line-height: 1;
}
.detection-radio input:checked + span {
  border: 0;
  background: transparent;
  color: #ffe79d;
}
.settings-help {
  margin: 3px 0 0;
  font-size: 0.5rem;
  line-height: 1.1;
}
.settings-toggle-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 6px;
}
.settings-toggle-grid label {
  min-width: 0;
  font-size: 0.56rem;
  line-height: 1.2;
  white-space: nowrap;
}
.settings-toggle-grid input {
  width: 13px;
  height: 13px;
  margin: 0 2px 0 0;
  vertical-align: -2px;
}
.settings-button-row { gap: 4px; }
.settings-button-row > button {
  min-width: 0;
  padding: 5px 6px;
  border-radius: 8px;
  font-size: 0.56rem;
}
.status-box,
.meta-box {
  min-width: 0;
  padding: 5px 6px;
  border-radius: 7px;
  font-size: 0.52rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.meta-box { margin-top: 3px; }

.bottom-dock-mobile {
  width: 100%;
  max-width: 100vw;
  padding: 5px 7px calc(5px + var(--safe-bottom));
  overflow: hidden;
}
.bottom-dock-scroll {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
  scrollbar-width: none;
}
.bottom-dock-scroll::-webkit-scrollbar,
.filter-rail::-webkit-scrollbar { display: none; }
.category-rail { display: contents; }
.dock-btn,
.category-btn {
  flex: 0 0 auto;
  min-width: auto;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 0.62rem;
  white-space: nowrap;
}

@media (max-width: 390px) {
  .header-links a { display: none; }
  .main-mobile { grid-template-rows: minmax(0, 1fr) clamp(168px, 34dvh, 225px); }
  .settings-toggle-grid { grid-template-columns: 1fr 1fr; }
  .param-card { grid-template-columns: 46px minmax(0, 1fr) 27px; gap: 4px; }
}
body { touch-action: auto; }

.param-empty {
  padding: 6px 2px;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.3;
}

.save-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 3600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(5, 8, 13, 0.62);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 120ms ease;
}
.save-dialog-overlay[hidden] { display: none; }
.save-dialog-overlay.is-open { opacity: 1; }
.save-dialog-box {
  width: min(310px, calc(100vw - 36px));
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  background: rgba(22, 27, 36, 0.98);
  box-shadow: 0 20px 52px rgba(0,0,0,0.48);
}
.save-dialog-title {
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
}
.save-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.save-dialog-actions button,
.save-dialog-cancel {
  min-width: 0;
  padding: 10px 8px;
  font-size: 0.78rem;
  font-weight: 700;
}
.save-dialog-actions button:first-child {
  border-color: #8b7420;
  background: #332a0b;
  color: #ffe79d;
}
.save-dialog-cancel {
  width: 100%;
  margin-top: 8px;
  background: #1b2230;
  color: var(--muted);
}
