:root {
  --bg: #121212;
  --surface: #1f1f1f;
  --surface-hi: #3a3a3c;
  --border: rgba(255, 255, 255, 0.15);
  --text: #f2f2f2;
  --text-dim: #9a9a9f;
  --accent: #0a84ff;
  --danger: #ff453a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* 左にキャンバス2枚を横に並べ、右のサイドバーに操作をまとめる */
.app {
  --side: clamp(220px, 24vw, 300px);
  --pad-x: clamp(16px, 2.2vw, 32px);
  --pad-y: clamp(12px, 2.7vh, 24px);
  --col-gap: clamp(16px, 2.2vw, 32px);
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr var(--side);
  grid-template-rows: auto 1fr;
  grid-template-areas: "panels header" "panels controls";
  column-gap: var(--col-gap);
  row-gap: 24px;
  padding: var(--pad-y) var(--pad-x);
}

header { grid-area: header; display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
.subtitle { font-size: 13px; margin: 0; color: var(--text-dim); }
.hint { margin: 0; font-size: 13px; line-height: 1.6; color: var(--text-dim); }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; width: 100%; }

button {
  font: inherit;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  white-space: nowrap;
}
.icon-button:hover { background: var(--surface-hi); }
.icon-button.danger { color: var(--danger); }
.icon-button:disabled, .icon-button.busy { opacity: 0.4; cursor: progress; pointer-events: none; }
.photo-button { position: relative; cursor: pointer; }
.photo-button input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }
.photo-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
header .icon-button { width: 100%; }
#undo, #reset, #clear, #share { flex: 1 1 calc(50% - 5px); }

.segmented {
  flex: 1 1 100%;
  display: flex;
  background: var(--surface);
  border-radius: 9px;
  padding: 2px;
}
.segmented button {
  flex: 1;
  color: var(--text);
  font-size: 13px;
  padding: 8px;
  gap: 6px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.segmented button[aria-checked="true"] { background: var(--surface-hi); }

.toggle {
  flex: 1 1 100%;
  white-space: nowrap;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
}
.toggle:hover { background: var(--surface-hi); }
.toggle[aria-pressed="true"] { background: var(--accent); color: white; }

.panels {
  grid-area: panels;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  /* 横は「画面幅 − サイドバー − 余白 − 矢印」の半分、縦は画面の高さに収まる大きさ */
  --panel: min(
    calc((100vw - var(--side) - 2 * var(--pad-x) - var(--col-gap) - 2 * 16px - 20px) / 2),
    calc(100dvh - 2 * var(--pad-y) - 28px)
  );
}
.arrow::before { content: "→"; color: var(--text-dim); font-size: 20px; }

.panel { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.panel canvas {
  width: var(--panel);
  height: var(--panel);
  background: black;
  border-radius: 10px;
  outline: 1px solid var(--border);
  image-rendering: pixelated;
  display: block;
}
.panel canvas.drawable { touch-action: none; cursor: crosshair; }
figcaption { font-size: 13px; color: var(--text-dim); text-align: center; }

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

.sliders { flex-direction: column; align-items: stretch; gap: 12px; }
.slider { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; }
.slider svg { width: 16px; height: 16px; flex: none; }
.slider .label { width: 2.5em; flex: none; }
.slider input { flex: 1; accent-color: var(--accent); min-width: 0; }

.presets h2 { font-size: 12px; font-weight: 600; color: var(--text-dim); margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  color: var(--text);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}
.chip:hover { background: var(--surface-hi); }

.site-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.site-footer p { margin: 0 0 6px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.site-footer a { color: var(--text-dim); text-decoration: none; }
.site-footer a:hover { color: var(--text); text-decoration: underline; }
