@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700&display=swap');

:root {
  --accent: oklch(0.68 0.14 158);
  --accent-dark: oklch(0.58 0.13 158);
  --accent-soft-bg: oklch(0.96 0.03 158);
  --accent-soft-text: oklch(0.42 0.09 158);
  --accent-border: oklch(0.85 0.04 158);
  --accent-shadow: oklch(0.55 0.14 158 / .45);

  --text-strong: oklch(0.25 0.02 150);
  --text-heading: oklch(0.28 0.03 155);
  --text-title: oklch(0.3 0.05 155);
  --text-body: oklch(0.5 0.03 155);
  --text-muted: oklch(0.55 0.02 150);
  --text-faint: oklch(0.6 0.02 150);
  --text-label: oklch(0.45 0.02 150);

  --border-light: oklch(0.93 0.008 150);
  --border-lighter: oklch(0.92 0.01 150);
  --bg-page: oklch(0.985 0.006 140);
  --bg-panel: oklch(0.98 0.005 150);
  --bg-track: oklch(0.9 0.01 150);

  --success-text: oklch(0.55 0.13 150);
  --waiting-text: oklch(0.6 0.02 150);

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --font: "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

/* ---------- 汎用ユーティリティ ---------- */

.hide {
  display: none !important;
}

.contents {
  display: contents;
}

/* ---------- アイコン（assets/*.svg をCSS maskで読み込み currentColor で着色） ---------- */

.icon {
  display: inline-block;
  flex: none;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.icon-brand {
  width: 17px;
  height: 17px;
  -webkit-mask-image: url(../assets/icon-brand.svg);
  mask-image: url(../assets/icon-brand.svg);
}

.icon-plus {
  width: 16px;
  height: 16px;
  -webkit-mask-image: url(../assets/icon-plus.svg);
  mask-image: url(../assets/icon-plus.svg);
}

.icon-upload {
  width: 34px;
  height: 34px;
  -webkit-mask-image: url(../assets/icon-upload.svg);
  mask-image: url(../assets/icon-upload.svg);
}

.icon-arrows {
  width: 16px;
  height: 16px;
  -webkit-mask-image: url(../assets/icon-arrows.svg);
  mask-image: url(../assets/icon-arrows.svg);
}

.icon-crop {
  width: 15px;
  height: 15px;
  -webkit-mask-image: url(../assets/icon-crop.svg);
  mask-image: url(../assets/icon-crop.svg);
}

.icon-rotate {
  width: 15px;
  height: 15px;
  -webkit-mask-image: url(../assets/icon-rotate.svg);
  mask-image: url(../assets/icon-rotate.svg);
}

.icon-flip {
  width: 15px;
  height: 15px;
  -webkit-mask-image: url(../assets/icon-flip.svg);
  mask-image: url(../assets/icon-flip.svg);
}

.icon-download {
  width: 15px;
  height: 15px;
  -webkit-mask-image: url(../assets/icon-download.svg);
  mask-image: url(../assets/icon-download.svg);
}

.icon-close {
  width: 10px;
  height: 10px;
  -webkit-mask-image: url(../assets/icon-close.svg);
  mask-image: url(../assets/icon-close.svg);
}

body {
  margin: 0;
  font-family: var(--font);
  background: oklch(0.93 0.008 150);
  color: var(--text-strong);
}

button,
input {
  font-family: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
}

/* ---------- ヘッダー ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, .7);
  border-bottom: 1px solid var(--border-light);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.brand-name {
  font: 600 17px var(--font);
  color: var(--text-heading);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.bulk-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 500 12px var(--font);
  color: var(--text-label);
}

.switch {
  width: 38px;
  height: 22px;
  border-radius: 20px;
  background: var(--bg-track);
  position: relative;
  flex: none;
  border: none;
  padding: 0;
  transition: background .15s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .15s ease;
}

.switch.is-on {
  background: var(--accent);
}

.switch.is-on::after {
  transform: translateX(16px);
}

.file-count {
  font: 500 12px var(--font);
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------- レイアウト ---------- */

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 210px 1fr;
  min-height: 0;
}

.app-main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- サイドバー ---------- */

.sidebar {
  border-right: 1px solid var(--border-light);
  background: var(--bg-panel);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.sidebar-title {
  font: 600 11px var(--font);
  color: var(--text-label);
  padding: 0 4px 4px;
}

.file-row {
  position: relative;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: #fff;
}

.file-row.is-active {
  border: 1.5px solid var(--accent);
}

.file-remove-btn {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--border-light);
  background: #fff;
  color: oklch(0.4 0.02 150);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .15);
}

.file-remove-btn:hover {
  background: oklch(0.55 0.2 25);
  border-color: oklch(0.55 0.2 25);
  color: #fff;
}

