/* =========================================================
   PS1風ローポリ画像変換 - スタイル
   ダークテーマ / Apple風シンプルデザイン
   背景 #111111 / カード #1b1b1b / アクセント #4FC3F7 / 角丸16px
   ========================================================= */

/* ---- カラーや共通値を変数化（保守しやすく） ---- */
:root {
  --bg:        #111111;
  --card:      #1b1b1b;
  --card-2:    #232323;
  --accent:    #4FC3F7;
  --accent-d:  #29A7E0;
  --text:      #e8e8e8;
  --text-sub:  #a0a0a0;
  --border:    #2c2c2c;
  --radius:    16px;
  --radius-sm: 10px;
  --shadow:    0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* ---- リセット ---- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* ---- レイアウト共通 ---- */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---- ヘッダー ---- */
.site-header {
  padding: 28px 0 18px;
  border-bottom: 1px solid var(--border);
}

.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}
.back-link:hover { text-decoration: underline; }

.site-title {
  margin: 0 0 6px;
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-subtitle {
  margin: 0;
  color: var(--text-sub);
  font-size: 15px;
}

/* ---- カード ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 20px 0;
}

.card-title {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
}

.info-card .info-list { margin: 0; }

.info-list {
  margin: 10px 0;
  padding-left: 22px;
}
.info-list li { margin-bottom: 6px; }

.privacy-note {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--card-2);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-sub);
}

/* ---- メッセージ ---- */
.message {
  margin: 16px 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.message.error   { background: #3a1d1d; color: #ff9b9b; border: 1px solid #5a2a2a; }
.message.success { background: #16301f; color: #8fe6b0; border: 1px solid #234d33; }
.message.info    { background: #142a33; color: #9bdcff; border: 1px solid #214957; }

/* ---- ドロップゾーン ---- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 180px;
  padding: 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--card-2);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s, transform .05s;
}
.dropzone:hover,
.dropzone:focus {
  border-color: var(--accent);
  outline: none;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: #14323f;
}
.dropzone-icon { font-size: 42px; }
.dropzone-text { font-size: 16px; font-weight: 600; }
.dropzone-sub  { font-size: 13px; color: var(--text-sub); }

/* 視覚的に隠す（アクセシビリティ維持） */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ---- プレビュー ---- */
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.preview-head .card-title { margin-bottom: 0; }

.preview-tools { display: flex; gap: 8px; flex-wrap: wrap; }

.preview-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}
/* 比較表示OFF時：変換後のみ表示 */
.preview-wrap.single { grid-template-columns: 1fr; }
.preview-wrap.single .preview-box.is-original { display: none; }

.preview-box {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.preview-label {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 600;
}

.preview-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  /* 透明背景が分かるチェッカー */
  background-image:
    linear-gradient(45deg, #1a1a1a 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1a 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  border-radius: 8px;
  overflow: hidden;
}

.preview-canvas {
  max-width: 100%;
  height: auto;
  display: none;          /* 画像読込後に表示 */
  /* PS1感を出すためプレビューでもドット保持 */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.placeholder {
  margin: 0;
  color: var(--text-sub);
  font-size: 14px;
}

/* ローディングオーバーレイ */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(17, 17, 17, 0.72);
  color: var(--text);
  font-size: 14px;
  border-radius: 8px;
}
.loading-overlay[hidden] { display: none; }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- プリセット ---- */
.preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---- スライダー ---- */
.slider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 22px;
}

.slider-row { display: flex; flex-direction: column; gap: 6px; }
.slider-row label {
  font-size: 14px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.slider-val {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--card-2);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0d2733;
  box-shadow: var(--shadow-sm);
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0d2733;
}

/* ---- トグル群 ---- */
.toggle-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 16px;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.toggle input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover { background: #2c2c2c; }
.btn:active { transform: translateY(1px); }

.btn-small { padding: 8px 12px; font-size: 13px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07222e;
}
.btn-primary:hover { background: var(--accent-d); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #07222e;
}
.btn-accent:hover { background: var(--accent-d); }

/* プリセット選択中 */
.preset-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* 無効状態 */
.btn.disabled,
.btn[aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
}

/* 比較トグルON時の見た目 */
#compareBtn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- 操作 / ダウンロード ---- */
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.dl-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 150px;
}
.dl-field label { font-size: 14px; }

.select {
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* JPEGなど品質非対応時に隠す */
.dl-field.hidden { display: none; }

/* ---- SEOセクション ---- */
.seo-section p { color: var(--text-sub); }
.seo-section .info-list { color: var(--text); }

/* ---- フッター ---- */
.site-footer {
  margin-top: 30px;
  padding: 22px 0;
  border-top: 1px solid var(--border);
  color: var(--text-sub);
  font-size: 13px;
  text-align: center;
}

/* ---- 全画面表示モード ---- */
body.fullscreen-mode {
  overflow: hidden;
}
body.fullscreen-mode .preview-inner :is(canvas) {
  cursor: zoom-out;
}
.fs-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  background: rgba(0, 0, 0, 0.94);
  padding: 20px;
}
.fs-overlay canvas {
  max-width: 96vw;
  max-height: 86vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: var(--shadow);
}
.fs-close {
  position: absolute;
  top: 16px; right: 20px;
}

/* ---- レスポンシブ ---- */
@media (max-width: 640px) {
  .preview-wrap { grid-template-columns: 1fr; }
  .card { padding: 18px; }
}

/* ---- 輪郭線の色選択行 ---- */
.wire-color-row {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.wire-color-row.hidden { display: none; }
.wire-color-row input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-2);
  cursor: pointer;
}
