:root {
  color-scheme: light;
  --bg1: #ffe1ec;
  --bg2: #d9f2ff;
  --card: #ffffffee;
  --ink: #2c2440;
  --sub: #6b6280;
  --accent: #ff6fa5;
  --accent2: #4fb6ff;
  --btn: #f4f1fb;
  --btn-ink: #443a5c;
  --btn-border: #ded4f2;
  --lock-on: #ffb84d;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(80, 40, 90, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 20% 0%, var(--bg2), transparent 55%),
              radial-gradient(circle at 85% 15%, var(--bg1), transparent 50%),
              #fbf7ff;
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior-y: contain;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.header {
  text-align: center;
  margin-bottom: 12px;
}
.header h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.header .sub {
  margin: 0;
  color: var(--sub);
  font-size: 0.9rem;
}

.stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-height: 240px;
}

#glcanvas {
  touch-action: none;
  border-radius: 12px;
  display: block;
  cursor: grab;
  background: repeating-conic-gradient(#f3eefb 0% 25%, #ffffff 0% 50%) 0 0 / 24px 24px;
}
#glcanvas.grabbing { cursor: grabbing; }

.drop-hint {
  position: absolute;
  inset: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--sub);
  font-size: 0.95rem;
  border: 2px dashed #d9cdf0;
  border-radius: 12px;
  pointer-events: none;
  background: rgba(255,255,255,0.55);
  line-height: 1.6;
}
.drop-hint.hidden { display: none; }

.controls {
  margin-top: 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 10px;
}
.row:last-child { margin-bottom: 0; }

.btn {
  appearance: none;
  border: 1px solid var(--btn-border);
  background: var(--btn);
  color: var(--btn-ink);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn:hover { box-shadow: 0 2px 10px rgba(80,40,90,0.12); }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
}

.btn.primary.video {
  background: linear-gradient(135deg, #8a63ff, #4fb6ff);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.btn.toggle[aria-pressed="true"] {
  background: var(--lock-on);
  color: #fff;
  border-color: transparent;
}

.file-btn { position: relative; }

.slider-row {
  align-items: center;
  gap: 10px;
  color: var(--sub);
  font-size: 0.85rem;
}
.slider-row input[type="range"] {
  flex: 1;
  max-width: 260px;
  accent-color: var(--accent);
}

.privacy {
  margin: 16px 4px 0;
  font-size: 0.78rem;
  color: var(--sub);
  text-align: center;
  line-height: 1.6;
}

.footer {
  margin-top: 22px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--sub);
}
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

@media (max-width: 420px) {
  .header h1 { font-size: 1.25rem; }
  .btn { font-size: 0.85rem; padding: 9px 12px; }
}

/* ---------- トリミングモーダル ---------- */
.crop-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 30, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.crop-modal.hidden { display: none; }

.crop-card {
  background: #fff;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 94vw;
}

.crop-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.crop-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  touch-action: none;
}
.crop-stage img {
  display: block;
  max-width: 82vw;
  max-height: 52vh;
  width: auto;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 4px;
}

.crop-box {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.45);
  cursor: move;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 26px;
  height: 26px;
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  touch-action: none;
}
.crop-handle::before {
  /* タップしやすいように見た目より広い当たり判定を確保 */
  content: "";
  position: absolute;
  inset: -14px;
}
.crop-handle[data-corner="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.crop-handle[data-corner="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.crop-handle[data-corner="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.crop-handle[data-corner="se"] { left: 100%; top: 100%; cursor: nwse-resize; }

.crop-actions {
  display: flex;
  gap: 10px;
}
