:root {
  --brand: #E87722;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --line: #e6e6e3;
  --line-2: #d9d9d5;
  --ink: #1f1f1d;
  --ink-2: #6b6b66;
  --accent: #2563eb;
  --sel: #E87722;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; overflow: hidden; }

.brandmark { font-weight: 800; letter-spacing: -.4px; }
.brand-dot { color: #E87722; font-weight: 800; }

/* ===== Auth gate ===== */
#gate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
#gate .gate-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 36px; width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
#gate h1.brandmark { font-size: 28px; letter-spacing: -.5px; margin: 0 0 6px; }
#gate p { color: var(--ink-2); font-size: 13px; margin: 0 0 22px; line-height: 1.6; }
#gate input {
  width: 100%; border: 1px solid var(--line-2); border-radius: 7px;
  padding: 11px 12px; margin-bottom: 10px; font-size: 14px;
  background: #fbfbfa; font-family: var(--font);
}
#gate input:focus { outline: none; border-color: var(--brand); background: #fff; }
#gate button {
  width: 100%; background: var(--brand); color: #fff; border: 0;
  border-radius: 7px; padding: 11px; font-size: 14px; cursor: pointer;
  font-weight: 600; font-family: var(--font);
}
#gate button:hover { background: #d76a17; }
#gate button.gate-secondary {
  background: #fff; color: var(--brand); border: 1px solid var(--brand);
  margin-top: 8px; font-weight: 500;
}
#gate button.gate-secondary:hover { background: #faf3ec; }
#gate .gate-err { color: #eb5757; font-size: 12px; margin-top: 10px; min-height: 16px; line-height: 1.5; }
#gate .gate-note { color: var(--ink-2); font-size: 11px; margin-top: 18px; line-height: 1.6; }

/* App is hidden until authenticated (auth.js adds .shown) */
#app { display: none; flex: 1 1 auto; flex-direction: column; min-height: 0; }
#app.shown { display: flex; }

/* Header user email */
.tb-user {
  font-size: 12px; color: var(--ink-2); max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 50;
}
.toolbar-brand { display: flex; align-items: baseline; gap: 8px; }
.toolbar-brand .brandmark { font-size: 18px; }
.toolbar-sub { font-size: 12px; color: var(--ink-2); }
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-right { margin-left: auto; }
.tb-divider { width: 1px; height: 22px; background: var(--line-2); margin: 0 4px; }

