/* ══════════════════════════════════════════════
   Snapedit — Global Styles (Dark Theme)
   ══════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3248;
  --accent:    #6c63ff;
  --accent-h:  #8b85ff;
  --danger:    #e05252;
  --success:   #52c97a;
  --warning:   #f0a04a;
  --text:      #e8eaf6;
  --text-muted:#8b92b8;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
  --font:      'Inter', 'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); }

/* ── Scrollbar ───────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Header ──────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}
.header-logo span { color: var(--accent); }
.header-actions { display: flex; gap: 10px; align-items: center; }

/* ── HUB導線（全アプリ統一） ─────────────────── */
.header-right { display: flex; gap: 16px; align-items: center; }
.manual-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.manual-link:hover { color: var(--accent); text-decoration: underline; }

/* ヘッダー右側のユーザーメアド表示（auth.js から差し込み） */
.header-user-email {
  color: var(--text-muted);
  font-size: 0.82rem;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success   { background: var(--success); color: #000; }
.btn-sm        { padding: 5px 11px; font-size: 0.78rem; }
.btn-icon      { padding: 7px; border-radius: 8px; }
.btn:disabled  { opacity: .45; cursor: not-allowed; }

/* ── Toast ───────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slideIn .25s ease;
  max-width: 320px;
}
.toast-success { background: var(--success); color: #000; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--accent);  color: #fff; }
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ── Loading spinner ─────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: min(440px, 95vw);
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 1.1rem; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ══════════════════════════════════════════════
   LOGIN PAGE
   ══════════════════════════════════════════════ */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 8px;
}
.login-logo span { color: var(--accent); }
.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 32px;
}
.login-tabs {
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}
.login-tab {
  flex: 1; padding: 8px;
  text-align: center;
  border-radius: 7px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
  border: none;
  background: transparent;
}
.login-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ── Form ────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color .15s;
  outline: none;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.form-submit {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
}
.form-error {
  background: rgba(224,82,82,.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-top: 12px;
  display: none;
}

/* ══════════════════════════════════════════════
   GALLERY PAGE
   ══════════════════════════════════════════════ */
.gallery-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px;
}
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.gallery-header h1 { font-size: 1.4rem; font-weight: 700; }
.gallery-stats { color: var(--text-muted); font-size: 0.85rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}
.gallery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: transform .15s, border-color .15s;
  cursor: pointer;
  position: relative;
}
.gallery-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}
.gallery-card-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--surface2);
  display: block;
}
.gallery-card-thumb-empty {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 2rem;
}
.gallery-card-body {
  padding: 12px 14px;
}
.gallery-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.gallery-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.gallery-card-actions {
  display: flex;
  gap: 6px;
  padding: 0 14px 12px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-kept  { background: rgba(82,201,122,.15); color: var(--success); border: 1px solid var(--success); }
.badge-exp   { background: rgba(240,160,74,.15);  color: var(--warning); border: 1px solid var(--warning); }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  grid-column: 1/-1;
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h2 { font-size: 1.1rem; color: var(--text); margin-bottom: 8px; }

/* ══════════════════════════════════════════════
   EDITOR PAGE
   ══════════════════════════════════════════════ */
/* editor.html 専用: デスクトップでは縦スクロール禁止（サイドバー固定で全部見える設計） */
.editor-page { overflow: hidden; }

.editor-layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────── */
.editor-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Tools */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
}
.tool-btn:hover  { border-color: var(--accent); color: var(--text); }
.tool-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(108,99,255,.12); }
.tool-icon { font-size: 1.25rem; }

/* Color picker */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.color-label { font-size: 0.78rem; color: var(--text-muted); flex: 1; }
.color-swatch {
  width: 32px; height: 32px;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.color-swatch input[type="color"] {
  position: absolute; inset: 0;
  opacity: 0;
  width: 100%; height: 100%;
  cursor: pointer;
}

/* Slider */
.slider-row { margin-bottom: 10px; }
.slider-row label { font-size: 0.78rem; color: var(--text-muted); display: flex; justify-content: space-between; }
.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  margin-top: 8px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.toggle {
  position: relative;
  width: 36px; height: 20px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* Font size input */
.number-input {
  width: 60px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 0.85rem;
  text-align: center;
  outline: none;
}
.number-input:focus { border-color: var(--accent); }

/* Select */
.form-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  margin-bottom: 8px;
}
.form-select:focus { border-color: var(--accent); }

/* Sidebar action buttons */
.sidebar-btn-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
}

