/* imgmaster：草地綠＋泥土棕，方角、按鈕底部加深一條模擬方塊厚度 */
:root {
  --bg: #f3f1ec;
  --surface: #fff;
  --ink: #1d2320;
  --muted: #5f6862;
  --line: #dcd8cf;
  --grass: #4c9a2a;
  --grass-dark: #3a7a1f;
  --grass-soft: #e6f2df;
  --dirt: #8a5a35;
  --danger: #b83227;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  --checker: repeating-conic-gradient(#e9e6df 0% 25%, #fff 0% 50%) 50% / 20px 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--grass-dark); }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9em; }
h1, h2 { line-height: 1.25; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }

/* ─── 頁首頁尾 ─────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: #23291f;
  color: #fff;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: .02em;
}
.brand img { image-rendering: pixelated; }
.tagline { color: #b9c4b3; font-size: .9rem; }

.site-footer {
  padding: 24px 20px 40px;
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
}

/* ─── 共用元件 ─────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .08);
  transition: background .15s, transform .05s;
}
.btn:hover { background: #f7f6f2; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--grass);
  border-color: var(--grass-dark);
  color: #fff;
  box-shadow: inset 0 -4px 0 var(--grass-dark);
}
.btn-primary:hover { background: #55a830; }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-danger { color: var(--danger); border-color: #e7c4c0; }
.btn-danger:hover { background: #fbeeed; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-lg { padding: 13px 28px; font-size: 1.05rem; }

.chip {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.chip:hover, .chip.is-active { border-color: var(--grass); background: var(--grass-soft); color: var(--grass-dark); }

.linklike {
  padding: 0;
  border: 0;
  background: none;
  color: var(--grass-dark);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.messages { list-style: none; margin: 0 0 20px; padding: 0; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border: 1px solid; }
.msg-success { background: var(--grass-soft); border-color: #bcdcae; color: #2d5f17; }
.msg-error { background: #fbeeed; border-color: #efc6c2; color: #8f241b; }
.msg-info { background: #eaf1fb; border-color: #c3d6f2; color: #23497d; }

.form-errors {
  margin: 0 0 12px;
  padding: 10px 14px 10px 30px;
  border-radius: 8px;
  background: #fbeeed;
  color: #8f241b;
  font-size: .92rem;
}

.notice { padding: 8px 12px; border-radius: 8px; background: #fff6df; color: #7a5a12; font-size: .9rem; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.pixelated { image-rendering: pixelated; }

/* ─── 首頁 ─────────────────────────────────────── */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { font-size: clamp(1.8rem, 4.5vw, 2.8rem); margin: 0 0 12px; font-weight: 900; }
.hl {
  color: var(--grass-dark);
  /* 底下一條棕色方塊線，呼應泥土層 */
  background: linear-gradient(transparent 78%, rgba(138, 90, 53, .25) 78%);
}
.lead { color: var(--muted); font-size: 1.05rem; margin: 0 auto 28px; max-width: 640px; }

.dropzone {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  padding: 28px;
  border: 3px dashed #c8c3b7;
  border-radius: 16px;
  background: var(--surface);
  transition: border-color .15s, background .15s;
}
.dropzone.is-drag { border-color: var(--grass); background: var(--grass-soft); }
.dropzone.has-file { border-style: solid; border-color: var(--grass); }
.dropzone.is-invalid { border-color: var(--danger); }
/* 不能用 display:none：required 驗證會因欄位「無法聚焦」而失效 */
.dropzone input[type=file] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dropzone-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px;
  cursor: pointer;
}
.dropzone-label strong { font-size: 1.1rem; }
.dropzone-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 6px;
  border-radius: 4px;
  /* 草地方塊：上方綠、下方泥土 */
  background:
    linear-gradient(var(--grass) 0 30%, transparent 30%),
    repeating-linear-gradient(90deg, var(--dirt) 0 14px, #9b6a42 14px 28px);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .2);
}
.filename { font-weight: 600; color: var(--grass-dark); min-height: 1.6em; }
/* 有 JS 時選好檔案就自動上傳，按鈕只留給無 JS 的備援 */
.js .dropzone .btn-lg { display: none; }
.js-only { display: none; }
.js .js-only { display: inline; }
/* 觸控裝置不能拖曳檔案，別提 */
@media (hover: none) { .drag-hint { display: none; } }
.dropzone.is-uploading { cursor: progress; border-style: solid; border-color: var(--grass); background: var(--grass-soft); }
.dropzone.is-uploading .dropzone-label { pointer-events: none; }
.dropzone.is-uploading .dropzone-icon { animation: bob .8s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .dropzone.is-uploading .dropzone-icon { animation: none; } }
.dropzone.is-invalid .filename { color: var(--danger); }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin: 44px 0 24px;
}
.feature { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.feature h2 { font-size: 1.1rem; margin: 10px 0 6px; }
.feature p { margin: 0; color: var(--muted); font-size: .93rem; }
.feature-icon { display: block; width: 36px; height: 36px; border-radius: 4px; }
.fi-block { background: conic-gradient(var(--grass) 0 25%, #6bb544 0 50%, var(--grass-dark) 0 75%, #82c35d 0) 0 0 / 18px 18px; }
.fi-resize { background: linear-gradient(135deg, transparent 45%, var(--dirt) 45% 55%, transparent 55%), #f1e4d6; border: 2px solid var(--dirt); }
.fi-crop { border: 3px dashed var(--grass-dark); background: var(--grass-soft); }
.fi-rotate { border: 3px solid var(--dirt); border-radius: 50%; border-right-color: transparent; }

.privacy h2 { margin-top: 0; font-size: 1.1rem; }
.privacy ul { margin: 0; padding-left: 20px; color: var(--muted); }

.empty-state { max-width: 560px; margin: 40px auto; text-align: center; }

/* ─── 編輯頁 ───────────────────────────────────── */
.job-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.job-title { margin: 0; font-size: 1.3rem; word-break: break-all; }
.job-meta { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}

.stage {
  position: relative;   /* 縮放按鈕的定位基準，也是 editor.js 換算座標用的 offsetParent */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;     /* 放大後超出畫面的部分切掉 */
  min-height: 320px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--checker);
}
.stage-inner {
  position: relative;
  display: inline-block;
  transform-origin: 0 0;
  line-height: 0;
  overflow: hidden;   /* 裁切框的暗色遮罩靠超大 box-shadow，要在這裡切掉 */
}
.stage-inner img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  user-select: none;
  -webkit-user-drag: none;
}
.stage.is-cropping .stage-inner { cursor: crosshair; touch-action: none; }
/* 沒放大時單指上下滑仍是捲動頁面，雙指交給 editor.js 縮放；放大後單指改成平移圖片 */
.js .stage { touch-action: pan-y; }
.js .stage.is-zoomed { touch-action: none; cursor: grab; }
.js .stage.is-panning { cursor: grabbing; }

.zoom-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: flex;
  gap: 4px;
}
.zoom-controls[hidden], .stage.is-cropping .zoom-controls { display: none; }
.zoom-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  font: inherit;
  font-size: .95rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.zoom-btn:hover { border-color: var(--grass); color: var(--grass-dark); }
.zoom-fit { font-size: .8rem; font-weight: 600; }
.zoom-hint { margin: 6px 0 0; color: var(--muted); font-size: .82rem; }

.grid-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;   /* 不擋裁切框選 */
}
.grid-overlay.is-off { display: none; }
.grid-overlay path {
  fill: none;
  stroke: rgba(0, 0, 0, .35);
  /* 線寬由 editor.js 依縮放倍率設定（viewBox 單位，1＝1 格），維持螢幕上 1px */
  shape-rendering: crispEdges;
}
.grid-overlay path.major { stroke: rgba(0, 0, 0, .7); }
.grid-toggle { margin: 0; font-size: .9rem; }

