/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #1e1e1e;
  --bg2:     #252526;
  --bg3:     #2d2d2d;
  --bg4:     #3c3c3c;
  --bg5:     #484848;
  --border:  #454545;
  --accent:  #4d9de0;
  --accent2: #2e7abd;
  --text:    #d4d4d4;
  --dim:     #888888;
  --danger:  #f14c4c;

  --left-w:  66px;
  --right-w: 272px;
  --header-h: 36px;
  --footer-h: 24px;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
  --bg:      #b8b8b8;
  --bg2:     #c4c4c4;
  --bg3:     #cccccc;
  --bg4:     #c0c0c0;
  --bg5:     #b0b0b0;
  --border:  #989898;
  --text:    #1a1a1a;
  --dim:     #505050;
}

html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Yu Gothic UI', system-ui, sans-serif;
  font-size: 12px;
  user-select: none;
}

#app { display: flex; flex-direction: column; width: 100%; height: 100%; }

/* ===== Header ===== */
#header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  flex-shrink: 0;
  z-index: 200;
}
.logo { font-weight: 700; font-size: 13px; color: #f08030; white-space: nowrap; margin-right: 4px; }

#header-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

#lang-toggle, #theme-toggle {
  background: var(--bg4); border: 1px solid var(--border);
  color: var(--accent); border-radius: 4px;
  padding: 2px 8px; cursor: pointer; font-size: 11px; font-weight: 700;
  letter-spacing: 0.05em;
}
#lang-toggle:hover, #theme-toggle:hover { background: var(--accent2); color: #fff; }

