/* Editor variables */
:root {
  --editor-accent: #0088ff;
  --editor-accent-strong: #0c7bec;
  --editor-surface: rgba(230, 230, 230, 0.9);
  --editor-shadow: 0 16px 32px rgba(0, 0, 0, 0.14);
}

/* Editor layout */
.editor {
  position: fixed;
  inset: 0;
  padding:16px 16px 24px;
  background: url('../img/editor_bg.png') center center / cover no-repeat;
  backdrop-filter: blur(6px);
  background-color: #ccc;
  z-index: 1000;
  display: none;
  overflow-y: auto;
}

.editor.no-scroll {
  overflow: hidden !important;
  height: 100%;
}

@media (orientation: landscape) {
  .editor {
    padding: 16px 8px;
    overflow-y: scroll;
    height: 100svh;
    max-height: 100svh;
  }
}

.editor__content {
  position: relative;
  width: min(440px, 100%);
  margin: 0 auto;
  display: block;
  color: #1c1c1c;
}

@media (orientation: landscape) {
  .editor__content {
    width: 100%;
    height: 100%;
    max-height: 100%;
    display: grid;
    grid-template-columns: auto 1fr 140px;
    grid-template-rows: 1fr;
    column-gap: 16px;
    align-items: stretch;
    overflow: visible;
  }
}

/* Back button */
.editor__back {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--editor-accent), #0d9dff);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  box-shadow: 0 6px 16px rgba(0, 136, 255, 0.28);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  max-width: 180px;
  min-height: 0;
}

#editor-close {
  margin-bottom: 16px;
}

@media (orientation: landscape) {
  .editor__back {
    flex-shrink: 0;
  }
}

.editor__back:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 136, 255, 0.34);
}

.editor__back:active {
  transform: translateY(0);
  box-shadow: 0 5px 12px rgba(0, 136, 255, 0.28);
}

/* Visual area */
.editor__visual {
  width: 100%;
  height: auto;
  margin-bottom: 40px;
}

@media (orientation: landscape) {
  .editor__visual {
    height: 100%;
    max-height: 100%;
    align-self: stretch;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.editor__image-wrap {
  position: relative;
  width: 100%;
  height: auto;
  touch-action: none;
}

.editor__content[data-editor-orientation='portrait'] .editor__image-wrap {
  width: 100%;
  margin: 0 auto;
}

/* 縦型画像を表示する縦向きレイアウト時のみ余白を多めに確保 */
body.vertical .editor__content[data-editor-orientation='portrait'] .editor__image-wrap {
  width: 85%;
  max-width: 85%;
}

@media (orientation: landscape) {
  .editor__image-wrap {
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
    flex-shrink: 1;
    margin: 0 auto;
  }
}

.editor__image-wrap img {
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

@media (orientation: landscape) {
  .editor__image-wrap img {
    width: auto;
    height: 100%;
    max-height: 100%;
  }
}

.editor__image-wrap .mirror {
  transform: scale(-1, 1);
  transform-origin: center;
}

#editor-preview {
  display: block;
  margin: 0 auto;
  /* プレビュー上はジェスチャー優先 */
  touch-action: none;
}

/* Crop overlay */
.editor__crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none; /* イベントは子のrect/handleで */
}
.editor__crop-rect {
  position: absolute;
  border: 2px dashed var(--editor-accent);
  background: rgba(0, 136, 255, 0.08);
  pointer-events: auto;
  touch-action: none; /* ドラッグ時にスクロールさせない */
}
.editor__crop-overlay.mirror .editor__crop-rect,
.editor__crop-overlay.mirror {
  transform: scale(-1, 1);
  transform-origin: center;
}
.editor__crop-rect .editor__crop-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  background: var(--editor-accent);
  border: 2px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  touch-action: none; /* つまみ操作でスクロールしない */
}
.editor__crop-rect .editor__crop-handle::before {
  content: '';
  position: absolute;
  inset: -10px; /* 視覚サイズはそのまま、ヒット領域だけ拡大 */
  background: transparent;
  pointer-events: auto;
}
.editor__crop-handle--tl {
  top: 0;
  left: 0;
}
.editor__crop-handle--tr {
  top: 0;
  left: 100%;
}
.editor__crop-handle--bl {
  top: 100%;
  left: 0;
}
.editor__crop-handle--br {
  top: 100%;
  left: 100%;
}

/* Controls */
.editor__controls {
  padding: 0 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

@media (orientation: landscape) {
  .editor__controls {
    width: 140px;
    justify-content: space-between;
    align-self: stretch;
  }
}

.editor__sliders {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, auto);
  column-gap: 12px;
  row-gap: 10px;
}

@media (orientation: landscape) {
  .editor__sliders {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    column-gap: 0;
    row-gap: 8px;
  }
}

