/* ====== Gazou — styles ====== */
:root {
  --bg: #0e1116;
  --bg2: #151a22;
  --panel: #171d26;
  --panel2: #1d2430;
  --border: #29313f;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --accent: #5b8cff;
  --accent-hover: #6f9aff;
  --danger: #ff5b5b;
  --radius: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* text for screen readers / search engines only */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ====== topbar ====== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 50px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
  user-select: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.brand svg {
  stroke: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

/* ====== buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: #242d3b;
  border-color: #394355;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.mini {
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 6px;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:hover:not(:disabled) {
  background: var(--panel2);
  border-color: var(--border);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ====== workspace ====== */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ====== toolbar ====== */
.toolbar {
  flex: none;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 3px;
  padding: 6px 6px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  user-select: none;
}

.tool-sep {
  flex: none;
  width: 26px;
  height: 1px;
  margin: 2px auto;
  background: var(--border);
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.tool-btn:hover {
  background: var(--panel2);
  color: var(--text);
}

.tool-btn.active {
  background: rgba(91, 140, 255, 0.16);
  border-color: rgba(91, 140, 255, 0.5);
  color: var(--accent);
}

.tool-btn svg {
  width: 20px;
  height: 20px;
}

/* ====== stage ====== */
.stage-outer {
  flex: 1;
  position: relative;
  min-width: 0;
  background: var(--bg);
}

.stage {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  overscroll-behavior: contain;
  /* gestures may start on the gray area outside the canvas — without this,
     touch drags there are claimed by native scrolling and cancelled */
  touch-action: none;
}

.canvas-wrap {
  position: relative;
  margin: auto;
  flex: none;
  box-shadow: var(--shadow);
  background: repeating-conic-gradient(#252b36 0% 25%, #1c212b 0% 50%) 0 0 /
    16px 16px;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#overlay {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.stage.cursor-pan {
  cursor: grab;
}

.stage.cursor-draw {
  cursor: crosshair;
}

/* after cursor-draw: same specificity, panning must win mid-gesture */
.stage.cursor-panning {
  cursor: grabbing;
}

.stage.cursor-text #overlay {
  cursor: text;
}

/* text editor (created by JS) */
.text-editor {
  position: absolute;
  min-width: 1ch;
  white-space: pre;
  line-height: 1.3;
  outline: 1px dashed rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
  background: rgba(0, 0, 0, 0.15);
  caret-color: currentColor;
  z-index: 5;
}

/* ====== empty state ====== */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 56px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  color: var(--text-dim);
  text-align: center;
}

.empty-box svg {
  color: #3d475a;
  stroke-width: 1.4;
}

.empty-title {
  margin: 6px 0 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.empty-sub {
  margin: 0;
  font-size: 13px;
}

.empty-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.empty-note {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: #8f99a8;
}

/* ====== crop bar ====== */
.crop-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(23, 29, 38, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 6;
  backdrop-filter: blur(4px);
}

.crop-bar.bottom {
  top: auto;
  bottom: 12px;
}

.crop-bar span {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 13px;
}

/* ====== drop hint ====== */
.drop-hint {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 17, 22, 0.82);
  pointer-events: none;
}

.drop-hint > div {
  padding: 40px 64px;
  border: 3px dashed var(--accent);
  border-radius: 20px;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

/* ====== side panel ====== */
.panel {
  flex: none;
  width: 280px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  user-select: none;
}

.panel details {
  border-bottom: 1px solid var(--border);
}

.panel summary {
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}

.panel summary::-webkit-details-marker {
  display: none;
}

.panel summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.panel details:not([open]) summary::after {
  transform: rotate(-45deg);
}

.sec {
  padding: 2px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

.note {
  margin: 0;
  font-size: 11px;
  color: #8f99a8;
}

.sel-note {
  padding: 6px 8px;
  border-radius: 6px;
  line-height: 1.5;
  border: 1px solid var(--border);
}

/* lit up only while a selection is actually active */
.sel-note.active {
  color: var(--accent);
  background: rgba(91, 140, 255, 0.12);
  border-color: rgba(91, 140, 255, 0.35);
}

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.opt-row select {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}

.opt-row input[type="color"] {
  width: 44px;
  height: 28px;
  padding: 2px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.opt-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.name-row input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

.slider-row {
  display: grid;
  grid-template-columns: 72px 1fr 30px;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.slider-name {
  font-size: 11.5px;
  white-space: nowrap;
  color: var(--text-dim);
}

.slider-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 12px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  transition: transform 0.1s;
}

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

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.chip:hover {
  color: var(--text);
  border-color: #394355;
}

.chip.active {
  background: rgba(91, 140, 255, 0.16);
  border-color: rgba(91, 140, 255, 0.5);
  color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn {
  flex: 1;
}

.btn-row.wrap4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-row.wrap4 .btn {
  padding: 7px 6px;
  font-size: 12.5px;
}

.sub-label {
  margin: 4px 0 -2px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
}

.resize-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.resize-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.resize-row input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
}

.resize-row .x {
  padding-bottom: 8px;
  color: var(--text-dim);
}

/* ====== statusbar ====== */
.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 34px;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}

.stat-left {
  display: flex;
  gap: 16px;
  font-variant-numeric: tabular-nums;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-controls .icon-btn {
  width: 26px;
  height: 26px;
}

.zoom-controls .icon-btn svg {
  width: 14px;
  height: 14px;
}

.zoom-label {
  min-width: 46px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ====== no-image state ====== */
body.no-image .needs-image-area {
  opacity: 0.45;
  pointer-events: none;
}

/* ====== modal ====== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.6);
  backdrop-filter: blur(2px);
}

.modal {
  width: min(400px, calc(100vw - 48px));
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.modal p {
  margin: 0 0 16px;
  line-height: 1.6;
}

/* ====== toasts ====== */
#toasts {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  background: rgba(29, 36, 48, 0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 0.2s ease-out;
}

.toast.out {
  animation: toast-out 0.25s ease-in forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ====== responsive ====== */
@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
  }

  .toolbar {
    order: 1;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 6px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .tool-sep {
    width: 1px;
    height: 26px;
    margin: auto 2px;
  }

  .crop-bar {
    max-width: calc(100% - 24px);
    flex-wrap: wrap;
    justify-content: center;
  }

  .stage-outer {
    order: 2;
    min-height: 0;
  }

  .panel {
    order: 3;
    width: auto;
    max-height: 38dvh;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .topbar .btn span {
    display: none;
  }

  .empty-box {
    padding: 32px 24px;
  }
}