/* ===== Tab Bar ===== */
#tab-bar {
  height: 28px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 0 0 0 4px;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  z-index: 100;
}
#tab-bar::-webkit-scrollbar { height: 3px; }
.editor-tab {
  height: 24px;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  display: flex; align-items: center; gap: 4px;
  padding: 0 6px 0 10px;
  cursor: pointer; font-size: 11px; color: var(--dim);
  white-space: nowrap; min-width: 140px; max-width: 320px;
  flex-shrink: 0; user-select: none;
}
.editor-tab:hover:not(.active) { background: var(--bg5); color: var(--text); }
.editor-tab.active {
  background: var(--bg2); color: var(--text);
  border-color: var(--border); border-bottom-color: var(--bg2);
  position: relative; z-index: 1;
}
.tab-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tab-close {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 0; border-radius: 3px;
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.tab-close:hover { background: var(--danger); color: #fff; }
#btn-new-tab {
  height: 22px; min-width: 26px;
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-size: 16px; align-self: center;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; padding: 0 6px; flex-shrink: 0; margin-left: 4px;
}
#btn-new-tab:hover { background: var(--bg5); color: var(--text); }

/* ===== Menu ===== */
#menubar { display: flex; gap: 1px; }
.menu-item { position: relative; }
.menu-btn {
  display: block; padding: 4px 10px; cursor: default;
  border-radius: 4px; font-size: 12px; color: var(--text); white-space: nowrap;
}
.menu-item.open .menu-btn, .menu-btn:hover { background: var(--bg5); }
.menu-dropdown {
  display: none; position: absolute; top: 100%; left: 0;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
  min-width: 220px; padding: 4px 0; z-index: 999;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.menu-item.open .menu-dropdown { display: block; }
.menu-dropdown button {
  display: block; width: 100%; background: none; border: none;
  color: var(--text); padding: 5px 14px; text-align: left; cursor: pointer; font-size: 12px;
}
.menu-dropdown button:hover { background: var(--accent2); color: #fff; }
.menu-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 3px 0; }

/* ===== Workspace ===== */
#workspace { display: flex; flex: 1; overflow: hidden; }

/* ===== Left Panel ===== */
#left-panel {
  width: var(--left-w); min-width: var(--left-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 0; gap: 0; overflow-y: auto; overflow-x: hidden;
}

#tool-buttons {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; width: 100%; padding: 0 6px;
}
.tool-btn {
  width: 46px; height: 46px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 9px; transition: background 0.12s, border-color 0.12s; flex-shrink: 0;
}
.tool-btn svg { width: 20px; height: 20px; }
.tool-btn:hover  { background: var(--bg5); }
.tool-btn.active { background: var(--accent2); border-color: var(--accent); color: #fff; }

.tool-sep   { width: 38px; height: 1px; background: var(--border); margin: 3px auto; }
.tool-sep-h { width: 100%; height: 1px; background: var(--border); margin: 5px 0; }

/* Mini colors — FG/BG squares (no overlap with buttons) */
#mini-colors {
  position: relative;
  width: 50px; height: 50px;
  margin: 4px auto 0;
}
#mini-bg, #mini-fg {
  position: absolute; width: 30px; height: 30px; border-radius: 4px;
  border: 2px solid var(--border); cursor: pointer;
  background-image:
    linear-gradient(45deg,#555 25%,transparent 25%),
    linear-gradient(-45deg,#555 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#555 75%),
    linear-gradient(-45deg,transparent 75%,#555 75%);
  background-size: 8px 8px;
  background-position: 0 0,0 4px,4px -4px,-4px 0;
  background-color: #333;
}
#mini-bg { bottom:0; right:0; z-index:1; }
#mini-fg { top:0; left:0; z-index:2; border-color:rgba(255,255,255,0.6); }

/* Swap/Reset buttons — separate row below squares, no overlap */
#mini-btns {
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 6px;
  margin: 3px auto 0;
  width: 100%;
}
#mini-btns button {
  background: var(--bg4); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; width: 22px; height: 18px; cursor: pointer;
  font-size: 11px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
#mini-btns button:hover { background: var(--accent2); }

.mini-label { font-size:10px; color:var(--dim); text-align:center; display:block; margin-top:4px; }
#fg-alpha-input { width:48px; height:4px; accent-color:var(--accent); margin:4px auto; display:block; }
.opt-label { font-size:10px; color:var(--dim); display:flex; align-items:center; gap:3px; justify-content:center; padding:0 4px; cursor:pointer; }
.opt-label input { cursor:pointer; }

/* Mirror buttons */
#mirror-group {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 0 6px; width: 100%;
}
.mirror-btn {
  width: 46px; height: 36px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 5px;
  color: var(--dim); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 3px; transition: background 0.12s;
}
.mirror-btn svg { width: 18px; height: 18px; }
.mirror-btn span { font-size: 9px; font-weight: 700; letter-spacing: 0.05em; }
.mirror-btn:hover { background: var(--bg5); color: var(--text); }
.mirror-btn.active { background: var(--accent2); border-color: var(--accent); color: #fff; }

/* ===== Center Column (Canvas + Layer panel) ===== */
#center-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ===== Canvas Area ===== */
#canvas-area { flex:1; display:flex; flex-direction:column; overflow:hidden; background:var(--bg); min-height:0; }
#canvas-controls {
  height:34px; background:var(--bg2); border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:5px; padding:0 8px; flex-shrink:0;
}
#canvas-controls button {
  background:var(--bg3); border:1px solid var(--border); color:var(--text);
  border-radius:4px; padding:2px 9px; cursor:pointer; font-size:12px;
}
#canvas-controls button:hover { background:var(--bg5); }
#canvas-controls button.active { background:var(--accent2); border-color:var(--accent); }
#zoom-display { min-width:34px; text-align:center; font-weight:700; color:var(--accent); font-size:12px; }
.dim { color:var(--dim); font-size:11px; margin-left:auto; }
.ctrl-label { font-size:11px; color:var(--dim); white-space:nowrap; }
#brush-size-wrap { display:flex; align-items:center; gap:3px; margin-left:6px; }
#brush-size-display { min-width:18px; text-align:center; font-weight:700; color:var(--accent); font-size:12px; }
#fill-mode-wrap { display:flex; align-items:center; gap:4px; margin-left:6px; }
#outline-corners-toggle.active { background:var(--accent2); border-color:var(--accent); }

#canvas-viewport { flex:1; position:relative; overflow:hidden; cursor:crosshair; }
#main-canvas, #overlay-canvas {
  position:absolute; top:0; left:0;
  image-rendering:pixelated; image-rendering:crisp-edges;
}
#overlay-canvas { pointer-events:none; }

/* ===== Horizontal resizer (between canvas and lf-panel) ===== */
#lf-h-resizer {
  height: 5px;
  background: var(--border);
  cursor: row-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  z-index: 10;
}
#lf-h-resizer:hover, #lf-h-resizer.resizing { background: var(--accent); }

