/* ===========================================================
   ES Transform — tool page (index.html) styles
   =========================================================== */

html, body {
  overflow-x: hidden;
}

header {
  padding: 2.5rem var(--pad-x) 1.5rem;
  border-bottom: 1px solid var(--line);
  position: relative;
  background: var(--paper);
}

header::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: var(--pad-x);
  right: var(--pad-x);
  height: 1px;
  background: var(--line);
}

@media (max-width: 700px) {
  header { padding: 1.5rem var(--pad-x) 1rem; }
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: nowrap;
}

.title-row > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

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

h1 {
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-weight: 400;
  font-size: clamp(1.75rem, 5vw, 3.5rem);
  letter-spacing: -0.02em;
  line-height: 1;
}

h1 em { font-style: italic; font-weight: 500; color: var(--accent); }

.formula {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--line);
  letter-spacing: 0.05em;
  border: 1px solid var(--line);
  padding: 0.4rem 0.7rem;
  background: var(--paper-dark);
  white-space: nowrap;
}

.about-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.65rem 1rem;
  background: var(--paper);
  transition: all 0.2s;
  align-self: flex-start;
  flex-shrink: 0;
}

@media (hover: hover) {
  .about-link:hover {
    background: var(--ink);
    color: var(--paper);
  }
  .about-link:hover .about-link-icon { color: var(--paper); }
}

.about-link-icon {
  font-size: 1.4rem;
  color: var(--accent);
  line-height: 1;
  transition: color 0.2s;
}

.about-link-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.2;
}

.about-link-title {
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 1rem;
  font-weight: 500;
}

.about-link-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

@media (max-width: 700px) {
  .about-link { padding: 0.55rem 0.85rem; gap: 0.5rem; }
  .about-link-title { font-size: 0.95rem; }
  .about-link-sub { font-size: 0.58rem; }
}

@media (max-width: 700px) {
  .formula { font-size: 0.65rem; padding: 0.3rem 0.5rem; }
}

.subtitle {
  font-style: italic;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--line);
  margin-top: 0.5rem;
  opacity: 0.9;
  line-height: 1.5;
}

.caveat {
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 0.78rem;
  color: var(--line);
  margin-top: 0.85rem;
  padding-left: 0.7rem;
  border-left: 2px solid var(--accent);
  opacity: 0.78;
  line-height: 1.55;
}

.caveat-label {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-style: normal;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.2rem;
  opacity: 0.95;
}

main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  min-height: calc(100vh - 140px);
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

.canvas-area {
  padding: 2rem var(--pad-x);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  position: relative;
  min-width: 0;
  background: var(--paper);
}

.canvas-area::before {
  content: 'I.';
  position: absolute;
  top: 1rem;
  left: var(--pad-x);
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--line);
  opacity: 0.65;
}

@media (max-width: 700px) {
  .canvas-area { padding: 1.25rem var(--pad-x); }
}

.canvas-wrap {
  position: relative;
  background: var(--paper-dark);
  border: 1px solid var(--line);
  box-shadow: 8px 8px 0 var(--ink);
  width: 100%;
  max-width: min(600px, calc(100vw - var(--pad-x) * 2 - 12px));
  aspect-ratio: 1 / 1;
}

@media (max-width: 700px) {
  .canvas-wrap { box-shadow: 4px 4px 0 var(--ink); }
}

/* 非正方形画像 + crop モードのときだけドラッグ可能のカーソル */
.canvas-wrap.pannable-x {
  cursor: ew-resize;
  touch-action: none;  /* スマホで横スクロールを抑止 */
}
.canvas-wrap.pannable-y {
  cursor: ns-resize;
  touch-action: none;
}
.canvas-wrap.dragging { cursor: grabbing; }

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  cursor: pointer;
  transition: background 0.3s;
}

@media (hover: hover) {
  #placeholder:hover { background: rgba(139, 58, 31, 0.05); }
}
#placeholder.dragover { background: rgba(139, 58, 31, 0.1); }

.placeholder-icon {
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-size: clamp(3rem, 10vw, 4rem);
  font-style: italic;
  color: var(--accent);
  line-height: 1;
  display: inline-block;            /* transform を効かせるため */
  transform-origin: 50% 55%;        /* ∮ は重心が中心よりやや下 */
  animation: placeholder-icon-spin 4s ease-in-out infinite;
}

/* 3.2秒 静止 → 0.8秒で 1 回転 → ループ。"時折クルッ" の演出 */
@keyframes placeholder-icon-spin {
  0%, 80%  { transform: rotate(0deg); }
  100%     { transform: rotate(360deg); }
}

/* モーション抑制設定をしているユーザーには動かさない */
@media (prefers-reduced-motion: reduce) {
  .placeholder-icon { animation: none; }
}

.placeholder-text {
  font-style: italic;
  color: var(--line);
  text-align: center;
  font-size: clamp(0.95rem, 3vw, 1.1rem);
  padding: 0 1rem;
}

.placeholder-text small {
  display: block;
  margin-top: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-style: normal;
  letter-spacing: 0.1em;
  opacity: 0.6;
}

/* Fit-mode toggle (above canvas) */
.fit-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 0.95rem;
  font-weight: 500;
  background: var(--paper);
}

.fit-toggle button {
  background: transparent;
  border: none;
  padding: 0.5rem 1.1rem;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
  font-style: inherit;
  font-size: inherit;
  font-weight: inherit;
  border-right: 1px solid var(--line);
  min-height: 36px;
}

.fit-toggle button:last-child { border-right: none; }

.fit-toggle button.active {
  background: var(--ink);
  color: var(--paper);
}

.quality-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  font-weight: 400;
  background: var(--paper);
  margin-top: 0.75rem;
  align-self: center;
  text-transform: uppercase;
}

