/* Die Tools v0 — original stylesheet (layout inspired by common 3-pane editors; not a pixel clone). */
:root {
  --bg: #e8eaef;
  --panel: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --line: #dde1e8;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --canvas: #fafafa;
  --in: #f3f4f6;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  /* Shared topbar wordmark. Floor 56px; desktop settles around 64–72px. */
  --wordmark-h: clamp(56px, 3rem + 1.6vw, 72px);
  --topbar-pad-y: 10px;
  --topbar-h: calc(var(--wordmark-h) + (var(--topbar-pad-y) * 2) + var(--safe-t) + 1px);
  --editor-pane-h: calc(100vh - var(--topbar-h) - 24px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: var(--topbar-h);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
    "Hiragino Sans", "Noto Sans KR", sans-serif;
  padding-bottom: var(--safe-b);
}

[hidden] {
  display: none !important;
}

/* ---- Shared top bar (Home + Editor) ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: calc(var(--topbar-pad-y) + var(--safe-t)) 24px var(--topbar-pad-y);
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  line-height: 0;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  /* Clip the paint-only wordmark shift so transparent-canvas pixels
     cannot spill past the logo box onto the bar or the pills. */
  overflow: hidden;
}

.brand:hover .brand-wordmark {
  opacity: 0.82;
}

.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.brand-wordmark {
  display: block;
  height: var(--wordmark-h);
  width: auto;
  /* logo-wordmark.png is 1083×497, but the MakePk ink only occupies
     y=24–191 (center 107.5px = 21.6298% from the top). The topbar
     already flex-centers this image box with the language pills;
     shift the bitmap so the ink center lands on that shared axis.
     Glyph size and the header row height stay the same. */
  --wordmark-ink-center: 21.6298%;
  transform: translateY(calc(50% - var(--wordmark-ink-center)));
}

.lang-switch {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  background: var(--in);
}

.lang-switch button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}

.lang-switch button.on {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

@media (max-width: 720px) {
  .topbar {
    gap: 8px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .lang-switch {
    gap: 2px;
    padding: 2px;
  }
  .lang-switch button {
    padding: 4px 6px;
    font-size: 11px;
    white-space: nowrap;
  }
}

/* ---- Home ---- */
#home {
  min-height: calc(100vh - var(--topbar-h));
  background: #fff;
}

.home-hero {
  padding: 28px 24px 8px;
}

.home-hero h1 {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 700;
}

.home-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  max-width: 40rem;
}

.gal {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr));
  gap: 22px 20px;
  padding: 20px 24px 56px;
}

.card {
  cursor: pointer;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  width: 100%;
}

