:root{
  --bg:#0f1724;
  --panel:#0b1220;
  --surface:#07101a;
  --glass:rgba(255,255,255,0.03);
  --muted:#9aa7b2;
  --text:#e6eef6;
  --accent:#7722ff;
  --radius:12px;
  --shadow:0 6px 20px rgba(2,6,23,0.6);
  --canvas-grid:#1a2533;
  --canvas-grid-2: #0a1320;
}
[data-theme="light"]{
  --bg:#f4f6fb;
  --panel:#ffffff;
  --surface:#f0f2f8;
  --glass:rgba(0,0,0,0.04);
  --muted:#5b6472;
  --text:#0f1724;
  --accent:#5b5df5;
  --canvas-grid:#d4e5fa;
  --canvas-grid-2: #e9ecf0;
}
*{box-sizing:border-box}
html,body,#app{height:100%}
body{
  margin:0;
  font-family:Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}
#app {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
}
.toolbar{grid-row:1 / span 2;background:transparent;display:flex;flex-direction:column;gap:12px;padding:8px;border-radius:12px}
.toolbar .tools{display:flex;flex-direction:column;gap:8px}
.tool{width:56px;height:56px;border-radius:10px;border:0;background:var(--glass);display:flex;flex-direction:column;align-items:center;justify-content:center;color:var(--muted);cursor:pointer;transition:all .15s}
.tool span{display:none;font-size:11px}
.tool.active{background:linear-gradient(180deg,var(--accent),#6f6bf5);color:white;box-shadow:0 6px 18px rgba(79,70,229,0.18);transform:translateY(-2px)}
.toolbar .zoom-tools {
    display: flex;
    gap: 6px;
    padding-top: 6px;
    flex-direction: column;
}
.tool-options{margin-top:auto;background:rgba(255,255,255,0.02);padding:10px;border-radius:10px;display:flex;flex-direction:column;gap:10px}
.active-tool{display:flex;gap:10px;align-items:center}
.active-tool i{width:36px;height:36px;display:flex;align-items:center;justify-content:center}
.active-tool .small{font-size:11px;color:var(--muted)}
.option{display:flex;flex-direction:column;gap:6px}
.option input[type="range"]{width:100%}
.option input[type="color"]{height:36px;border-radius:6px;border:0;padding:0}
.topbar{grid-column:1 / span 3;height:64px;border-radius:12px;background:linear-gradient(90deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));display:flex;align-items:center;justify-content:space-between;padding:0 18px;box-shadow:var(--shadow)}
.topbar button{background:transparent;border:0;color:var(--muted);padding:8px;border-radius:8px;cursor:pointer}
.topbar .file-controls{display:flex;align-items:center;gap:10px}
.topbar input[type=number]{width:88px;padding:6px;border-radius:8px;border:0;background:rgba(255,255,255,0.02);color:inherit}
.workspace {
    display: flex;
    gap: 18px;
    align-items: stretch;
    flex: 1;
}
.canvas-panel{flex:1;display:flex;flex-direction:column;gap:12px}
.canvas-viewport {
    flex: 1;
    border-radius: 12px;
    background: transparent;
    overflow: hidden;
    position: relative;
    padding: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 480px;
    width: min-content;
}
.checkerboard {
    display: none;
}
.canvas-wrap {
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: top left;
    background-image: repeating-linear-gradient(45deg, var(--canvas-grid) 25%, transparent 25%, transparent 75%, var(--canvas-grid) 75%, var(--canvas-grid)), repeating-linear-gradient(45deg, var(--canvas-grid) 25%, var(--canvas-grid-2) 25%, var(--canvas-grid-2) 75%, var(--canvas-grid) 75%, var(--canvas-grid));
    background-position: 0 0, 10px 10px;
    background-size: 20px 20px;
}
#display-canvas{background:transparent;display:block;border-radius:4px;box-shadow:inset 0 0 0 1px rgba(255,255,255,0.02);cursor:crosshair}
.layers-panel{background:linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));border-radius:12px;padding:12px;display:flex;flex-direction:column;gap:12px;min-height:360px}
.layers-header{display:flex;justify-content:space-between;align-items:center}
.layer-actions button{background:transparent;border:1px solid rgba(255,255,255,0.03);padding:6px 8px;border-radius:8px;color:var(--muted)}
.layers-list{display:flex;flex-direction:column;gap:8px;overflow:auto;padding-right:6px}
.layer-item{height:var(--layer-item-height);display:flex;align-items:center;gap:10px;padding:8px;border-radius:10px;background:rgba(255,255,255,0.015);border:1px solid transparent;cursor:pointer}
.layer-item.dragging{opacity:.5}
.layer-item.active{border-color:rgba(79,70,229,0.25);box-shadow:0 6px 18px rgba(79,70,229,0.06)}
.layer-thumb{width:56px;height:40px;border-radius:6px;background:#0b1116;overflow:hidden;flex-shrink:0;display:flex;align-items:center;justify-content:center}
.layer-meta{flex:1;display:flex;flex-direction:column;gap:4px}
.layer-title{display:flex;justify-content:space-between;align-items:center;gap:8px}
.layer-title .name{font-size:13px}
.layer-controls{display:flex;gap:8px;align-items:center}
.layer-controls button{background:transparent;border:0;color:var(--muted);cursor:pointer;height:36px;width:36px;border-radius:8px}
.layer-opacity{width:100%}
.muted{color:var(--muted);font-size:12px}
.small{font-size:12px}
button,input,select{font-family:inherit}
@media (max-width:980px){
  .layers-panel{grid-row:3;grid-column:1 / span 2}
}
button {
    color: var(--muted);
    cursor: pointer;
    border-radius: 10px;
    border-width: 0px;
    background: var(--glass);
}
.toolbar .zoom-tools button {
    color: var(--muted);
    cursor: pointer;
    border-radius: 10px;
    border-width: 0px;
    background: var(--glass);
    width: 56px;
    height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.toolbar .zoom-tools {
    display: flex;
    gap: 6px;
    padding-top: 6px;
    flex-direction: column;
    border-top: 1px solid var(--muted);
    width: 56px;
}
input[type="range"] {
    accent-color: var(--accent);
}
#settings-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.55);
  display:flex;
  align-items:center;
  justify-content:center;
  opacity:0;
  pointer-events:none;
  transition:opacity .2s ease;
  z-index:999;
}

#settings-overlay.open{
  opacity:1;
  pointer-events:auto;
}

.settings-modal{
  background:var(--panel);
  border-radius:14px;
  width:320px;
  box-shadow:var(--shadow);
  transform:scale(.92);
  transition:transform .2s ease;
}

#settings-overlay.open .settings-modal{
  transform:scale(1);
}

.settings-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 16px;
  border-bottom:1px solid var(--glass);
}

.settings-header .title{
  font-weight:600;
}

.settings-header button{
  background:transparent;
  border:0;
  color:var(--muted);
}

.settings-content{
  padding:16px;
}

.setting{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
}
#color {
    width: 100%;
    min-width: 100px;
    padding: 10px;
    border: 1px solid rgba(150, 150, 150, 0.1);
    border-radius: 0.5rem;
    background: var(--glass);
    color: var(--text);
    font-size: 0.875rem;
}

.setting select{
  background:var(--surface);
  color:var(--text);
  border-radius:8px;
  border:0;
  padding:6px 10px;
}