/* ドット絵メーカー — Day 002
   外部フォント・外部CSSは一切読み込まない（file:// で単体動作させるため） */

:root {
  --bg: #14161c;
  --panel: #1d212b;
  --panel-2: #262b38;
  --line: #39404f;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --accent: #4f9cff;
  --accent-strong: #2f7ff0;
  --danger: #ff8a8a;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
               "Yu Gothic", "Noto Sans JP", "Segoe UI", sans-serif;
  line-height: 1.6;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px 48px;
}

.app {
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- 見出し ---- */
.app__head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.app__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
}

.app__day {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .7rem;
  letter-spacing: .08em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 10px;
}

/* ---- ドロップゾーン ---- */
.drop {
  position: relative;              /* 中のfile inputを隠す位置の基準 */
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px;
}

/* file input は見た目だけ消す。キーボードのフォーカスは残す */
.drop__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.drop__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 132px;
  padding: 20px 16px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}

.drop__label:hover,
.drop.is-dragover .drop__label {
  border-color: var(--accent);
  background: var(--panel-2);
}

/* キーボードでfile inputにフォーカスが来たことを枠で示す */
.drop__input:focus-visible + .drop__label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drop__lead {
  font-size: 1.05rem;
  font-weight: 600;
}

/* 画像を読み込んだあとは受け取り口を小さくして、結果を主役にする */
body[data-state="ready"] .drop__label {
  min-height: 76px;
  padding: 14px 16px;
}

body[data-state="ready"] .drop__lead { font-size: .9rem; }

.drop__sub {
  font-size: .85rem;
  color: var(--muted);
}

.drop__note {
  margin: 8px 0 2px;
  text-align: center;
  font-size: .8rem;
  color: var(--danger);
  min-height: 1.6em;
}

.hint {
  margin: -8px 0 0;
  text-align: center;
  font-size: .75rem;
  color: var(--muted);
}

/* ---- 変換の設定 ---- */
.controls {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.control__label {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
  min-width: 5.5em;
}

.control__range {
  flex: 1 1 200px;
  min-width: 0;
  accent-color: var(--accent);
  height: 32px;
  cursor: pointer;
}

.control__range:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.control__value {
  flex: 0 0 auto;
  min-width: 4.5em;
  text-align: right;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}

.segmented {
  flex: 1 1 240px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* ---- ボタン ---- */
.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 8px;
  min-height: 48px;
  cursor: pointer;
  transition: background-color .15s ease, opacity .15s ease;
}

.btn:hover:not(:disabled) { background: #323847; }

.btn:disabled {
  opacity: .38;
  cursor: not-allowed;
}

.btn--seg {
  font-size: .9rem;
  padding: 12px 4px;
  min-height: 44px;
}

.btn--seg.is-selected {
  background: var(--accent-strong);
  border-color: var(--accent);
}

.btn--seg.is-selected:hover:not(:disabled) { background: var(--accent); }

.btn--primary {
  background: var(--accent-strong);
  width: 100%;
}

.btn--primary:hover:not(:disabled) { background: var(--accent); }

/* ---- 結果（Before / After） ---- */
.result {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.frames {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.frame {
  margin: 0;
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px;
}

/* ドット絵側が主役。枠とラベルの色で差をつける */
.frame--main {
  border-color: var(--accent-strong);
}

.frame__label {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.frame--main .frame__label { color: var(--accent); }

/* 縦長・横長どちらの画像でも枠の大きさが変わらないようにする */
.frame__box {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border-radius: 10px;
  overflow: hidden;
}

.frame__media {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

/* 拡大表示でドットの境界をぼかさない */
.frame__media--pixel {
  image-rendering: crisp-edges;   /* pixelated 未対応ブラウザ向け */
  image-rendering: pixelated;
}

.result__info {
  margin: 0;
  text-align: center;
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 1.6em;
}

/* ---- フッター ---- */
.foot {
  text-align: center;
  font-size: .8rem;
}

.foot__link {
  color: var(--accent);
  text-decoration: none;
}

.foot__link:hover { text-decoration: underline; }

/* スマホでは Before / After を縦に積む */
@media (max-width: 640px) {
  .frames { grid-template-columns: 1fr; }
}

/* 狭い画面ではラベルとスライダーを2段にする */
@media (max-width: 420px) {
  .control { gap: 8px; }
  .control__label { min-width: 100%; }
  .segmented { flex-basis: 100%; }
  .drop__label { min-height: 112px; }
}

/* マウス操作でないデバイス向けにhoverの残留を防ぐ */
@media (hover: none) {
  .btn:hover:not(:disabled) { background: var(--panel-2); }
  .btn--primary:hover:not(:disabled),
  .btn--seg.is-selected:hover:not(:disabled) { background: var(--accent-strong); }
  .drop__label:hover { border-color: var(--line); background: transparent; }
}