.tb-btn {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.tb-btn:hover { background: #f3f3f1; }
.tb-btn:active { background: #ebebe8; }
.tb-btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.tb-btn-primary:hover { background: #d76a17; }

.tb-dropdown { position: relative; }
.tb-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  padding: 4px;
  display: none;
  min-width: 120px;
  z-index: 60;
}
.tb-menu.open { display: block; }
.tb-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}
.tb-menu button:hover { background: #f3f3f1; }

/* ===== Layout ===== */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.pane { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.pane-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--ink-2);
  text-transform: uppercase;
  padding: 12px 14px 8px;
  flex: 0 0 auto;
}
.pane-left { width: 200px; border-right: 1px solid var(--line); }
.pane-right { width: 280px; border-left: 1px solid var(--line); }
.pane-center { flex: 1 1 auto; background: var(--bg); align-items: center; justify-content: center; }

/* ===== Slide list ===== */
.slide-list { flex: 1 1 auto; overflow-y: auto; padding: 6px 10px 14px; }
.slide-thumb {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 10px;
  cursor: pointer;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.slide-thumb.active { border-color: var(--sel); box-shadow: 0 0 0 2px rgba(232,119,34,.18); }
.slide-thumb-inner {
  position: absolute;
  top: 0; left: 0;
  width: 1280px; height: 720px;
  transform-origin: top left;
  pointer-events: none;
}
.slide-thumb-num {
  position: absolute;
  top: 4px; left: 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-2);
  background: rgba(255,255,255,.85);
  border-radius: 4px;
  padding: 1px 5px;
  z-index: 2;
}
.slide-thumb-actions {
  position: absolute;
  top: 3px; right: 4px;
  display: none;
  gap: 3px;
  z-index: 3;
}
.slide-thumb:hover .slide-thumb-actions { display: flex; }
.slide-thumb-actions button {
  font-size: 10px;
  border: 1px solid var(--line-2);
  background: rgba(255,255,255,.95);
  border-radius: 4px;
  padding: 2px 5px;
  cursor: pointer;
  line-height: 1;
}
.slide-thumb-actions button:hover { background: #f3f3f1; }
.slide-thumb.dragging { opacity: .5; }
.slide-thumb.drop-target { border-color: var(--accent); }

/* ===== Canvas ===== */
.canvas-wrap {
  position: relative;
  box-shadow: 0 6px 30px rgba(0,0,0,.12);
}
.canvas {
  position: relative;
  width: 1280px;
  height: 720px;
  background: #fff;
  transform-origin: top left;
  overflow: hidden;
}

/* Elements */
.el {
  position: absolute;
  box-sizing: border-box;
  cursor: move;
  user-select: none;
}
.el.selected { outline: 2px solid var(--sel); outline-offset: 0; }
.el-text {
  display: flex;
  overflow: hidden;
  word-break: break-word;
  white-space: pre-wrap;
}
.el-text .el-text-inner { width: 100%; outline: none; }
/* Arks official content highlight box (mirrors reference .title .hl) */
.el-text .el-text-inner .hl {
  display: inline-block;
  background: #03006A;
  color: #fff;
  padding: 2px 14px;
  border-radius: 4px;
  font-weight: 700;
}
.el-text[contenteditable="true"], .el-text .el-text-inner[contenteditable="true"] {
  cursor: text;
  user-select: text;
}
.el-image { background-size: cover; background-position: center; background-repeat: no-repeat; }
.el-image img { width: 100%; height: 100%; display: block; }
.el-shape svg { width: 100%; height: 100%; display: block; overflow: visible; pointer-events: none; }
.el-image img { pointer-events: none; }

/* Resize handles */
.handle {
  position: absolute;
  width: 11px; height: 11px;
  background: #fff;
  border: 2px solid var(--sel);
  border-radius: 50%;
  z-index: 30;
  pointer-events: none;
  display: none;
}
.el.selected .handle { pointer-events: auto; display: block; }
.h-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.h-n  { top: -6px; left: 50%; margin-left: -5.5px; cursor: ns-resize; }
.h-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.h-e  { top: 50%; right: -6px; margin-top: -5.5px; cursor: ew-resize; }
.h-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.h-s  { bottom: -6px; left: 50%; margin-left: -5.5px; cursor: ns-resize; }
.h-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.h-w  { top: 50%; left: -6px; margin-top: -5.5px; cursor: ew-resize; }

/* Snap guides */
.snap-guide {
  position: absolute;
  background: var(--brand);
  z-index: 40;
  pointer-events: none;
}
.snap-guide.v { width: 1px; top: 0; bottom: 0; }
.snap-guide.h { height: 1px; left: 0; right: 0; }

/* ===== Property panel ===== */
.props { flex: 1 1 auto; overflow-y: auto; padding: 4px 14px 24px; }
.props-empty { color: var(--ink-2); font-size: 13px; padding: 20px 4px; text-align: center; }
.prop-group { border-top: 1px solid var(--line); padding: 12px 0; }
.prop-group:first-child { border-top: none; }
.prop-group-title { font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 8px; }
.prop-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop-row label { font-size: 12px; color: var(--ink-2); width: 64px; flex: 0 0 auto; }
.prop-row .field { flex: 1 1 auto; display: flex; gap: 6px; align-items: center; }
.props input[type="text"], .props input[type="number"], .props select, .props textarea {
  font-family: var(--font);
  font-size: 13px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
  background: #fff;
  color: var(--ink);
}
.props textarea { resize: vertical; min-height: 60px; }
.props input[type="color"] {
  width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line-2);
  border-radius: 6px; background: #fff; cursor: pointer; flex: 0 0 auto;
}
.props input[type="range"] { width: 100%; }
.seg { display: flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button {
  flex: 1; border: none; background: #fff; padding: 6px 4px; font-size: 12px;
  cursor: pointer; color: var(--ink); font-family: var(--font);
}
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.active { background: var(--brand); color: #fff; }

.prop-btn {
  font-family: var(--font); font-size: 12px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-2); border-radius: 6px;
  padding: 7px 10px; cursor: pointer; flex: 1;
}
.prop-btn:hover { background: #f3f3f1; }
.prop-btn.danger { color: #b42318; border-color: #f0c4bf; }
.prop-btn.danger:hover { background: #fdf2f1; }
.prop-btns { display: flex; gap: 6px; }

.ai-box { background: #faf7f3; border: 1px dashed var(--line-2); border-radius: 8px; padding: 10px; }
.ai-box .ai-title { font-size: 12px; font-weight: 700; color: var(--brand); margin-bottom: 6px; }
.ai-box textarea { min-height: 56px; }
.ai-box .prop-btn { width: 100%; margin-top: 6px; }
.ai-box .badge { font-size: 10px; background: var(--brand); color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: 4px; }
.ai-box .prop-btn:disabled { opacity: .55; cursor: not-allowed; }

.ai-status { margin-top: 8px; font-size: 12px; border-radius: 6px; padding: 7px 9px; line-height: 1.4; }
.ai-status-load { background: #f1f1ef; color: var(--ink-2); }
.ai-status-ok { background: #ecf7ee; color: #1a7f37; }
.ai-status-err { background: #fdf2f1; color: #b42318; }

/* Wider menu for layout names */
#layoutMenu { min-width: 200px; }

/* ===== AI deck button (toolbar) ===== */
.tb-btn-ai {
  background: linear-gradient(135deg, #E87722, #f0903f);
  border-color: #E87722;
  color: #fff;
  font-weight: 700;
}
.tb-btn-ai:hover { background: linear-gradient(135deg, #d76a17, #e07f2e); }
.tb-btn-ai:disabled { opacity: .6; cursor: not-allowed; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(20, 20, 18, .42);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 14px; width: 560px; max-width: 100%;
  max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
  animation: modal-in .16s ease-out;
}
@keyframes modal-in { from { transform: translateY(8px) scale(.99); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; color: var(--ink); }
.modal-close {
  border: none; background: none; font-size: 24px; line-height: 1;
  color: var(--ink-2); cursor: pointer; padding: 0 4px; border-radius: 6px;
}
.modal-close:hover { background: #f1f1ef; color: var(--ink); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--line); background: #fafafa;
}
.modal-label {
  display: block; font-size: 12px; font-weight: 700; color: var(--ink-2);
  margin: 16px 0 7px; letter-spacing: .02em;
}
.modal-label:first-child { margin-top: 0; }
.deck-instruction {
  width: 100%; border: 1px solid var(--line-2); border-radius: 9px;
  padding: 12px 13px; font-size: 14px; line-height: 1.6; font-family: var(--font);
  background: #fbfbfa; color: var(--ink); resize: vertical;
}
.deck-instruction:focus { outline: none; border-color: var(--brand); background: #fff; }

.deck-templates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.deck-tpl {
  text-align: left; border: 1.5px solid var(--line-2); background: #fff;
  border-radius: 9px; padding: 10px 12px; cursor: pointer; font-family: var(--font);
  display: flex; flex-direction: column; gap: 3px; transition: border-color .12s, background .12s;
}
.deck-tpl:hover { background: #f8f8f6; }
.deck-tpl.active { border-color: var(--brand); background: #fdf3ec; box-shadow: 0 0 0 1px var(--brand) inset; }
.deck-tpl-name { font-size: 13px; font-weight: 700; color: var(--ink); }
.deck-tpl-desc { font-size: 11px; color: var(--ink-2); line-height: 1.45; }

.deck-select {
  width: 100%; border: 1px solid var(--line-2); border-radius: 7px;
  padding: 9px 10px; font-size: 14px; font-family: var(--font);
  background: #fff; color: var(--ink); cursor: pointer;
}
.deck-select:focus { outline: none; border-color: var(--brand); }
.deck-model-note { font-size: 11px; color: var(--ink-2); margin-top: 6px; line-height: 1.5; }

.deck-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.deck-row input[type="number"] {
  width: 80px; border: 1px solid var(--line-2); border-radius: 7px;
  padding: 8px 10px; font-size: 14px; font-family: var(--font);
}

.deck-status { margin-top: 16px; font-size: 13px; border-radius: 8px; padding: 10px 12px; line-height: 1.5; }
.deck-status[hidden] { display: none; }
.deck-status-load { background: #f3f1ef; color: var(--ink-2); }
.deck-status-ok { background: #ecf7ee; color: #1a7f37; }
.deck-status-err { background: #fdf2f1; color: #b42318; }

/* Spinner */
.spinner {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Print root hidden in screen mode */
.print-root { display: none; }

/* ===== 埋め込み(iframe in keiei-app)時: 親アプリと重複するchromeを隠す ===== */
html.embedded .toolbar-brand,
html.embedded .tb-user,
html.embedded [data-action="logout"],
html.embedded .tb-divider-brand { display: none !important; }
html.embedded .toolbar { padding-left: 14px; }