/* ===== Layer/Frame panel (below canvas) ===== */
#lf-section {
  height: 180px;
  min-height: 60px;
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
#lf-toolbar { display:flex; gap:4px; padding:4px 8px; flex-shrink:0; border-bottom:1px solid var(--border); flex-wrap:wrap; }
.lf-group { display:flex; gap:2px; }
.lf-group button {
  background:var(--bg3); border:1px solid var(--border); color:var(--text);
  border-radius:4px; padding:2px 6px; cursor:pointer; font-size:11px; white-space:nowrap;
}
.lf-group button:hover { background:var(--accent2); }

#lf-table-wrap { flex:1; overflow:auto; min-height:0; }

/* ===== Layer/Frame table ===== */
#lf-table {
  border-collapse: collapse;
  font-size: 11px;
  table-layout: auto;
  width: auto;
}
#lf-table th, #lf-table td {
  border: 1px solid var(--border);
  padding: 0;
}

/* Drag handle column */
.lf-th-handle, .lf-td-handle {
  width: 14px; min-width: 14px;
  background: var(--bg3);
  text-align: center;
  vertical-align: middle;
}
.drag-handle {
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-height: 28px;
  cursor: grab; color: var(--dim);
  font-size: 12px; line-height: 1;
  padding: 2px 0;
}
.drag-handle:hover { color: white; }
.drag-handle:active { cursor: grabbing; }
.lf-layer-row.drag-src { opacity: 0.5; }
.lf-layer-row.drag-over-top { border-top: 2px solid var(--accent) !important; }
.lf-layer-row.drag-over-bot { border-bottom: 2px solid var(--accent) !important; }

/* Corner / frame header */
.lf-corner { width: 120px; min-width: 120px; background: var(--bg3); }
.lf-fh {
  width: 36px; min-width: 36px;
  background: var(--bg3); color: var(--dim); font-size: 10px;
  text-align: center; padding: 3px 2px; cursor: pointer;
}
.lf-fh:hover { background: var(--bg5); color: var(--text); }
.lf-fh.af   { background: var(--accent2); color: #fff; border-left: 2px solid var(--accent) !important; border-right: 2px solid var(--accent) !important; }

/* Add-frame button */
.lf-add-f-cell { width: 18px; min-width: 18px; background: var(--bg3); text-align: center; }
.lf-add-f-btn  { background:none; border:none; color:var(--dim); cursor:pointer; font-size:13px; padding:2px 2px; width:100%; }
.lf-add-f-btn:hover { color:var(--accent); }

/* Layer name cell */
.lf-layer-name {
  background: var(--bg3); padding: 0 3px;
  width: 240px; min-width: 240px; vertical-align: middle;
}
.lf-layer-row.al .lf-layer-name { background: var(--bg4); }
.lf-name-row { display:flex; align-items:center; gap:2px; height:100%; min-height:28px; }

/* Visibility button */
.vis-btn {
  flex-shrink: 0;
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  color: white; opacity: 0.9;
}
.vis-btn svg { width: 14px; height: 14px; }
.vis-btn:hover { opacity: 1; }
.vis-btn.hidden-layer { opacity: 0.25; color: var(--dim); }

/* Layer name text (display mode) */
.layer-name-text {
  color: var(--text); font-size: 11px;
  width: 184px; padding: 2px 3px;
  cursor: pointer;
  border-radius: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: block;
}
.layer-name-text:hover { background: var(--bg5); }

/* Layer name input (edit mode) */
.layer-name-input {
  background: var(--bg5); border: 1px solid var(--accent2); outline: none;
  color: var(--text); font-size: 11px;
  width: 92px; padding: 2px 3px; cursor: text;
  border-radius: 3px;
}

/* Frame cell */
.lf-cell {
  width: 36px; min-width: 36px;
  vertical-align: middle; text-align: center; cursor: pointer; padding: 2px;
}
.lf-cell:hover { background: var(--bg5); }
.lf-cell.af    { background: rgba(46,122,189,0.28); border-left: 2px solid var(--accent2) !important; border-right: 2px solid var(--accent2) !important; }
.lf-cell.al    { background: rgba(255,255,255,0.04); }
.lf-cell.active { background: var(--accent2) !important; box-shadow: inset 0 0 0 2px var(--accent); }
.lf-cell canvas { display:block; margin:0 auto; border-radius:2px; image-rendering:pixelated; }

/* ===== Right Panel Resizer (horizontal) ===== */
#right-resizer {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  z-index: 10;
}
#right-resizer:hover, #right-resizer.resizing { background: var(--accent); }

