:root {
  --bg: #111827;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #d0d5dd;
  --blue: #2563eb;
  --blue-2: #eff6ff;
  --green: #10b981;
  --danger: #dc2626;
  --warn: #f59e0b;
  --shadow: 0 10px 30px rgba(15, 23, 42, .18);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Meiryo, "Yu Gothic", system-ui, sans-serif;
  color: var(--ink);
  background: #0b1220;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
#app {
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr) 30px;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}
#app.ad-hidden { grid-template-rows: 62px minmax(0, 1fr) 30px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 9px 14px; background: #f8fafc; border-bottom: 1px solid #d8dee7;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; background: #111827; color: #fff; font-weight: 800;
}
.brand-title { font-weight: 800; letter-spacing: .04em; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.btn, .mini {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; min-height: 36px; padding: 7px 10px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .05);
}
.btn { display: inline-flex; align-items: center; gap: 6px; }
.btn:hover, .mini:hover { border-color: #98a2b3; background: #f9fafb; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn:disabled, .mini:disabled { opacity: .45; cursor: not-allowed; }
.sep { width: 1px; height: 28px; background: #d0d5dd; margin: 0 4px; }
.workspace { min-height: 0; display: grid; grid-template-columns: 84px 1fr 340px; }
.toolbar {
  background: #f8fafc; border-right: 1px solid #d8dee7; padding: 8px 7px;
  display: flex; flex-direction: column; gap: 6px; overflow-y: auto;
}
.tool-group {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 5px;
  background: #eef2ff;
  display: grid;
  gap: 5px;
}
.tool-group:nth-of-type(2) { background: #f8fafc; }
.group-title {
  font-size: 10px;
  color: #344054;
  text-align: center;
  font-weight: 800;
  letter-spacing: .02em;
  padding: 2px 0;
}
.tool {
  width: 68px; min-height: 52px; border: 1px solid #d0d5dd; background: #fff; border-radius: 12px;
  display: grid; place-items: center; gap: 1px; color: #111827;
}
.tool.sub { width: 56px; min-height: 48px; justify-self: center; }
.tool span { font-weight: 800; font-size: 20px; line-height: 1; }
.tool small { color: #475467; font-size: 11px; line-height: 1; }
.tool:hover { background: #f2f4f7; }
.tool.active { background: var(--blue-2); border-color: var(--blue); color: var(--blue); }
.tool.active small { color: var(--blue); }
.stage-wrap { min-width: 0; min-height: 0; display: grid; grid-template-rows: 42px 1fr 30px; background: #1f2937; }
.stage-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 5px 8px; background: #f3f4f6; border-bottom: 1px solid #d8dee7;
}
.zoom-actions, .image-actions, .row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mini { min-height: 30px; padding: 4px 9px; border-radius: 8px; font-size: 13px; }
.mini.danger { color: #fff; border-color: var(--danger); background: var(--danger); }
.mini.warn { color: #111827; border-color: #fbbf24; background: #fef3c7; }
.mini.action { color: #fff; border-color: #059669; background: #059669; }
.zoom-label { min-width: 55px; text-align: center; color: #344054; font-size: 13px; }
.stage {
  min-width: 0; min-height: 0; position: relative; overflow: hidden;
  background-color: #273244;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.05) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0px;
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.drop-hint { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.drop-card {
  width: min(440px, 80%); padding: 30px; border-radius: 22px; background: rgba(255,255,255,.92);
  text-align: center; box-shadow: var(--shadow); border: 1px solid rgba(255,255,255,.6);
}
.drop-icon { font-size: 44px; }
.drop-title { font-size: 20px; font-weight: 800; margin-top: 10px; }
.drop-sub { color: var(--muted); margin-top: 8px; font-size: 13px; }
.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 5px 10px; background: #f8fafc; border-top: 1px solid #d8dee7;
  color: #475467; font-size: 12px; white-space: nowrap;
}
.sidepanel {
  min-height: 0; overflow-y: auto; background: #f8fafc; border-left: 1px solid #d8dee7;
  padding: 10px; display: flex; flex-direction: column; gap: 10px;
}
.panel { background: #fff; border: 1px solid #d8dee7; border-radius: 14px; padding: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.help { margin: 0 0 10px; font-size: 12px; color: #475467; line-height: 1.55; }
.selection-state {
  display: flex; justify-content: space-between; align-items: center;
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  border-radius: 10px; padding: 7px 9px; font-size: 12px; margin-bottom: 10px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label { display: grid; gap: 4px; color: #344054; font-size: 12px; }
input, select {
  width: 100%; border: 1px solid #d0d5dd; border-radius: 9px; padding: 6px 8px; background: #fff;
}
input[type="color"] { height: 34px; padding: 2px; }
.wide { margin-top: 8px; }
.size-current {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 7px 9px;
  font-size: 12px;
  color: #344054;
  margin-bottom: 8px;
}
.checkline {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  margin: 6px 0 10px;
}
.checkline input {
  width: auto;
}
.range { margin: 8px 0; }
.range input { padding: 0; }
.row-actions { margin-top: 10px; }
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.layer-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 7px;
  border: 1px solid #d0d5dd; border-radius: 10px; padding: 7px; background: #fff;
}
.layer-item.active { border-color: var(--blue); background: var(--blue-2); }
.layer-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

.site-footer {
  width: 100%;
  min-height: 30px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, .92);
  border-top: 1px solid rgba(216, 222, 231, .75);
  color: #1565c0;
  font-size: 13px;
  line-height: 1.45;
}
.site-footer p { margin: 0; }
.site-footer a {
  color: #1565c0;
  text-decoration: none;
  font-weight: 700;
}
.site-footer a:hover { text-decoration: underline; }
.text-editor {
  display: none; position: fixed; z-index: 50; min-width: 220px; min-height: 70px;
  border: 2px solid var(--blue); border-radius: 10px; padding: 8px;
  background: rgba(255,255,255,.98); resize: both; box-shadow: var(--shadow); outline: none;
}

.context-menu {
  position: fixed;
  z-index: 100;
  min-width: 190px;
  display: none;
  padding: 6px;
  border: 1px solid #d0d5dd;
  border-radius: 12px;
  background: rgba(255,255,255,.98);
  box-shadow: var(--shadow);
}
.context-menu.show { display: grid; gap: 2px; }
.context-menu button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #111827;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
}
.context-menu button:hover:not(:disabled) { background: #eef2ff; }
.context-menu button:disabled { color: #98a2b3; cursor: not-allowed; }
.context-separator { width: 100%; border: 0; border-top: 1px solid #d0d5dd; margin: 2px 0; }
.menu-separator { height: 1px; background: #e5e7eb; margin: 4px 2px; }

@media (max-width: 1000px) {
  #app { grid-template-rows: auto minmax(0, 1fr) 30px; }
  #app.ad-hidden { grid-template-rows: auto minmax(0, 1fr) 30px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .workspace { grid-template-columns: 84px 1fr; }
  .sidepanel { position: fixed; right: 10px; top: 86px; bottom: 12px; width: 320px; z-index: 20; box-shadow: var(--shadow); border-radius: 16px; }
}