/* 點方塊清單時蓋暗其他格：畫布 1 像素＝1 格，放大時要保持方塊邊界銳利 */
.block-focus {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
}
.block-focus[hidden] { display: none; }
.cell-info { margin: -8px 0 16px; min-height: 1.5em; color: var(--muted); font-size: .9rem; }

.crop-box {
  position: absolute;
  border: 2px solid #fff;
  outline: 1px dashed rgba(0, 0, 0, .7);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
  cursor: move;
}
.crop-box::after {
  content: attr(data-size);
  position: absolute;
  left: 0;
  top: -1px;
  transform: translateY(-100%);
  padding: 2px 6px;
  background: rgba(0, 0, 0, .7);
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 12px 0 20px;
}
.alt-formats { color: var(--muted); font-size: .9rem; }
.alt-formats a { margin-left: 6px; }
.undo-form { margin-left: auto; }

.tools { position: sticky; top: 16px; padding: 16px; }
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 9px;
  background: #efece5;
}
.tabs button {
  padding: 8px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.field output { color: var(--grass-dark); font-weight: 800; margin-left: 4px; }
input[type=number], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
}
input[type=number]:focus, select:focus { outline: 2px solid var(--grass); outline-offset: 0; border-color: var(--grass); }
input[type=range] { width: 100%; accent-color: var(--grass); }
input[type=checkbox] { accent-color: var(--grass); width: 17px; height: 17px; margin: 3px 0 0; flex: none; }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=number] { width: 84px; flex: none; }
.range-row input[type=range] { flex: 1; }
.custom-angle .range-row input[type=number] { flex: 1; width: auto; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.check { display: flex; gap: 8px; margin-bottom: 10px; cursor: pointer; font-size: .95rem; }
.check small { display: block; color: var(--muted); font-size: .8rem; }

fieldset.field { border: 0; padding: 0; min-width: 0; }
fieldset.field legend { padding: 0; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }

/* 兩種配色方式各自的欄位與說明，依 form 的 data-mode 只顯示一種 */
form[data-mode=bedrock] [data-mode-only=color],
form[data-mode=color] [data-mode-only=bedrock] { display: none; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 9px;
  background: #efece5;
}
.segmented label { position: relative; margin: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 7px 4px;
  border-radius: 7px;
  text-align: center;
  font-weight: 600;
  font-size: .92rem;
  color: var(--muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--grass); }

.group-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.group-checks .check { margin-bottom: 6px; }
.group-checks small { display: inline; margin-left: 4px; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.btn-grid .btn { font-weight: 500; }

/* 配色表 */
.palette-head h2 { margin: 0; font-size: 1.1rem; }
.palette-head p { margin: 4px 0 14px; color: var(--muted); font-size: .9rem; }
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  max-height: 340px;
  overflow: auto;
}
.swatches li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .88rem;
}
.swatch { width: 26px; height: 26px; flex: none; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.swatches .count { margin-left: auto; color: var(--muted); }
.palette-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* 基岩版方塊清單 */
.palette-head .hint { margin: -6px 0 14px; }
.block-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  max-height: 420px;
  overflow: auto;
}
.block-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: .88rem;
  text-align: left;
  color: inherit;
  cursor: pointer;
}
.block-row:hover { border-color: var(--grass); }
.block-row[aria-pressed=true] { border-color: var(--grass-dark); background: var(--grass-soft); box-shadow: inset 0 0 0 1px var(--grass-dark); }
.block-icon {
  width: 32px;
  height: 32px;
  flex: none;
  image-rendering: pixelated;   /* 16×16 貼圖放大兩倍，保持像素方正 */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .2);
}
.block-name { min-width: 0; font-weight: 600; }
.block-name small, .block-row .count small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.block-row .count { margin-left: auto; text-align: right; white-space: nowrap; color: var(--muted); }

