/* ============================================================================
 * style.css — 港鐵馬賽克產生器介面
 * ----------------------------------------------------------------------------
 * 設計語言：港鐵月台指示牌——白底、紅色主色（#AC2E44）、無襯線字、圓角藥丸掣。
 * 支援淺色／深色主題（跟系統，亦可手動切換 <html data-theme>）。
 * ==========================================================================*/

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --card: #ffffff;
  --card-2: #fafafa;
  --text: #1b1d21;
  --dim: #6b7280;
  --border: #e3e5ea;
  --accent: #ac2e44;
  --accent-soft: rgba(172, 46, 68, .10);
  --ok: #12805c;
  --shadow: 0 1px 2px rgba(16, 20, 28, .05), 0 6px 18px rgba(16, 20, 28, .06);
  --radius: 14px;
  --font-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system, "Segoe UI", sans-serif;
}
html[data-theme="dark"] {
  --bg: #16181d;
  --panel: #1e2127;
  --card: #23262d;
  --card-2: #272b33;
  --text: #eef0f4;
  --dim: #9aa1ae;
  --border: rgba(255, 255, 255, .10);
  --accent: #e5455f;
  --accent-soft: rgba(229, 69, 95, .16);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
h1, h2, p { margin: 0; }

/* ---------------- 頂欄 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 14px;
  padding-top: calc(9px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  background: var(--accent);
  background-image: linear-gradient(135deg, #c8394f, #8d2135);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px 7px;
  background:
    linear-gradient(#fff, #fff) center/100% 3px no-repeat,
    linear-gradient(#fff, #fff) center/3px 100% no-repeat;
  border-radius: 1px; opacity: .95;
}
.topbar h1 { font-size: 16px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.topbar p { font-size: 10.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-tools { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 15px; cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }

/* ---------------- 版面 ---------------- */
.app {
  display: grid;
  grid-template-columns: 384px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  align-items: start;
  max-width: 1560px;
  margin: 0 auto;
}
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.stage { position: sticky; top: 66px; }
.stage-inner { display: flex; flex-direction: column; gap: 10px; }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 13px 14px;
}
.sec-title {
  font-size: 12.5px; font-weight: 700; letter-spacing: .6px;
  color: var(--accent); text-transform: none;
  margin-bottom: 9px; padding-bottom: 7px;
  border-bottom: 1px dashed var(--border);
}
.sec-body { display: flex; flex-direction: column; gap: 9px; }

/* ---------------- 表單元件 ---------------- */
.text-input, .num-input, .hex-input, select.text-input {
  width: 100%; min-width: 0;
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; outline: none;
}
.text-input:focus, .num-input:focus, .hex-input:focus { border-color: var(--accent); }
.num-input { width: 74px; text-align: center; }
.hex-input { width: 104px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.mini-label { font-size: 11px; color: var(--dim); }
.field-label { font-size: 11.5px; font-weight: 600; color: var(--dim); margin-top: 2px; }
.hint { font-size: 11px; color: var(--dim); }
.row { display: flex; gap: 8px; align-items: center; }
.row-tight { gap: 6px; }
.row-wrap { flex-wrap: wrap; }

.btn {
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--text); background: var(--card-2);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 11px; cursor: pointer; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-dense { gap: 4px; }
.seg-btn {
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--dim); background: var(--card-2);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; cursor: pointer; flex: 1 1 auto; text-align: center;
}
.seg-dense .seg-btn { padding: 6px 4px; min-width: 40px; flex: 1 1 0; }
.seg-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* 開關 */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.switch { position: relative; flex: 0 0 auto; width: 44px; height: 26px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--border); transition: background .16s ease;
}
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .16s ease;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 滑桿（手機觸控友善：input 本身 28px 高） */
.slider-row { display: grid; grid-template-columns: 1fr 108px 46px; align-items: center; gap: 8px; }
.slider-row label { font-size: 12.5px; color: var(--text); }
.slider-row output { font-size: 11.5px; color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: transparent; margin: 0; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--border) var(--fill, 50%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--border); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--accent);
}