/* ===== Right Panel ===== */
#right-panel {
  width: var(--right-w); min-width: 180px;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-title {
  font-size: 10px; font-weight: 700; color: var(--dim);
  text-transform: uppercase; letter-spacing: 0.06em;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 4px; flex-shrink: 0;
}
.panel-title-btns { display:flex; gap:2px; }
.panel-title-btns button, .panel-title button {
  background: var(--bg4); border: 1px solid var(--border); color: var(--text);
  border-radius: 3px; width: 18px; height: 18px; cursor: pointer;
  font-size: 13px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.panel-title button:hover, .panel-title-btns button:hover { background: var(--accent2); }

/* Palette */
#palette-section { flex-shrink: 0; overflow: hidden; display: flex; flex-direction: column; }
#color-inputs { display:flex; gap:6px; padding:0 8px 6px; font-size:11px; color:var(--dim); }
#color-inputs label { display:flex; align-items:center; gap:4px; }
#color-inputs input[type="color"] {
  width:28px; height:18px; border:1px solid var(--border); border-radius:3px;
  background:none; cursor:pointer; padding:1px;
}
#palette-grid {
  display:grid;
  grid-template-columns: repeat(auto-fill, 18px);
  gap:2px;
  padding:0 6px 6px;
  max-height:160px;
  overflow-y:auto;
  align-content: start;
}
.pal-swatch {
  width:18px; height:18px;
  border-radius:3px; border:1.5px solid transparent;
  cursor:pointer; position:relative; overflow:hidden;
  background-image:
    linear-gradient(45deg,#444 25%,transparent 25%),
    linear-gradient(-45deg,#444 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#444 75%),
    linear-gradient(-45deg,transparent 75%,#444 75%);
  background-size:6px 6px;
  background-position:0 0,0 3px,3px -3px,-3px 0;
  background-color:#333;
}
.pal-swatch:hover { transform:scale(1.18); z-index:2; }
.pal-swatch.fg-sel { border-color:#fff; }
.pal-swatch.bg-sel { border-color:#f88; }
.pal-swatch .sw-inner { position:absolute; inset:0; }

/* ===== Vertical resizer between palette and animation ===== */
#right-v-resizer {
  height: 5px;
  background: var(--border);
  cursor: row-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  z-index: 10;
}
#right-v-resizer:hover, #right-v-resizer.resizing { background: var(--accent); }

/* ===== Memo resizer ===== */
#memo-resizer {
  height: 5px;
  background: var(--border);
  cursor: row-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  z-index: 10;
}
#memo-resizer:hover, #memo-resizer.resizing { background: var(--accent); }

/* ===== Animation ===== */
#anim-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
#fps-row { display:flex; align-items:center; gap:4px; padding:4px 8px; flex-shrink:0; }
#fps-row label { display:flex; align-items:center; gap:4px; color:var(--dim); font-size:11px; }
#fps-input { width:44px; background:var(--bg3); border:1px solid var(--border); color:var(--text); border-radius:4px; padding:2px 4px; font-size:11px; text-align:center; }
#fps-row button { background:var(--bg3); border:1px solid var(--border); color:var(--text); border-radius:4px; padding:2px 8px; cursor:pointer; font-size:12px; }
#fps-row button:hover { background:var(--accent2); }
#btn-play.playing { background:var(--accent2); border-color:var(--accent); }

/* Preview controls (zoom) */
#preview-controls {
  display: flex; align-items: center; gap:4px; padding: 2px 8px; flex-shrink:0;
}
#preview-controls button {
  background:var(--bg3); border:1px solid var(--border); color:var(--text);
  border-radius:3px; width:20px; height:20px; cursor:pointer; font-size:13px; font-weight:700;
  display:flex; align-items:center; justify-content:center; padding:0;
}
#preview-controls button:hover { background:var(--accent2); }
#preview-zoom-display { color:var(--dim); font-size:11px; min-width:34px; text-align:center; }

/* Preview scroll area */
#preview-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 0;
  padding: 4px;
}
#preview-canvas {
  display: block;
  border: 1px solid var(--border);
  border-radius: 3px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

/* ===== Status ===== */
#statusbar {
  height: var(--footer-h); background:var(--bg2); border-top:1px solid var(--border);
  display:flex; align-items:center; gap:14px; padding:0 10px; font-size:11px; color:var(--dim); flex-shrink:0;
}