/* 放進 Minecraft 的步驟說明 */
.howto { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #faf9f6; font-size: .92rem; }
.howto summary { font-weight: 700; cursor: pointer; color: var(--grass-dark); }
.howto ol { margin: 10px 0 0; padding-left: 22px; }
.howto li { margin-bottom: 8px; }
.howto li small { display: block; color: var(--muted); font-size: .82rem; }
.howto .notice, .howto .hint { margin: 10px 0 0; }
.howto .commands { margin-top: 6px; }
.howto .variants { margin: 6px 0 2px; padding-left: 18px; list-style: disc; }
.howto .variants li { margin-bottom: 4px; }
.howto .commands li { margin-bottom: 4px; }
code.cmd {
  padding: 1px 6px;
  border-radius: 4px;
  background: #23291f;
  color: #e9f5e1;
  font-size: .88rem;
  word-break: break-all;
  user-select: all;   /* 點一下就整段選取，方便複製 */
}

.disclaimer { margin: 6px 0 0; font-size: .8rem; }

/* 處理紀錄 */
.history { margin-top: 24px; }
.history h2 { margin: 0 0 12px; font-size: 1.1rem; }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  border-radius: 8px;
}
.steps li + li { border-top: 1px solid #eeebe4; }
.steps li.is-current { background: var(--grass-soft); }
.thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--checker);
  background-size: 12px 12px;
  overflow: hidden;
}
.thumb img { max-width: 100%; max-height: 100%; }
.step-info { display: flex; flex-direction: column; min-width: 0; }
.step-no { font-size: .8rem; font-weight: 700; color: var(--grass-dark); }
.step-label { font-weight: 600; }
.dim { color: var(--muted); font-size: .85rem; }
.step-actions { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: .9rem; white-space: nowrap; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .tools { position: static; }
  .stage-inner img { max-height: 60vh; }
}
@media (max-width: 560px) {
  .container { padding: 16px 12px 40px; }
  .job-bar { flex-direction: column; }
  .tagline { display: none; }
  .step-actions { flex-direction: column; gap: 4px; align-items: flex-end; }
}