.file-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  flex: none;
  overflow: hidden;
  background: repeating-linear-gradient(45deg, #eee, #eee 5px, #e4e4e4 5px, #e4e4e4 10px);
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-row.is-active .file-thumb {
  background: repeating-linear-gradient(45deg, #e6e9e3, #e6e9e3 5px, #dde2dc 5px, #dde2dc 10px);
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font: 500 12px var(--font);
  color: oklch(0.3 0.02 150);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-row.is-active .file-name {
  font-weight: 600;
  color: oklch(0.25 0.02 150);
}

.file-status {
  font: 400 10px ui-monospace, monospace;
  margin-top: 2px;
  color: var(--waiting-text);
}

.file-status.is-saved {
  color: var(--accent-dark);
}

.file-status.is-done {
  color: var(--success-text);
}

.file-progress {
  height: 4px;
  border-radius: 3px;
  background: var(--bg-track);
  overflow: hidden;
  margin-top: 6px;
}

.file-progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.file-progress > span.is-processing {
  width: 60%;
}

.add-file-btn {
  margin-top: 4px;
  width: 100%;
  border: 1.5px dashed var(--accent-border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.add-file-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.add-file-btn span {
  font: 600 12px var(--font);
  color: oklch(0.4 0.04 155);
}

/* モバイル: 縦のサイドバーの代わりに横スクロールのフィルムストリップ */
.filmstrip {
  display: none;
}

/* ---------- 空状態 ---------- */

.dropzone-wrap {
  flex: 1;
  padding: 26px;
  display: flex;
  min-width: 0;
}

.dropzone {
  flex: 1;
  border: 2px dashed var(--accent-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, oklch(0.985 0.015 158), oklch(0.965 0.028 158));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 40px;
  min-height: 420px;
  transition: border-color .15s ease, background .15s ease;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: linear-gradient(180deg, oklch(0.97 0.03 158), oklch(0.94 0.045 158));
}

.dropzone-icon {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: #fff;
  color: oklch(0.62 0.14 158);
  box-shadow: 0 8px 22px -8px var(--accent-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.dropzone-title {
  font: 700 26px var(--font);
  color: var(--text-title);
  line-height: 1.4;
}

.dropzone-subtitle {
  font: 400 14px var(--font);
  color: var(--text-body);
}

.dropzone-cta {
  margin-top: 16px;
  border: none;
  background: var(--accent);
  color: #fff;
  font: 600 14px var(--font);
  padding: 13px 28px;
  border-radius: 13px;
  box-shadow: 0 8px 18px -8px var(--accent-shadow);
}

.dropzone-hint {
  font: 400 12px var(--font);
  color: var(--text-faint);
  margin-top: 2px;
}

.format-tags {
  display: none;
}

/* ---------- エディタ（画像読み込み後の状態） ---------- */

.editor {
  flex: 1;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  min-width: 0;
}

.editor-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 232px;
  gap: 18px;
  min-height: 0;
}

.preview-card {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 26px -18px rgba(0, 0, 0, .2);
  display: flex;
  flex-direction: column;
}

.preview-name {
  font: 600 14px var(--font);
  color: var(--text-strong);
  margin-bottom: 12px;
}

.preview-compare {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  flex: 1;
  min-height: 280px;
  background: repeating-linear-gradient(45deg, #eef1ec, #eef1ec 11px, #e6ebe6 11px, #e6ebe6 22px);
  touch-action: none;
  user-select: none;
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 11px ui-monospace, monospace;
  color: #adb5ac;
  pointer-events: none;
}

.preview-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  pointer-events: none;
}

.preview-img.is-ready {
  display: block;
}

.preview-img.before {
  clip-path: inset(0 calc(100% - var(--split, 50%)) 0 0);
}

.preview-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split, 50%);
  width: 2px;
  transform: translateX(-1px);
  background: #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, .2);
  display: none;
  pointer-events: none;
}

.preview-compare.has-result .preview-divider {
  display: block;
}

.preview-handle {
  position: absolute;
  top: 50%;
  left: var(--split, 50%);
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  color: oklch(0.6 0.13 158);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .28);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
}

.preview-compare.has-result .preview-handle {
  display: flex;
}

.preview-badge {
  position: absolute;
  top: 13px;
  font: 600 11px var(--font);
  color: #fff;
  padding: 5px 11px;
  border-radius: 20px;
}

.preview-badge.before {
  left: 14px;
  background: rgba(20, 30, 25, .5);
}

.preview-badge.after {
  right: 14px;
  background: var(--accent-dark);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.bulk-banner {
  font: 500 10px var(--font);
  color: var(--accent-soft-text);
  background: var(--accent-soft-bg);
  padding: 6px 10px;
  border-radius: 9px;
  text-align: center;
}

.control-group h3 {
  font: 600 11px var(--font);
  color: var(--text-label);
  margin: 0 0 11px;
}

.control-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 11px;
}

.control-header h3 {
  margin: 0;
}

.control-header .value {
  font: 600 12px ui-monospace, monospace;
  color: var(--accent-dark);
}

.dimension-fields {
  display: flex;
  gap: 7px;
  align-items: flex-end;
}

.dimension-field {
  flex: 1;
}

.dimension-field label {
  display: block;
  font: 400 10px var(--font);
  color: var(--text-faint);
  margin-bottom: 5px;
}

.dimension-field .value-box {
  width: 100%;
  border: 1px solid var(--border-lighter);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  font: 500 13px ui-monospace, monospace;
  color: oklch(0.3 0.02 150);
  outline: none;
}

.dimension-field .value-box:focus {
  border-color: var(--accent);
}

.value-box::-webkit-outer-spin-button,
.value-box::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.value-box[type="number"] {
  -moz-appearance: textfield;
}

.segmented {
  display: flex;
  gap: 5px;
  margin-top: 9px;
}

.segmented.compact {
  background: oklch(0.96 0.008 150);
  border-radius: 10px;
  padding: 3px;
  gap: 0;
}

.segmented button {
  flex: 1;
  text-align: center;
  font: 500 11px var(--font);
  color: var(--text-muted);
  background: #fff;
  border: 1px solid var(--border-lighter);
  padding: 7px;
  border-radius: 9px;
}

.segmented.compact button {
  border: none;
  background: none;
  border-radius: 8px;
}

.segmented button.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  outline: none;
  background: linear-gradient(90deg, var(--accent) 70%, var(--bg-track) 70%);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  border: none;
}

.tool-icons {
  display: flex;
  gap: 6px;
}

.tool-icons button {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--border-lighter);
  border-radius: 9px;
  padding: 9px;
  color: oklch(0.4 0.02 150);
}

.tool-icons button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tool-icons button::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translate(-50%, 3px);
  background: oklch(0.22 0.02 150);
  color: #fff;
  font: 500 11px var(--font);
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .1s ease .1s, transform .1s ease .1s;
  z-index: 30;
}