/* 顏色列 */
.color-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; }
.color-row label { font-size: 12.5px; }
input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 40px; height: 32px; padding: 0; border: 1px solid var(--border);
  border-radius: 9px; background: transparent; cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: inherit; font-size: 11.5px; font-weight: 600;
  color: var(--dim); background: var(--card-2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

/* 車站列表 */
.station-list {
  max-height: 216px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card-2);
  display: flex; flex-direction: column;
}
.station-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.station-item:last-child { border-bottom: none; }
.station-item:hover { background: var(--accent-soft); }
.station-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.station-item .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .18); flex: 0 0 auto; }
.station-item .en { color: var(--dim); font-size: 11.5px; margin-left: auto; text-align: right; }
.station-empty { padding: 12px; text-align: center; color: var(--dim); font-size: 12px; }
.selected-info { font-size: 12px; color: var(--dim); }
.selected-info b { color: var(--text); }

.line-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.line-swatch {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--dim);
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 9px;
}
.line-swatch i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.preset-list { display: flex; flex-direction: column; gap: 6px; }
.preset-item {
  display: flex; align-items: center; gap: 7px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 8px; font-size: 12px;
}
.preset-item .swatch { display: flex; gap: 2px; }
.preset-item .swatch i { width: 14px; height: 14px; border-radius: 4px; display: block; }
.preset-item .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-item button {
  font-size: 11px; padding: 3px 7px; border-radius: 7px;
  border: 1px solid var(--border); background: transparent; color: var(--dim); cursor: pointer;
}
.preset-item button:hover { border-color: var(--accent); color: var(--accent); }

.drop-zone {
  border: 1.5px dashed var(--border); border-radius: 10px;
  padding: 12px; text-align: center; font-size: 12px; color: var(--dim);
  cursor: pointer;
}
.drop-zone.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* 歷史 */
.history-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.history-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 8px; font-size: 12px; cursor: pointer;
}
.history-item:hover { border-color: var(--accent); }
.history-item .sw { width: 16px; height: 16px; border-radius: 5px; flex: 0 0 auto; }
.history-item .txt { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .tm { font-size: 10.5px; color: var(--dim); }

/* ---------------- 預覽舞台 ---------------- */
.preview-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e9ebef 25%, transparent 25%, transparent 75%, #e9ebef 75%),
    linear-gradient(45deg, #e9ebef 25%, transparent 25%, transparent 75%, #e9ebef 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
  touch-action: none;
}
#preview { display: block; width: 100%; height: auto; cursor: grab; }
#preview.dragging { cursor: grabbing; }
.stage-badge {
  position: absolute; right: 8px; bottom: 8px;
  font-size: 10.5px; color: #fff; background: rgba(20, 20, 24, .62);
  padding: 3px 8px; border-radius: 999px; backdrop-filter: blur(4px);
  font-variant-numeric: tabular-nums;
}
.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.msg { font-size: 11.5px; color: var(--dim); }
.footer-note { font-size: 11px; color: var(--dim); text-align: center; padding: 4px 0 18px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: #1b1d21; color: #fff; font-size: 12.5px;
  padding: 9px 15px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 60; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
html[data-theme="dark"] .toast { background: #f2f3f6; color: #16181d; }

/* ---------------- 響應式 ---------------- */
@media (max-width: 1000px) {
  .app { grid-template-columns: 1fr; gap: 10px; padding: 10px; }
  .stage { position: sticky; top: 56px; z-index: 10; order: -1; }
  .stage-inner { background: var(--bg); padding-bottom: 6px; }
  .station-list { max-height: 168px; }
  .stage-actions .btn { font-size: 12px; padding: 7px 9px; }
}
@media (max-width: 420px) {
  .topbar h1 { font-size: 14.5px; }
  .topbar p { display: none; }
  .slider-row { grid-template-columns: 1fr 92px 42px; }
  .color-row { grid-template-columns: 1fr auto; }
  .color-row .hex-input { grid-column: 2; width: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