/* ===== Modal ===== */
#modal-overlay, #save-modal-overlay, #export-modal-overlay, #outline-modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,0.6); display:flex; align-items:center; justify-content:center; z-index:9999; }
#modal-overlay.hidden, #save-modal-overlay.hidden, #export-modal-overlay.hidden, #outline-modal-overlay.hidden { display:none; }
#modal-box, #save-modal-box, #export-modal-box, #outline-modal-box { background:var(--bg2); border:1px solid var(--border); border-radius:10px; padding:20px 24px; min-width:280px; box-shadow:0 16px 48px rgba(0,0,0,0.6); }
#modal-box h2, #save-modal-box h2, #export-modal-box h2, #outline-modal-box h2 { font-size:15px; color:var(--text); margin-bottom:14px; }
#modal-content { display:flex; flex-direction:column; gap:8px; margin-bottom:16px; }
#modal-content label { display:flex; align-items:center; gap:10px; color:var(--dim); font-size:12px; }
#modal-content input[type="number"] { width:72px; background:var(--bg3); border:1px solid var(--border); color:var(--text); border-radius:4px; padding:3px 6px; font-size:12px; }
.modal-presets { display:flex; gap:4px; flex-wrap:wrap; }
.modal-presets button { background:var(--bg3); border:1px solid var(--border); color:var(--text); border-radius:4px; padding:3px 7px; cursor:pointer; font-size:11px; }
.modal-presets button:hover { background:var(--accent2); }
.modal-buttons { display:flex; gap:8px; justify-content:flex-end; }
.modal-buttons button { background:var(--bg3); border:1px solid var(--border); color:var(--text); border-radius:5px; padding:5px 16px; cursor:pointer; font-size:12px; }
.modal-buttons button:hover { background:var(--bg5); }
#modal-ok, #save-modal-ok, #outline-ok { background:var(--accent2); border-color:var(--accent); color:#fff; }
#modal-ok:hover, #save-modal-ok:hover, #outline-ok:hover { background:var(--accent); }
#outline-modal-content { display:flex; flex-direction:column; gap:8px; margin-bottom:16px; }
#outline-modal-content label { display:flex; align-items:center; gap:8px; color:var(--dim); font-size:12px; cursor:pointer; }

/* Save modal content */
#save-modal-content { display:flex; flex-direction:column; gap:8px; margin-bottom:16px; }
#save-modal-content label { display:flex; align-items:center; gap:8px; color:var(--dim); font-size:12px; flex-wrap:wrap; }
#save-fname-input { width:140px; background:var(--bg3); border:1px solid var(--border); color:var(--text); border-radius:4px; padding:3px 6px; font-size:12px; }
#save-fname-input:focus { outline:none; border-color:var(--accent); }
#save-ext-display { color:var(--dim); font-size:12px; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width:5px; height:5px; }
::-webkit-scrollbar-track { background:var(--bg2); }
::-webkit-scrollbar-thumb { background:var(--bg4); border-radius:3px; }
::-webkit-scrollbar-thumb:hover { background:var(--accent2); }

/* ===== About ===== */
#about-section {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 7px 8px;
}
#about-content { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.about-title { font-size: 11px; font-weight: 700; color: #f08030; }
.about-ver   { font-size: 10px; color: var(--dim); }
.about-copy  { font-size: 10px; color: var(--dim); }

/* ===== Export Modal ===== */
#export-modal-content { display:flex; flex-direction:column; gap:8px; margin-bottom:16px; }
#export-modal-content label { display:flex; align-items:center; gap:8px; color:var(--dim); font-size:12px; }
#export-scale-select {
  background:var(--bg3); border:1px solid var(--border); color:var(--text);
  border-radius:4px; padding:3px 6px; font-size:12px; cursor:pointer;
}
#export-scale-select:focus { outline:none; border-color:var(--accent); }

/* ===== Memo Panel ===== */
#memo-section {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#memo-wrap { padding: 4px 6px; }
#memo-textarea {
  width: 100%;
  height: 80px;
  resize: vertical;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  padding: 4px;
  box-sizing: border-box;
  font-family: inherit;
}
#memo-textarea:focus { outline: none; border-color: var(--accent); }