.tool-icons button:hover::after,
.tool-icons button:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

input[type="range"]:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* ---------- フッターのサマリーバー ---------- */

.summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 8px 24px -18px rgba(0, 0, 0, .25);
}

.summary-label {
  font: 400 11px var(--font);
  color: var(--text-muted);
}

.summary-value {
  font: 600 15px var(--font);
}

.summary-value .after {
  color: var(--accent-dark);
}

.summary-value .delta {
  font: 600 12px ui-monospace, monospace;
  color: var(--accent-dark);
}

.summary-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  border: none;
  font: 600 13px var(--font);
  padding: 12px 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.btn-outline {
  border: 1px solid var(--accent-border);
  background: #fff;
  color: var(--accent-soft-text);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  box-shadow: 0 6px 16px -8px var(--accent-shadow);
}

/* ---------- レスポンシブ（モバイル） ---------- */

@media (max-width: 800px) {
  .app-header {
    padding: 14px 18px;
  }

  .bulk-toggle {
    display: none;
  }

  .app-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .filmstrip {
    display: flex;
    gap: 9px;
    padding: 12px 16px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-light);
  }

  .filmstrip-item {
    position: relative;
    flex: none;
  }

  .filmstrip .file-thumb {
    width: 56px;
    height: 56px;
    border-radius: 12px;
  }

  .filmstrip-item.is-active .file-thumb {
    border: 2px solid var(--accent);
    background: repeating-linear-gradient(45deg, #e6e9e3, #e6e9e3 5px, #dde2dc 5px, #dde2dc 10px);
  }

  .filmstrip-item .file-remove-btn {
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
  }

  .filmstrip .add-file-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: none;
    border: 1.5px dashed var(--accent-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: oklch(0.6 0.1 158);
  }

  .filmstrip .add-file-icon .icon-plus {
    width: 18px;
    height: 18px;
  }

  .dropzone-wrap {
    padding: 18px;
  }

  .dropzone {
    padding: 28px;
    min-height: 320px;
  }

  .dropzone-title {
    font-size: 21px;
  }

  .format-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 10px;
  }

  .format-tags span {
    font: 500 10px ui-monospace, monospace;
    color: oklch(0.5 0.04 155);
    background: #fff;
    border: 1px solid oklch(0.9 0.02 155);
    padding: 4px 9px;
    border-radius: 20px;
  }

  .dropzone-hint {
    display: none;
  }

  .editor {
    padding: 14px 16px;
    padding-bottom: calc(180px + env(safe-area-inset-bottom));
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }

  .preview-compare {
    min-height: 180px;
  }

  .two-col {
    display: flex;
    gap: 12px;
  }

  .two-col .control-group {
    flex: 1;
  }

  .summary-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    box-shadow: 0 -10px 28px -14px rgba(0, 0, 0, .22);
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  }

  .summary-row {
    display: flex;
    justify-content: space-between;
  }

  .summary-actions {
    justify-content: stretch;
  }

  .summary-actions .btn-primary {
    flex: 1;
  }
}