/* ── Canvas area ─────────────────────────── */
.editor-canvas-area {
  flex: 1;
  overflow: auto;
  background: #181c2b;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
}
.canvas-wrapper {
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
#editor-canvas {
  display: block;
  cursor: crosshair;
}

/* ── Right panel ─────────────────────────── */
.editor-right {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
}
.editor-right-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.image-info-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.image-info-row span:last-child { color: var(--text); }

/* share URL area */
.share-url-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 12px;
}
.share-url-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 6px; }
.share-url-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  outline: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Editor meta info strip ──────────────── */
.editor-status {
  position: fixed;
  bottom: 0; left: 240px; right: 220px;
  height: 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  font-size: 0.72rem;
  color: var(--text-muted);
  z-index: 10;
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ══════════════════════════════════════════════
   RESPONSIVE  ← v2 (2026-06-01: スマホ全面対応)
   ══════════════════════════════════════════════ */

/* ── タブレット未満（〜900px）：エディタを縦並びへ ── */
@media (max-width: 900px) {
  /* エディタ：両サイドバーを「消す」のではなく「縦並び表示」に */
  .editor-page { overflow: auto; }
  .editor-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .editor-sidebar,
  .editor-right {
    width: 100%;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
  }
  .editor-right {
    border-bottom: none;
    border-top: 1px solid var(--border);
  }
  .editor-canvas-area {
    padding: 8px;
    min-height: 45vh;
    align-items: center;
    overflow: auto;            /* 収まらない時はスクロール可能に */
  }
  /* canvas（fabric.js）の表示縮小は editor.js の fitCanvasToScreen() が
     コンテナと両canvasに明示pxを設定して行う（CSSで height:auto を当てると
     fabric の絶対配置canvasにより .canvas-container が高さ0に潰れるため触らない）。 */
  .canvas-wrapper { max-width: 100%; }
  /* ツールを横3列に */
  .tool-grid { grid-template-columns: repeat(3, 1fr); }
  /* ボトム固定のステータスバー：横幅フル */
  .editor-status {
    position: relative;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
  }
  /* サイドバー底部固定だったボタン群は普通の位置で */
  .sidebar-btn-group { margin-top: 0; }

  /* スマホでの表示順序：画像(キャンバス)を最初に、ツールを後に
     HTML順序は「左サイドバー → キャンバス → 右パネル」だが
     スマホでは「キャンバス → ツール → 情報」の順が自然 */
  .editor-canvas-area { order: 1; }
  .editor-sidebar      { order: 2; }
  .editor-right        { order: 3; }
}

/* ── スマホ（〜700px）：ヘッダー詰め、フォント縮小 ── */
@media (max-width: 700px) {
  .header { padding: 0 12px; }
  .header-right { gap: 10px; }
  .manual-link { font-size: 0.72rem; }
  .header-user-email { max-width: 120px; font-size: 0.72rem; }
  .gallery-wrap { padding: 20px 14px; }
  .gallery-header { gap: 10px; }
  .gallery-header h1 { font-size: 1.2rem; }
  /* タッチターゲットを少し大きく */
  .btn-sm { padding: 7px 12px; font-size: 0.82rem; }
}

/* ── スマホ縦（〜600px）：ギャラリーは2列、ログイン詰め ── */
@media (max-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .login-card { padding: 28px 20px; }
  /* manual.html の grid2 もスマホでは1列 */
  .m-sec .grid2 { grid-template-columns: 1fr !important; }
}

/* ── 小型スマホ（〜480px）：メアド非表示・ロゴ縮小 ── */
@media (max-width: 480px) {
  .header { padding: 0 10px; height: 52px; }
  .header-logo { font-size: 1.05rem; }
  .header-right { gap: 8px; }
  .manual-link { font-size: 0.65rem; }
  /* メアドは小型では完全に隠す（ログアウトボタンだけ残す） */
  .header-user-email { display: none; }
  /* ギャラリーカードのボタンも詰める */
  .gallery-card-actions { gap: 4px; padding: 0 10px 10px; }
  .gallery-card-body { padding: 10px 12px; }
}

/* ── 極小（〜400px）：ギャラリー1列 ── */
@media (max-width: 400px) {
  .gallery-grid { grid-template-columns: 1fr; }
}