.editor__controls .editor__control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.editor__controls .editor__control p {
  margin: 0;
  min-width: 0;
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: #373737;
  font-weight: 500;
}

.editor__controls .editor__slider {
  width: 100%;
  height: 30px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  --progress-width: 50%;
}

.editor__controls .editor__slider:focus-visible {
  outline: 2px solid rgba(0, 136, 255, 0.3);
  outline-offset: 2px;
  border-radius: 999px;
}

.editor__controls .editor__slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(
      to right,
      var(--editor-accent) 0%,
      var(--editor-accent) var(--progress-width, 0%),
      rgba(0, 0, 0, 0.16) var(--progress-width, 0%),
      rgba(0, 0, 0, 0.12) 100%
    ),
    radial-gradient(circle, rgba(80, 80, 80, 0.28) 1px, transparent 1px);
  background-repeat: no-repeat, repeat-x;
  background-size: 100% 6px, 20% 6px;
  background-position: center, center;
}

.editor__controls .editor__slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(
      to right,
      var(--editor-accent) 0%,
      var(--editor-accent) var(--progress-width, 0%),
      rgba(0, 0, 0, 0.16) var(--progress-width, 0%),
      rgba(0, 0, 0, 0.12) 100%
    ),
    radial-gradient(circle, rgba(80, 80, 80, 0.28) 1px, transparent 1px);
  background-repeat: no-repeat, repeat-x;
  background-size: 100% 6px, 20% 6px;
  background-position: center, center;
}

.editor__controls .editor__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 38px;
  height: 24px;
  background: #fff;
  border: none;
  border-radius: 100px;
  box-shadow: 0 0.5px 4px 0 rgba(0, 0, 0, 0.12),
    0 6px 13px 0 rgba(0, 0, 0, 0.12);
  margin-top: -9px;
}

.editor__controls .editor__slider::-moz-range-thumb {
  width: 38px;
  height: 24px;
  background: #fff;
  border: none;
  border-radius: 100px;
  box-shadow: 0 0.5px 4px 0 rgba(0, 0, 0, 0.12),
    0 6px 13px 0 rgba(0, 0, 0, 0.12);
}

/* Actions */
.editor__actions {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (orientation: portrait) {
  .editor__actions {
    display: grid;
    grid-template-columns: 3fr 2fr;
    grid-template-rows: auto auto;
    gap: 16px 8px;
  }

  #editor-toggle-crop {
    grid-row: 1;
    grid-column: 1;
  }

  #editor-reset {
    grid-row: 1;
    grid-column: 2;
  }

  #editor-post {
    grid-row: 2;
    grid-column: 1 / span 2;
  }
}

.editor__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease,
    border-color 0.2s ease;
  font-family: 'Noto Sans JP', sans-serif;
  min-height: 0;
}

.editor__button:hover {
  transform: translateY(-1px);
}

.editor__button:active {
  transform: translateY(0);
}

.editor__button--primary {
  background: linear-gradient(135deg, var(--editor-accent), #0073ff);
  color: #fff;
  box-shadow: 0 12px 24px rgba(0, 136, 255, 0.3);
  border: none;
}

@media (orientation: landscape) {
  .editor__button--primary {
    box-shadow: 0 2px 12px rgba(0, 136, 255, 0.3);
  }
}

.editor__button--outline {
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid var(--editor-accent);
  color: var(--editor-accent);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

@media (orientation: landscape) {
  .editor__button--outline {
    position: absolute;
    bottom: 72px;
    left: 0;
    width: max-content;
    background-color: rgba(255, 255, 255, 0.6);
  }
}

.editor__button--secondary {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: var(--editor-accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

@media (orientation: landscape) {
  .editor__button--secondary {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 130px;
    background-color: rgba(255, 255, 255, 0.6);
  }
}

.editor__button.is-disabled,
.editor__button:disabled {
  opacity: 0.4;
  background: #cfd7e3;
  color: #5c6a7b;
  border-color: rgba(0, 0, 0, 0.05);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.editor__hint {
  font-size: 16px;
  color: #5c6a7b;
  text-align: center;
  line-height: 1.4;
  grid-column: 1 / span 2;
}

@media (orientation: landscape) {
  .editor__hint {
    position: absolute;
    bottom: 160px;
    left: 0;
    text-align: left;
    width: 160px;
    max-width: 480px;
  }
}

/* HQ overlay */
.editor__hq-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(6px);
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.editor__hq-overlay-inner {
  background: #ffffff;
  color: #1f3557;
  padding: 16px 24px;
  border-radius: 12px;
  text-align: center;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.editor__spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(0, 136, 255, 0.25);
  border-top-color: #0c7bec;
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin 1s linear infinite;
}

.editor__msg {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* HQ status */
.editor__hq-status {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 3000;
  font-size: 14px;
  line-height: 1.3;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.editor__hq-status--error {
  background: #b00020;
}
