* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0d0b1a;
  --panel: #14122a;
  --panel2: #1c1936;
  --line: rgba(245,158,11,0.18);
  --amber: #f59e0b;
  --amber2: #fcd9a6;
  --text: #ece8ff;
  --muted: #9a93b8;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Sarabun", "Noto Sans Thai", sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* ---- Panel ---- */
#panel {
  width: 340px; min-width: 340px; height: 100%;
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 16px; padding-top: 56px;
}
.brand { margin-bottom: 16px; }
.brand-title { font-weight: 800; font-size: 17px; color: #fff; line-height: 1.3; }
.brand-sub { font-size: 12px; color: var(--amber2); margin-top: 2px; }

/* ---- Language dropdown (Thai / English / Vietnamese) — kept subtle, not prominent ---- */
.lang-select {
  width: auto; margin-bottom: 10px; padding: 4px 8px; font-size: 11px; font-weight: 600;
  background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.15); color: var(--muted);
  border-radius: 6px; cursor: pointer;
}
.lang-select:hover, .lang-select:focus { color: var(--text); border-color: rgba(245,158,11,0.4); outline: none; }
.lang-select option { background: #1c1936; }

.group { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.group-head { font-weight: 700; font-size: 14px; margin-bottom: 10px; color: #fff; }

.btn { width: 100%; padding: 10px 12px; border: none; border-radius: 8px; font-size: 14px; font-weight: 700; cursor: pointer; transition: all .18s; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn-upload { background: rgba(245,158,11,0.15); border: 1px solid var(--amber); color: var(--amber2); }
.btn-upload:hover { background: rgba(245,158,11,0.28); }
.btn-primary { background: linear-gradient(135deg,#f59e0b,#f43f5e); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-export { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15); margin-bottom: 8px; }
.btn-export:hover { background: rgba(255,255,255,0.12); }
.btn-ghost { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12); }

.filename { font-size: 12px; color: var(--muted); margin-top: 8px; word-break: break-all; }

.help { margin-top: 10px; font-size: 12px; color: var(--muted); }
.help summary { cursor: pointer; color: var(--amber2); font-weight: 600; }
.help ul { margin: 8px 0 0 16px; line-height: 1.6; }
.help b { color: #fff; }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select { width: 100%; padding: 7px 9px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.15); color: #fff; border-radius: 6px; font-size: 14px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--amber); }
.field select option { background: #1c1936; }

.readout { font-size: 14px; font-weight: 700; color: #3ce6d1; margin-bottom: 10px; }

.tabs { display: flex; gap: 6px; margin: 4px 0 12px; }
.tab { flex: 1; padding: 8px 4px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.15); background: rgba(0,0,0,0.25); color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; line-height: 1.2; }
.tab small { font-weight: 400; font-size: 10px; }
.tab.active { background: rgba(245,158,11,0.18); border-color: var(--amber); color: var(--amber2); }
.tab:disabled { opacity: .5; cursor: not-allowed; }

.adv { margin: 8px 0; font-size: 12px; }
.adv summary { cursor: pointer; color: var(--amber2); font-weight: 600; margin-bottom: 8px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-bottom: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--amber); }

.q { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; background: rgba(255,255,255,0.12); color: var(--amber2); font-size: 10px; font-weight: 800; cursor: help; margin-left: 3px; }

.sheet-info { font-size: 13px; color: var(--amber2); margin-bottom: 10px; }
.warn { background: rgba(244,63,94,0.12); border: 1px solid rgba(244,63,94,0.4); color: #ffb4c0; font-size: 12px; padding: 8px 10px; border-radius: 8px; margin-bottom: 10px; line-height: 1.5; }
.lock-note { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---- Stage: split 2D | 3D ---- */
#stage { flex: 1; display: flex; min-width: 0; background: #0a0816; }
#split { flex: 1; display: flex; min-width: 0; }
.pane { flex: 1 1 50%; min-width: 0; display: flex; flex-direction: column; }
#pane2d { border-right: 1px solid var(--line); }
.pane-title { padding: 9px 14px; font-size: 13px; font-weight: 800; color: var(--amber2); border-bottom: 1px solid var(--line); }
.pane-sub { font-weight: 500; color: var(--muted); font-size: 11px; }
@media (max-width: 820px) { #split { flex-direction: column; } #pane2d { border-right: none; border-bottom: 1px solid var(--line); } }

.viewbox { flex: 1; position: relative; overflow: hidden; padding: 16px; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 15px; text-align: center; }
.empty-icon { font-size: 48px; }
#preview2d { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
/* fill the box; viewBox + preserveAspectRatio(meet) contains the whole work centered.
   width/height mm attrs on the SVG are overridden here but kept for export. */
#preview2d svg { width: 100%; height: 100%; display: block; }

#hiddenSvgHost { position: absolute; width: 0; height: 0; overflow: hidden; opacity: 0; pointer-events: none; }

/* ---- 3D controls ---- */
#view3d { background: #12101f; }
#td3d-controls {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: rgba(20,18,42,0.9); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; backdrop-filter: blur(10px);
}
.td3d-btn { background: linear-gradient(135deg,#f59e0b,#f43f5e); color:#fff; border:none; border-radius: 999px; padding: 7px 16px; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.td3d-btn:hover { filter: brightness(1.08); }
#td3d-scrub { width: 200px; accent-color: var(--amber); cursor: pointer; }
#td3d-letter { background: rgba(0,0,0,0.4); color:#fff; border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; padding: 6px 8px; font-size: 13px; }

/* ---- Mobile: sidebar drawer + toggle button ---- */
#panelToggle { display: none; position: fixed; top: 8px; left: 8px; z-index: 200; align-items: center; gap: 6px; padding: 8px 13px; border-radius: 999px; border: 1px solid var(--amber); background: rgba(20,18,42,0.96); color: var(--amber2); font-size: 13px; font-weight: 800; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,0.5); }
#panelToggle svg { width: 18px; height: 18px; }

@media (max-width: 820px) {
  #panelToggle { display: inline-flex; }
  #panel { position: fixed; top: 0; left: 0; height: 100%; width: min(340px, 86vw); min-width: 0; z-index: 150; box-shadow: 6px 0 30px rgba(0,0,0,0.65); transition: transform 0.25s ease; }
  body.sidebar-hidden #panel { transform: translateX(-103%); }
  #stage { width: 100%; }
}