.quality-toggle button {
  background: transparent;
  border: none;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  color: var(--line);
  font-family: inherit;
  font-size: inherit;
  letter-spacing: inherit;
  border-right: 1px solid var(--line);
  min-height: 32px;
}

.quality-toggle button:last-child { border-right: none; }

.quality-toggle button.active {
  background: var(--ink);
  color: var(--paper);
}

/* Sidebar */
aside {
  background: var(--ink);
  color: var(--paper);
  padding: 2rem 1.75rem;
  position: relative;
  border-left: 1px solid var(--line);
}

@media (max-width: 900px) {
  aside {
    border-left: none;
    border-top: 1px solid var(--line);
    padding: 1.5rem var(--pad-x);
  }
}

aside::before {
  content: 'II.';
  position: absolute;
  top: 1rem;
  left: 1.5rem;
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 1rem;
  opacity: 0.65;
}

@media (max-width: 900px) {
  aside::before { left: var(--pad-x); }
}

.section-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0.78;
  margin-bottom: 0.5rem;
  margin-top: 1.5rem;
  display: block;
}

.section-label:first-of-type { margin-top: 2rem; }

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

@media (max-width: 480px) {
  .preset-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.preset-btn {
  background: transparent;
  border: 1px solid rgba(237, 228, 211, 0.45);
  color: var(--paper);
  padding: 0.7rem 0.5rem;
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
  min-height: 44px;
}

@media (hover: hover) {
  .preset-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
  }
}

.preset-btn.active {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.control-row { margin-bottom: 1.1rem; }

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.control-label .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  opacity: 0.88;
}

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

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--paper);
  opacity: 0.55;
}

input[type="range"]::-moz-range-track {
  height: 1px;
  background: var(--paper);
  opacity: 0.55;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: var(--accent);
  border: 2px solid var(--paper);
  border-radius: 0;
  margin-top: -11px;
  cursor: pointer;
  transform: rotate(45deg);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: var(--accent);
  border: 2px solid var(--paper);
  border-radius: 0;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.1rem;
  font-size: 1rem;
}

.toggle-switch {
  position: relative;
  width: 46px;
  height: 24px;
  background: rgba(237, 228, 211, 0.25);
  cursor: pointer;
  transition: background 0.2s;
  border: 1px solid rgba(237, 228, 211, 0.5);
}

.toggle-switch.on { background: var(--accent); border-color: var(--accent); }

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--paper);
  transition: left 0.2s;
}

.toggle-switch.on::after { left: 24px; }

.actions {
  margin-top: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.action-btn {
  background: var(--paper);
  color: var(--ink);
  border: none;
  padding: 0.95rem;
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
  min-height: 48px;
}

.action-btn.secondary {
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--paper);
}

@media (hover: hover) {
  .action-btn:hover { background: var(--accent); color: var(--paper); }
  .action-btn.secondary:hover { background: var(--paper); color: var(--ink); }
}

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

footer {
  padding: 1rem var(--pad-x);
  border-top: 1px solid var(--line);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--line);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--paper);
}

@media (max-width: 700px) {
  footer { font-size: 0.75rem; }
}

footer code {
  font-family: 'JetBrains Mono', monospace;
  font-style: normal;
  font-size: 0.75rem;
  background: var(--paper-dark);
  padding: 0.2rem 0.4rem;
}

.footer-link {
  font-style: italic;
  color: var(--line);
  text-decoration: none;
  border-bottom: 1px solid rgba(58, 42, 31, 0.4);
  padding-bottom: 1px;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}

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

.footer-meta {
  display: inline-flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.quality-indicator {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  background: rgba(26, 20, 16, 0.7);
  color: var(--paper);
  padding: 0.2rem 0.4rem;
  letter-spacing: 0.1em;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.quality-indicator.show { opacity: 1; }

/* ---------- Save modal (mobile long-press to save) ---------- */
.save-modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, 0.97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  opacity: 0;
  transition: opacity 0.25s;
  overflow-y: auto;
}

.save-modal.show { display: flex; opacity: 1; }

.save-modal-inner {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--paper);
}

.save-modal-img {
  max-width: min(90vw, 600px);
  max-height: 65vh;
  border: 1px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink), 4px 4px 0 var(--accent);
  /* iOS: allow long-press save */
  -webkit-touch-callout: default;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

.save-modal-instruction {
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 0.95rem;
  text-align: center;
  max-width: 90vw;
  line-height: 1.5;
  opacity: 0.85;
}

.save-modal-instruction small {
  display: block;
  margin-top: 0.35rem;
  font-family: 'JetBrains Mono', monospace;
  font-style: normal;
  font-size: 0.62rem;
  opacity: 0.55;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.save-modal-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}

.save-modal-actions button {
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--paper);
  padding: 0.7rem 1.25rem;
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 1rem;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s;
}

.save-modal-actions button.primary {
  background: var(--paper);
  color: var(--ink);
}

@media (hover: hover) {
  .save-modal-actions button:hover {
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
  }
}

input[type="file"] { display: none; }

/* ---------- Export progress overlay (Save Image 中の進捗表示) ---------- */
.export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.export-overlay.show { display: flex; opacity: 1; }

.export-overlay-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 8px 8px 0 var(--accent);
  padding: 2rem 2.5rem;
  min-width: min(360px, 88vw);
  max-width: 88vw;
  text-align: center;
}

.export-label {
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--ink);
  margin-bottom: 1.1rem;
  letter-spacing: 0.01em;
}

.export-progress-track {
  height: 4px;
  background: var(--paper-dark);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}

.export-progress-fill {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 0%;
  background: var(--accent);
  transition: width 0.18s ease-out;
}

.export-percent {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--line);
  margin-top: 0.7rem;
  letter-spacing: 0.18em;
  opacity: 0.75;
}
