:root {
  --bg: #0b0c0f;
  --panel: #12141a;
  --muted: #9aa0a6;
  --text: #e8eaed;
  --accent: #6dc7ff;
  --accent-2: #7bf1a8;
  --border: #2a2f3a;
  --ring: #5a97ff;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP",
    sans-serif;
  background: linear-gradient(180deg, #0b0c0f 0%, #0f1420 100%);
  color: var(--text);
}

.app-header {
  text-align: center;
  padding: 32px 16px 16px;
}
.app-header h1 {
  margin: 0 0 8px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.sub {
  margin: 0;
  color: var(--muted);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 6px;
}
.field label {
  font-weight: 600;
}
.note {
  color: var(--muted);
}
.mono {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #1a2230;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}
.btn:hover {
  outline: 2px solid rgba(255, 255, 255, 0.06);
}
.btn:focus {
  outline: 3px solid var(--ring);
}
.btn-primary {
  background: linear-gradient(180deg, #2a7fff, #1b5fff);
  border-color: transparent;
}
.btn-secondary {
  background: #192132;
}

.dropzone {
  display: grid;
  place-items: center;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin: 16px 0;
  color: var(--muted);
  transition: border-color 0.15s ease, background 0.15s ease;
  background: rgba(255, 255, 255, 0.02);
}
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(109, 199, 255, 0.08);
}
.dropzone:focus {
  outline: 3px solid var(--ring);
}

.progress {
  min-height: 24px;
  margin-bottom: 8px;
  color: var(--muted);
}

.preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.card .meta {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}
.card .meta .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .body {
  padding: 8px;
  display: grid;
  gap: 8px;
}
.card img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #0b0c0f;
}
.card .stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.card .actions {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.card .actions .btn {
  padding: 8px 10px;
}
.app-footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
}
.muted {
  color: var(--muted);
}
.hidden {
  display: none !important;
}

/* === モーダル全体 === */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none; /* JSで制御 */
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 20px;
}

/* === モーダル内のコンテナ === */
#modal-content {
  position: relative;
  max-width: 95vw;
  max-height: 98vh; /* ← 95vh から 98vh に拡大 */
  display: flex;
  justify-content: center;
  align-items: center;
}

/* === モーダル内の画像 === */
.modal img {
  max-width: 95%;
  max-height: 95vh; /* ← 縦方向ほぼ全画面まで拡大 */
  object-fit: contain;
  transition: opacity 0.3s ease;
}
/* === ラベル（元画像 / 圧縮後） === */
#modal .label {
  position: absolute;
  top: 10px;
  right: 12px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
  user-select: none;
}

/* 閉じるボタン */
#modal .close-btn {
  position: absolute;
  top: 10px;
  left: 12px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}
/* --- カード内の横はみ出し対策 --- */
.card .meta,
.card .actions {
  min-width: 0; /* flex内の子要素を縮められるようにする */
}

.card .meta .name {
  min-width: 0; /* 省略記号の効きを保証 */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .stats {
  overflow-wrap: anywhere; /* 数値や英単語が長い場合でも折り返す */
  word-break: break-word;
}

/* ボタンが幅不足で押し出さないようラップ時の伸縮を許可 */
.card .actions .btn {
  flex: 1 1 auto;
}

/* 画像はブロック化して余計な行間を消す＆横幅にフィット */
.card img {
  display: block;
  width: 100%;
  height: auto;
}

/* 極小幅での安全策：2列のstatsを1列に落とす */
@media (max-width: 420px) {
  .card .stats {
    grid-template-columns: 1fr;
  }
}
