/* 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);
  /* Header wordmark. Old size was a fixed 26px. Floor 40px (~1.5×), cap 52px (2×). */
  --wordmark-h: clamp(40px, 2.22rem + 1.15vw, 52px);
}

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

html {
  scroll-padding-top: var(--safe-t);
}

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-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

[hidden] {
  display: none !important;
}

/* ---- Home ---- */
#home {
  min-height: 100vh;
  background: #fff;
}

.home-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .home-bar {
    padding: 10px 14px;
    gap: 8px;
  }
}

.brand {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.brand-wordmark {
  display: block;
  height: var(--wordmark-h);
  width: auto;
}

.lang-switch {
  display: inline-flex;
  flex-wrap: wrap;
  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;
}

.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 {
  --chrome-h: calc(var(--wordmark-h) + 16px);
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(240px, 300px);
  gap: 12px;
  padding: 12px;
  min-height: 100vh;
}

.editor-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  height: var(--chrome-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: calc(100vh - 36px - var(--chrome-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: calc(100vh - 36px - var(--chrome-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: calc(100vh - 36px - var(--chrome-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);
}
