/* コマノート — プロ向けペイントソフト風のダークテーマ */
:root {
  --bg0: #1c1c1c;
  --bg1: #262626;
  --bg2: #2f2f2f;
  --bg3: #3a3a3a;
  --bg4: #474747;
  --line: #151515;
  --text: #dcdcdc;
  --text-dim: #9a9a9a;
  --accent: #3d8ee6;
  --accent-dim: #2a5f99;
  --danger: #d9534f;
  --canvas-bg: #5a5a5a;
  --touch: 40px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg0); color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.ic { display: block; flex: none; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- ボタン・入力 ---------- */
.btn {
  border: 1px solid #555; background: var(--bg4); border-radius: 4px;
  padding: 7px 14px; min-height: 34px; white-space: nowrap;
}
.btn:hover { background: #525252; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4f9cf0; }
.btn.danger { color: #ff8a86; }
.btn.danger.primary { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; min-height: 28px; font-size: 12px; }
.btn:disabled { opacity: .4; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 6px;
  border: 1px solid transparent; border-radius: 4px; background: transparent;
}
.icon-btn:hover { background: var(--bg4); }
.icon-btn.text { font-size: 11px; }
.icon-btn.on, .icon-btn.active { background: var(--accent-dim); }

.input, .select {
  width: 100%; min-height: 32px; padding: 4px 8px;
  background: var(--bg1); border: 1px solid #555; border-radius: 4px;
  -webkit-user-select: text; user-select: text;
}
textarea.input { min-height: 120px; resize: vertical; line-height: 1.6; }
.select { padding-right: 4px; }

.range { width: 100%; height: 24px; margin: 0; accent-color: var(--accent); }

/* ---------- ホーム ---------- */
.home-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg3); border-bottom: 1px solid var(--line);
}
.logo { font-size: 20px; font-weight: 700; letter-spacing: .05em; }
.logo small { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: 8px; }
.project-grid {
  flex: 1; overflow-y: auto; padding: 24px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 22px; align-content: start;
  -webkit-overflow-scrolling: touch;
}
.project-card { display: flex; flex-direction: column; gap: 4px; background: none; border: none; padding: 0; text-align: left; }
.card-thumb {
  height: 230px; width: 100%; padding: 0; border: 1px solid #444; border-radius: 6px;
  background: var(--bg2); display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card-thumb img { max-width: 100%; max-height: 100%; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.card-thumb .blank { width: 60%; height: 85%; background: #fff; }
.project-card.new .card-thumb { border-style: dashed; color: var(--text-dim); }
.project-card.new:hover .card-thumb { border-color: var(--accent); color: var(--accent); }
.card-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--text-dim); font-size: 12px; }
.card-meta.small { font-size: 11px; }
.card-actions { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.card-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.card-row .card-name { flex: 1; min-width: 0; }
.card-mark, .card-info { flex: none; width: 30px; height: 30px; border: none; border-radius: 15px; background: none; color: var(--text-dim); font-size: 16px; padding: 0; }
.card-mark:hover, .card-info:hover { background: var(--bg3); color: var(--text); }
.notice-body h4 { margin: 14px 0 6px; font-size: 13px; color: #fff; }
.notice-body ul, .notice-body ol { margin: 0; padding-left: 22px; line-height: 1.7; color: #ccc; }
.notice-box.ok { background: #20392a; color: #bfe8cc; border-color: #2f5a3d; }
.notice-box { margin: 8px 0; background: #3d3420; color: #f3dfa2; border: 1px solid #5a4a20; border-radius: 4px; padding: 10px 12px; line-height: 1.6; }
.empty { color: var(--text-dim); }

/* ---------- エディタ全体 ---------- */
#menubar {
  display: flex; align-items: center; gap: 4px; flex: none;
  height: calc(42px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0;
  background: var(--bg3); border-bottom: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
}
#menus { display: flex; }
.menu-btn { background: none; border: none; padding: 0 10px; height: 34px; border-radius: 4px; }
.menu-btn:hover { background: var(--bg4); }
#quick { display: flex; align-items: center; gap: 1px; margin-left: 6px; }
.qbtn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 34px; border: none; background: none; border-radius: 4px; }
.qbtn:hover { background: var(--bg4); }
.qbtn:disabled { opacity: .3; }
.qbtn.wide { width: auto; padding: 0 10px; font-size: 12px; border: 1px solid #555; height: 28px; }
.qsep { width: 1px; height: 22px; background: #555; margin: 0 4px; }
.chip { border: 1px solid #555; background: var(--bg2); border-radius: 14px; padding: 3px 10px; font-size: 12px; }
#doc-title { color: var(--text-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
#status { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--bg2); color: var(--text-dim); margin-left: 6px; }
#status[data-state="未保存"] { color: #f0c419; }
#status[data-state="保存エラー"] { color: #ff6b6b; }

.menu-pop {
  position: fixed; z-index: 50; min-width: 240px; padding: 4px 0;
  background: var(--bg3); border: 1px solid #111; border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.menu-item { display: flex; align-items: center; width: 100%; min-height: 34px; padding: 0 12px 0 4px; border: none; background: none; text-align: left; }
.menu-item:hover { background: var(--accent); color: #fff; }
.menu-check { width: 22px; text-align: center; }
.menu-label { flex: 1; }
.menu-key { color: var(--text-dim); font-size: 11px; margin-left: 20px; }
.menu-item:hover .menu-key { color: #fff; }
.menu-sep { height: 1px; background: #555; margin: 4px 0; }

#workspace { flex: 1; display: flex; min-height: 0; position: relative; }

#toolbar {
  width: 50px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; background: var(--bg2); border-right: 1px solid var(--line); overflow-y: auto;
}
.tool-btn { width: 42px; height: 40px; border: 1px solid transparent; border-radius: 4px; background: none; display: flex; align-items: center; justify-content: center; }
.tool-btn:hover { background: var(--bg4); }
.tool-btn.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }

.dock { flex: none; display: flex; flex-direction: column; background: var(--bg2); min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#left-dock { width: 236px; border-right: 1px solid var(--line); }
#right-dock { width: 260px; border-left: 1px solid var(--line); }
.palette { border-bottom: 1px solid var(--line); flex: none; }
.palette.grow { flex: 1 0 auto; }
.pal-title { margin: 0; padding: 5px 8px; font-size: 11.5px; font-weight: 600; color: #bbb; background: var(--bg3); border-bottom: 1px solid var(--line); }

#editor.hide-left #left-dock, #editor.hide-right #right-dock, #editor.hide-pages #pages { display: none; }

/* 狭い画面ではパレットをキャンバスの上に重ねる */
@media (max-width: 999px) {
  #left-dock { position: absolute; left: 50px; top: 0; bottom: 0; z-index: 20; box-shadow: 4px 0 16px rgba(0,0,0,.5); }
  #right-dock { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -4px 0 16px rgba(0,0,0,.5); }
}

#canvas-wrap { flex: 1; position: relative; overflow: hidden; background: var(--canvas-bg); min-width: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#cursor { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#float-ui { position: absolute; inset: 0; pointer-events: none; }
#float-ui > * { pointer-events: auto; }

/* ---------- サブツール・プロパティ ---------- */
.subtools { display: flex; flex-direction: column; padding: 4px; gap: 2px; }
.subtool { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 8px; border: 1px solid transparent; border-radius: 3px; background: none; text-align: left; }
.subtool:hover { background: var(--bg4); }
.subtool.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.sub-ic { opacity: .8; }

.toolprops { padding: 6px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.prop { display: flex; flex-direction: column; gap: 2px; }
.prop.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.prop-head { display: flex; justify-content: space-between; align-items: baseline; }
.prop-label { font-size: 12px; color: #c4c4c4; }
.prop-val { font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.prop.check, .check { flex-direction: row; align-items: center; gap: 8px; min-height: 28px; }
.check input, .prop.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.check.mini { font-size: 12px; white-space: nowrap; display: flex; }
.segment { display: flex; border: 1px solid #555; border-radius: 4px; overflow: hidden; }
.seg { flex: 1; min-height: 30px; border: none; background: var(--bg1); font-size: 12px; padding: 0 4px; }
.seg + .seg { border-left: 1px solid #555; }
.seg.active { background: var(--accent-dim); color: #fff; }
.reset { align-self: flex-start; margin-top: 4px; }
.hint { color: var(--text-dim); font-size: 12px; margin: 4px 0; line-height: 1.5; }
.btn-row { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 6px; }
.row { display: flex; gap: 6px; align-items: center; }

/* ---------- カラー ---------- */
.color { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.color-top { display: flex; align-items: center; gap: 6px; }
.slots { position: relative; width: 52px; height: 40px; }
.slot { position: absolute; width: 30px; height: 30px; border: 2px solid #777; border-radius: 3px; padding: 0; }
.slot.main { left: 0; top: 0; z-index: 2; }
.slot.sub { left: 18px; top: 10px; z-index: 1; }
.slot.active { border-color: #fff; box-shadow: 0 0 0 1px var(--accent); z-index: 3; }
.slot.transparent {
  position: static; width: 28px; height: 28px;
  background: repeating-conic-gradient(#bbb 0 25%, #fff 0 50%) 0 0 / 10px 10px;
}
.hex { font-size: 11.5px; color: var(--text-dim); font-family: ui-monospace, Menlo, monospace; margin-left: auto; }
.sv-wrap { position: relative; height: 120px; touch-action: none; }
.sv { width: 100%; height: 100%; display: block; border-radius: 3px; touch-action: none; }
.sv-marker { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #000; pointer-events: none; }
.hue-wrap { position: relative; height: 16px; touch-action: none; }
.hue { width: 100%; height: 100%; display: block; border-radius: 3px; touch-action: none; }
.hue-marker { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; border: 2px solid #fff; border-radius: 2px; box-shadow: 0 0 0 1px #000; pointer-events: none; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.swatches.recent:empty { display: none; }
.sw { width: 20px; height: 20px; border: 1px solid #666; border-radius: 3px; padding: 0; }

/* ---------- ナビゲーター ---------- */
.nav { padding: 6px 10px 8px; display: flex; flex-direction: column; gap: 6px; }
.nav-view { position: relative; height: 150px; background: var(--bg1); border-radius: 3px; touch-action: none; }
.nav-thumb, .nav-over { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- レイヤー ---------- */
.layer-props { padding: 6px 10px 2px; display: flex; flex-direction: column; gap: 4px; }
.layer-list { display: flex; flex-direction: column; padding-bottom: 8px; }
.layer-row {
  display: flex; align-items: center; gap: 4px; min-height: 48px; padding: 2px 6px 2px 2px;
  border-bottom: 1px solid #262626; background: var(--bg2);
}
.layer-row.active { background: #34506e; }
.layer-row.hidden-layer .layer-thumb, .layer-row.hidden-layer .layer-name { opacity: .45; }
.layer-row .icon-btn { min-width: 28px; height: 30px; padding: 0 2px; }
.layer-row .lock { opacity: .4; }
.layer-row .lock.on { opacity: 1; color: #f0c419; background: none; }
.layer-thumb { width: 52px; height: 40px; background: #888; border: 1px solid #222; flex: none; }
.layer-name { flex: 1; min-width: 0; }
.layer-name .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-name .meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 6px; align-items: center; }
.badge { background: #2d5aa0; color: #fff; border-radius: 3px; padding: 0 5px; font-size: 10px; }
.layer-row.fixed { min-height: 38px; background: #2a2a2a; }
.layer-row.fixed .fixed-ic { width: 52px; display: flex; justify-content: center; color: var(--text-dim); }

/* ---------- ページ管理 ---------- */
.pages {
  flex: none; height: calc(128px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; flex-direction: column; background: var(--bg2); border-top: 1px solid var(--line);
}
.pages-head { display: flex; align-items: center; gap: 2px; padding: 0 6px; background: var(--bg3); border-bottom: 1px solid var(--line); }
.pages-head .pal-title { border: none; background: none; padding-left: 2px; margin-right: 8px; }
.pages-head .icon-btn { height: 28px; }
.page-list { flex: 1; display: flex; gap: 10px; padding: 6px 10px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.page-item { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: none; padding: 0; }
.page-frame { height: 70px; min-width: 40px; display: flex; align-items: center; justify-content: center; border: 2px solid transparent; border-radius: 2px; }
.page-item.active .page-frame { border-color: var(--accent); }
.page-img { height: 66px; background: #fff; display: block; }
.page-img:not([src]) { width: 47px; }
.page-no { font-size: 11px; color: var(--text-dim); }
.page-item.active .page-no { color: #fff; }

/* ---------- ダイアログ ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { width: 380px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; background: var(--bg3); border: 1px solid #111; border-radius: 6px; box-shadow: 0 16px 48px rgba(0,0,0,.6); }
.dialog.wide { width: 560px; }
.dialog-title { padding: 10px 14px; font-weight: 700; border-bottom: 1px solid var(--line); }
.dialog-body { padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dialog-body p { margin: 0 0 8px; line-height: 1.6; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.field > span { font-size: 12px; color: #c4c4c4; }
.field-row { display: flex; gap: 10px; }
.help-table { width: 100%; border-collapse: collapse; }
.help-table th { text-align: left; white-space: nowrap; padding: 5px 14px 5px 0; color: #fff; font-weight: 600; vertical-align: top; }
.help-table td { padding: 5px 0; color: #ccc; }
.help-table tr + tr { border-top: 1px solid #444; }

#toast {
  position: fixed; left: 50%; bottom: 150px; z-index: 200; transform: translate(-50%, 20px);
  background: rgba(20,20,20,.92); color: #fff; padding: 8px 16px; border-radius: 18px; font-size: 13px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 変形・テキスト編集などのフローティングバー */
.float-bar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; padding: 6px 8px;
  background: rgba(40,40,40,.95); border: 1px solid #111; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

/* Google ドライブの作品一覧 */
.drive-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.drive-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid #444; }
.drive-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.drive-name .hint { margin: 2px 0 0; }
#status.clickable { cursor: pointer; color: #fff; background: #8a5a12; }