.card-body {
  position: relative;
  height: 220px;
  border-radius: 20px;
  background: #f4f4f5;
  border: 1px solid #c8c8c8;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover .card-body,
.card:focus-visible .card-body {
  border-color: #111;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  outline: none;
}

.card-die,
.card-shot {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-die {
  padding: 18px 6px 18px 16px;
}

.card-die svg {
  width: 100%;
  height: 100%;
  display: block;
}

.card-shot {
  margin: 18px 18px 18px 0;
  border-radius: 8px;
  background: linear-gradient(145deg, #d4d4d8, #f4f4f5);
  color: var(--muted);
  font-size: 13px;
}

.card-tags {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}

.card-tags span {
  background: #fff;
  color: #777;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 7px;
}

.card-tags .soon {
  background: #111;
  color: #fff;
}

.card-name {
  margin: 10px 4px 0;
  font-size: 17px;
  color: #888;
}

.card:hover .card-name {
  color: #111;
}

.card[data-soon="1"] {
  opacity: 0.72;
  cursor: not-allowed;
}

.home-foot {
  text-align: center;
  padding: 8px 24px 32px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Editor shell ---- */
#editor {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(240px, 300px);
  gap: 12px;
  padding: 12px;
  min-height: calc(100vh - var(--topbar-h));
}

@media (max-width: 1100px) {
  #editor {
    grid-template-columns: 1fr;
    height: auto;
  }
  .stage-wrap {
    min-height: 58vh !important;
  }
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Left: rail + panes */
.left {
  display: grid;
  grid-template-columns: 72px 1fr;
  overflow: auto;
  max-height: var(--editor-pane-h);
}

.rail {
  border-right: 1px solid var(--line);
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  background: linear-gradient(var(--in), var(--panel));
}

.rail button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 10px 4px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.rail button .ico {
  font-size: 20px;
  line-height: 1;
  filter: grayscale(1);
  opacity: 0.75;
}

.rail button.on {
  color: var(--accent);
  font-weight: 600;
}

.rail button.on .ico {
  filter: none;
  opacity: 1;
}

.rail .spacer {
  flex: 1;
}

.pane {
  padding: 16px 14px 20px;
  min-width: 0;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  margin: 0 0 14px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--in);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pane h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 650;
}

.hint {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field {
  border-radius: 10px;
  padding: 4px;
}

.field:focus-within {
  background: var(--accent-soft);
}

.field label {
  display: block;
  font-size: 12px;
  padding: 2px 6px 4px;
}

.field .row {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
}

.field:focus-within .row {
  border-color: var(--accent);
}

.field input {
  border: 0;
  background: transparent;
  width: 100%;
  padding: 10px 0;
  font-size: 16px;
  outline: 0;
  min-width: 0;
  color: var(--text);
}

.field .unit {
  color: var(--muted);
  font-size: 13px;
}

input[type="number"]::-webkit-inner-spin-button {
  display: none;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.section {
  margin-top: 20px;
}

.stepper {
  display: flex;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.stepper button {
  width: 42px;
  border: 0;
  background: var(--in);
  font-size: 18px;
  cursor: pointer;
  margin: 5px;
  border-radius: 8px;
}

.stepper input {
  flex: 1;
  border: 0;
  text-align: center;
  font-size: 16px;
  outline: 0;
  min-width: 0;
  background: transparent;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.seg button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.seg button.on {
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  font-size: 14px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
}

.about-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

/* Center stage */
.mid {
  position: relative;
  min-width: 0;
}

.stage-wrap {
  height: var(--editor-pane-h);
  border-radius: var(--radius);
  background: var(--canvas);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  position: relative;
}

.stage-wrap.grabbing {
  cursor: grabbing;
}

.stage-world {
  width: 100%;
  height: 100%;
  transform-origin: center center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.stage-world svg {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.stage-empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
}

.legend {
  position: absolute;
  left: 14px;
  top: 12px;
  z-index: 2;
  pointer-events: none;
  font-size: 12px;
  line-height: 1.35;
}

.legend-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
}

.legend-lines span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-lines i {
  display: inline-block;
  width: 28px;
  border-top: 2px solid;
}

.legend-dims {
  color: var(--muted);
}

.legend-dims p {
  margin: 0 0 8px;
}

.legend-dims strong {
  color: var(--text);
  font-weight: 550;
}

.toolbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  padding: 6px 8px;
  z-index: 2;
}

.toolbar button {
  width: 38px;
  height: 36px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

.toolbar button:hover {
  background: var(--in);
}

.toolbar .hint-inline {
  font-size: 11px;
  color: var(--muted);
  padding: 0 8px;
  display: none;
}

@media (min-width: 1100px) {
  .toolbar .hint-inline {
    display: inline;
  }
}

/* Right column */
.right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  max-height: var(--editor-pane-h);
}

.mini {
  position: relative;
  height: 240px;
  border-radius: 18px;
  background: linear-gradient(180deg, #c4c4c8, #e8e8ea 90%);
  overflow: hidden;
  flex: none;
  padding: 16px;
}

.mini-label {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  background: rgba(255, 255, 255, 0.85);
  padding: 3px 8px;
  border-radius: 6px;
}

#miniPv {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 10px;
}

#miniPv svg {
  width: 100%;
  height: 100%;
}

.export-box {
  padding: 16px;
  flex: none;
}

.export-box h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 650;
}

.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-grid button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  padding: 8px;
}

.export-grid button:hover {
  border-color: var(--accent);
}

.export-grid button:disabled,
.export-grid button.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 5px;
  border-radius: 4px;
  color: #fff;
  line-height: 1;
}

.badge-svg {
  background: #0ea5e9;
}
.badge-ai {
  background: #d97706;
}
.badge-pdf {
  background: #e11d48;
}
.badge-dxf {
  background: #374151;
}

.export-notes {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.export-notes li {
  margin-bottom: 8px;
}

.editor-foot {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0 8px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  background: #111;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Home utility (not a box-style card) ---- */
.util {
  padding: 18px 24px 0;
}

.util h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.util-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 14px;
  row-gap: 2px;
  align-items: center;
  max-width: 520px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  color: inherit;
  text-decoration: none;
}

.util-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.12);
}

.util-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.util-mark {
  grid-row: 1 / span 3;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.util-kicker,
.util-name,
.util-desc {
  grid-column: 2;
}

.util-kicker {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.util-name {
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
}

.util-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

/* ---- Size converter (convert.html) ---- */
.cv {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

.cv-back {
  text-decoration: none;
}

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

.cv h1 {
  margin: 14px 0 8px;
  font-size: 26px;
  font-weight: 700;
}

.cv-lead {
  margin: 0 0 18px;
  max-width: 46rem;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

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

.cv-grid > * {
  min-width: 0;
}

.cv-card {
  padding: 16px 16px 18px;
}

.cv-card h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 650;
}

.cv .field .hint {
  margin: 6px 6px 0;
}

.cv .seg-2 {
  grid-template-columns: 1fr 1fr;
}

.cv .seg button {
  padding: 0 6px;
}

.cv-warn {
  margin-top: 0;
}

.cv-table-wrap {
  overflow-x: auto;
}

.cv-table {
  width: 100%;
  min-width: 280px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.cv-table th,
.cv-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.cv-table thead th {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.cv-table tbody th {
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.cv-table tr.on td,
.cv-table tr.on th {
  background: var(--accent-soft);
}

.cv-mm {
  display: block;
  font-weight: 650;
  white-space: nowrap;
}

.cv-in {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
}

.cv-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
  vertical-align: 1px;
}

.cv-caption {
  caption-side: bottom;
  text-align: left;
  padding-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.cv-formula {
  margin: 12px 0 0;
}

@media (max-width: 800px) {
  .cv {
    padding: 16px 12px 36px;
  }
  .cv-grid {
    grid-template-columns: 1fr;
  }
  .cv-table th,
  .cv-table td {
    padding: 8px 4px;
  }
}