/* ===== Rotation cursor ===== */
.cursor-rotate { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z' fill='white' stroke='black' stroke-width='0.5'/%3E%3C/svg%3E") 12 12, crosshair; }

/* ===== Resize Canvas Modal ===== */
#resize-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
#resize-modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  min-width: 200px;
}
#resize-modal-box h2 { font-size: 14px; margin-bottom: 14px; color: var(--text); }
#resize-modal-content { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 16px; }
.resize-size-row { display: flex; gap: 12px; }
.resize-size-row label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--dim); }
.resize-size-row input[type="number"] {
  width: 60px; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; padding: 3px 5px; font-size: 12px;
}
.resize-size-row input[type="number"]:focus { outline: none; border-color: var(--accent); }
#resize-anchor-grid { display: grid; grid-template-columns: repeat(3, 22px); gap: 3px; }
.resize-anchor-btn {
  width: 22px; height: 22px;
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: 3px; cursor: pointer;
}
.resize-anchor-btn:hover { background: var(--bg5); }
.resize-anchor-btn.active { background: var(--accent); border-color: var(--accent); }

/* ===== Tab drag reorder ===== */
.editor-tab.tab-dragging { opacity: 0.4; }
.editor-tab.tab-drag-over { border-left: 2px solid var(--accent); }

.hidden { display:none !important; }

/* ===== Help Modals (Tutorial / Privacy / About) ===== */
#tutorial-modal-overlay, #privacy-modal-overlay, #about-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#tutorial-modal-overlay.hidden, #privacy-modal-overlay.hidden, #about-modal-overlay.hidden { display: none; }

.help-modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  display: flex; flex-direction: column; gap: 12px;
}
.help-modal-box h2 { font-size: 15px; color: var(--text); margin: 0; }

/* Tutorial */
#tutorial-modal-box { width: min(580px, 94vw); max-height: 88vh; overflow-y: auto; }
.help-section-title { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 6px; }
.tut-table { width: 100%; border-collapse: collapse; font-size: 11px; color: var(--text); }
.tut-table tr:nth-child(even) td { background: rgba(255,255,255,0.03); }
.tut-table td { padding: 4px 6px; vertical-align: middle; }
.tut-key { font-family: monospace; background: var(--bg3); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; white-space: nowrap; color: var(--accent2); font-size: 11px; text-align: center; width: 1%; }
.tut-desc { color: var(--dim); font-size: 11px; }
.tut-steps { margin: 4px 0 0 16px; padding: 0; font-size: 12px; color: var(--text); display: flex; flex-direction: column; gap: 4px; }
.tut-steps li { line-height: 1.5; }

/* Privacy */
#privacy-modal-box { width: min(620px, 94vw); }
#privacy-content { max-height: 60vh; overflow-y: auto; font-size: 12px; color: var(--text); display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
#privacy-content h3 { font-size: 13px; color: var(--accent); margin: 6px 0 2px; }
#privacy-content h4 { font-size: 12px; color: var(--text); margin: 6px 0 2px; }
#privacy-content p { margin: 0; color: var(--dim); line-height: 1.6; }
#privacy-content a { color: var(--accent2); }
#privacy-content code { background: var(--bg3); border-radius: 3px; padding: 1px 4px; font-size: 11px; }
.priv-hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.priv-date { font-size: 11px; color: var(--dim); margin-top: 4px; }
.priv-lang-section { display: flex; flex-direction: column; gap: 4px; }

/* About */
#about-modal-box { width: min(360px, 90vw); text-align: center; }
#about-modal-content { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0 8px; }
.about-modal-logo { font-size: 40px; line-height: 1; }
.about-modal-name { font-size: 16px; font-weight: 700; color: var(--text); }
.about-modal-ver  { font-size: 12px; color: var(--dim); }
.about-modal-copy { font-size: 12px; color: var(--dim); }
.about-modal-desc { font-size: 12px; color: var(--dim); margin-top: 6px; }
.about-modal-links { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; }
.about-modal-links a { color: var(--accent2); text-decoration: none; }
.about-modal-links a:hover { text-decoration: underline; }
.about-modal-sep { color: var(--dim); }

/* Terms of Service Modal */
#terms-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 9999; }
#terms-modal-overlay.hidden { display: none; }
#terms-modal-box { width: min(520px, 94vw); }
#terms-content { display: flex; flex-direction: column; }
.terms-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.terms-item:last-child { border-bottom: none; }
.terms-num { flex-shrink: 0; width: 22px; height: 22px; background: var(--accent); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; margin-top: 1px; }
.terms-heading { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.terms-item p { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.6; }
