#app *, #app *::before, #app *::after { box-sizing: border-box; }
#app { display: flex; flex-direction: column; color: #ddd; background: #222; }
#mainBody { min-height: 600px; }
#titlebar { display: flex; align-items: center; height: 36px; background: #2a2a2a; border-bottom: 1px solid #555; padding: 0 8px; flex-shrink: 0; position: relative; }
#backLink { text-decoration: none; color: #d97706; font-size: 18px; line-height: 1; padding: 4px 8px; }
#backLink:hover { color: #f59e0b; }
#titleText { flex: 1; text-align: center; font-size: 14px; font-weight: 600; color: #d97706; }
#copyrightBtn { background: none; border: none; color: #888; font-size: 16px; cursor: pointer; padding: 4px 8px; line-height: 1; }
#copyrightBtn:hover { color: #ccc; }
#copyrightPopup { display:none; position:absolute; top:100%; right:0; background:#333; border:1px solid #555; border-radius:4px; padding:8px 10px; font-size:11px; line-height:1.5; white-space:nowrap; z-index:50; color:#ccc; }
#copyrightPopup.show { display:block; }
#copyrightPopup a { color:#d97706; text-decoration:none; }
#copyrightPopup a:hover { color:#f59e0b; text-decoration:underline; }
#mainBody { display: flex; flex: 1; min-height: 0; }
#planeView { flex: 1; position: relative; min-width: 0; }
#planeCanvas { display: block; width: 100%; height: 100%; cursor: crosshair; position: absolute; top: 0; left: 0; }
#gridCanvas { display: block; width: 100%; height: 100%; pointer-events: none; position: absolute; top: 0; left: 0; }
#sidePanel { width: 260px; display: flex; flex-direction: column; background: #333; border-left: 1px solid #555; overflow-y: auto; }
#tileView { width: 100%; height: 208px; background: #444; border-bottom: 1px solid #555; }
#tileCanvas { display: block; width: 100%; height: 100%; }
#planeCanvas, #tileCanvas, #undoBtn, #redoBtn { touch-action: none; }
.panel { padding: 8px 10px; border-bottom: 1px solid #444; }
.panel-title { font-size: 11px; text-transform: uppercase; color: #999; margin-bottom: 4px; letter-spacing: 1px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.group-btn { padding: 3px 6px; font-size: 11px; background: #444; color: #ccc; border: 1px solid #555; border-radius: 3px; cursor: pointer; }
.group-btn.active { background: #4488cc; color: #fff; border-color: #3377bb; }
.group-btn:hover { background: #555; }
.group-btn.active:hover { background: #5599dd; }
.stroke-btn { background: #444; border: 1px solid #555; border-radius: 2px; cursor: pointer; padding: 2px; }
.stroke-btn.active { outline: 2px solid #fff; outline-offset: 1px; }
.stroke-btn canvas { display: block; }
.action-btn { padding: 5px 10px; background: #444; color: #ccc; border: 1px solid #555; border-radius: 3px; cursor: pointer; font-size: 12px; }
.action-btn:hover { background: #555; color: #fff; }
.action-btn.primary { background: #4488cc; color: #fff; border-color: #3377bb; }
.action-btn.primary:hover { background: #5599dd; }
.action-btn.danger { background: #cc4444; color: #fff; border-color: #bb3333; }
.action-btn.danger:hover { background: #dd5555; }
.icon-btn { font-size: 16px; line-height: 1; }
.grid-lbl { display: flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; }
.grid-lbl input { accent-color: #4488cc; }
.grid-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
#status { font-size: 11px; color: #888; padding: 6px 10px; }
#togglePanelBtn { position:absolute; top:50%; right:0; z-index:20; width:22px; height:64px; padding:0; background:#555; border:1px solid #666; border-right:none; border-radius:4px 0 0 4px; cursor:pointer; font-size:14px; color:#d97706; line-height:64px; text-align:center; transform:translate(0,-50%); }
#togglePanelBtn:hover { background:#666; color:#f59e0b; }
#sidePanel.collapsed { display:none; }
.flex-row { display: flex; gap: 4px; }
.flex-row .action-btn { flex: 1; text-align: center; }
#colorPopup { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:100; }
#colorPopup.show { display:block; }
#colorPopupInner { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); background:#333; padding:16px; border-radius:6px; display:flex; gap:16px; align-items:center; }
.preset-grid { display:grid; grid-template-columns:repeat(5,1fr); gap:3px; align-content:start; min-width:140px; }
.preset-swatch { aspect-ratio:1; border-radius:3px; border:1px solid #555; cursor:pointer; }
.preset-swatch:hover { border-color:#d97706; }
@media (max-width: 700px) {
  #sidePanel { width: 200px; }
}
