/* KEB STAGE: one visual system across home, editor, viewer and dialogs. */
:root,
#app.workspace-editor,
#app.workspace-viewer {
  --ink: #20324a;
  --muted: #52647a;
  --accent: #2870cc;
  --accent-hover: #205eaf;
  --accent-strong: #1c4e8d;
  --accent-soft: #eaf3ff;
  --teal: var(--accent);
  --paper: #ffffff;
  --background: #f7fafe;
  --line: #dce5f0;
  --control-line: #7c8fa7;
  --focus: #174d94;
  color-scheme: light;
  color: var(--ink);
  background: var(--background);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}
body { background: var(--background); line-height: 1.6; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button { min-height: 44px; font-weight: 600; border-color: var(--line); background: var(--paper); }
button:hover { background: #f0f5fc; border-color: #afc1d9; }
button:active:not(:disabled) { background: #e2edfb; }
button.primary,
dialog .command-list button.primary,
.workspace-editor .touch-dock #touch-add {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
button.primary:hover, dialog .command-list button.primary:hover,
.workspace-editor .touch-dock #touch-add:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:active:not(:disabled) { background: var(--accent-strong); }
button:disabled { cursor: not-allowed; }
a { color: var(--accent-strong); text-underline-offset: .2em; }
input, select, textarea { min-height: 44px; border-color: var(--control-line); background: var(--paper); font-size: 16px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[type="checkbox"], input[type="radio"] { min-height: 20px; accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); }
#app label, dialog label { color: var(--ink); font-size: 14px; }
.help, .help-text, .muted, small { color: var(--muted); }
.help, .help-text { font-size: 14px; line-height: 1.75; }
:is(button, input, select, textarea, a, summary):focus-visible {
  outline: 3px solid var(--focus); outline-offset: 3px; box-shadow: 0 0 0 2px white;
}
button.danger { color: #a33228; background: #fff8f6; border-color: #dab4ae; }
.error { color: #b12e23; }
.skip-link {
  position: absolute; left: 16px; top: 8px; z-index: 200;
  transform: translateY(-180%); padding: 10px 18px; color: var(--accent-strong); background: #fff;
}
.skip-link:focus { transform: translateY(0); }
.canvas-skip { left: 12px; top: 12px; }
.canvas-skip:not(:focus) { clip-path: inset(100%); }
#main-content:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); }
#app .brand { color: var(--ink); gap: 12px; min-width: 0; text-decoration: none; }
#app .brand-mark { display: block; width: 40px; height: 40px; flex: 0 0 40px; background: none; border-radius: 11px; }
#app .brand-copy { min-width: 0; }
#app .brand b { display: block; font-size: 21px; line-height: 1.2; letter-spacing: .025em; font-weight: 750; color: var(--accent); }
#app .brand b span { color: var(--ink); }
#app .brand small { display: block; margin-top: 5px; font-size: 12px; line-height: 1.5; letter-spacing: 0; color: var(--muted); font-weight: 400; }
#app .brand small span { display: inline-block; white-space: nowrap; }
.top-title { margin: 0; font-weight: 600; line-height: 1.5; }
.tag { color: var(--accent-strong); background: var(--accent-soft); border-color: #c8dcf7; font-size: 12px; font-weight: 600; }

/* Public home: one primary action, with the working steps kept in view. */
.public-home .topbar { max-width: none; height: auto; min-height: 88px; padding: 16px max(28px,calc((100vw - 1120px)/2)); gap: 24px; }
.public-home .top-title { display: none; }
.public-home .topbar .tag { margin-left: auto; }
.public-home .topbar .spacer { display: none; }
.public-home .topbar .actions { display: flex; }
.public-home #home-help { color: var(--muted); }
.public-home .home { max-width: 1176px; padding: 56px 28px 36px; }
.public-home .welcome { display: grid; grid-template-columns: minmax(0,1.1fr) minmax(340px,.9fr); align-items: center; gap: 64px; margin-bottom: 38px; }
.public-home .eyebrow { margin: 0 0 16px; color: var(--accent-strong); font-size: 14px; font-weight: 600; letter-spacing: .08em; }
.public-home h1 { margin: 0 0 20px; font-size: clamp(34px,4.1vw,50px); font-weight: 700; line-height: 1.35; letter-spacing: -.035em; }
.public-home h1 em { color: var(--accent); font-style: normal; }
.public-home .home-lead { color: var(--muted); font-size: 16px; line-height: 1.85; }
.home-stage { margin: 22px 0 0; }
.home-stage svg { width: 100%; display: block; max-height: 270px; }
.home-stage figcaption { text-align: center; font-size: 12px; margin-top: 6px; color: var(--muted); }
.illustration-paper { fill: #fff; stroke: #dce5f0; stroke-width: 1.5; }
.illustration-risers { fill: #e7eef8; stroke: #8093ac; stroke-width: 1.2; }
.illustration-seats circle { fill: #eaf3ff; stroke: #2870cc; stroke-width: 1.7; }
.illustration-seats path { stroke: #687c96; stroke-width: 1.5; }
.illustration-podium { fill: #2870cc; }
.public-home .home-actions { display: flex; width: auto; flex-direction: column; gap: 0; padding: 30px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 40px #20324a07; }
.create-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.create-heading h2 { font-size: 21px; line-height: 1.5; letter-spacing: -.02em; }
.create-icon { display: inline-flex; color: var(--accent); }
.public-home .create-lead { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
#create-form { display: flex; flex-direction: column; }
.public-home .home-actions label { display: block; font-size: 16px; font-weight: 600; margin: 0; }
.optional { display: inline-block; font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.field-hint { color: var(--muted); font-size: 13px; line-height: 1.65; margin: 6px 0 10px; }
.public-home .home-actions input { min-height: 48px; margin: 0 0 16px; border-radius: 8px; }
.public-home #new-guided { min-height: 50px; padding: 12px; font-size: 15px; width: 100%; }
.public-home .sample-button { min-height: 48px; margin-top: 10px; color: var(--accent-strong); border-color: #aec3df; background: #fff; }
.public-home .sample-button:hover { background: var(--accent-soft); }
.public-home .create-footnote { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.8; }
.public-home .link-intro { background: var(--accent-soft); border: 0; border-radius: 10px; margin-top: 22px; padding: 16px; gap: 10px; font-size: 14px; line-height: 1.65; }
.link-intro > .ui-icon { color: var(--accent-strong); }
.public-home .link-intro p { color: var(--muted); margin-top: 8px; font-size: 12px; line-height: 1.75; }
.home-steps { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 22px; list-style: none; margin: 0; padding: 26px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.home-steps li { display: flex; gap: 13px; align-items: center; min-width: 0; }
.home-step-number { color: var(--accent); background: #eaf3ff; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 32px; font-size: 15px; font-weight: 700; }
.home-steps h2 { font-size: 15px; line-height: 1.5; margin-bottom: 4px; }
.home-steps p { font-size: 12px; color: var(--muted); }
.home-steps .ui-icon { margin-left: auto; color: #7188a7; width: 24px; height: 24px; flex: 0 0 24px; }
.public-home .recent-section { border: 0; padding-top: 0; margin-top: 38px; }
.recent-header { margin-bottom: 20px; }
.recent-header h2 { font-size: 20px; }
.public-home .recent-header .help { font-size: 14px; color: var(--muted); margin-top: 6px; }
.recent-empty { display: flex; align-items: center; gap: 18px; padding: 26px; border: 1px dashed #adc0d9; border-radius: 12px; background: #fff; }
.recent-empty > .ui-icon { width: 30px; height: 30px; flex: 0 0 30px; color: #637c9d; }
.recent-empty h3 { font-size: 15px; line-height: 1.6; }
.recent-empty p { color: var(--muted); font-size: 14px; margin-top: 5px; }
.public-home .project-grid { gap: 16px; }
.public-home .project-card { background: #fff; border-color: var(--line); border-radius: 12px; min-height: 0; }
.public-home .project-card > a { padding: 20px 20px 14px; }
.public-home .project-card > a:hover { background: #f4f8fe; }
.project-icon { display: flex; color: var(--accent); margin-bottom: 14px; }
.project-icon .ui-icon { width: 28px; height: 28px; }
.public-home .project-card .info { padding: 0; }
.public-home .project-card h3 { line-height: 1.6; font-size: 16px; overflow-wrap: anywhere; margin-bottom: 8px; }
.public-home .project-card .meta { color: var(--muted); font-size: 12px; gap: 8px; flex-wrap: wrap; }
.project-open { display: flex; align-items: center; gap: 6px; color: var(--accent-strong); font-size: 14px; font-weight: 600; margin-top: 20px; }
.project-open .ui-icon { transform: rotate(-90deg); width: 16px; height: 16px; }
.public-home .project-card .forget-link { margin: 0 10px 10px; color: var(--muted); min-height: 44px; font-size: 12px; font-weight: 400; }
.public-footer { padding-top: 24px; border-top: 1px solid var(--line); margin-top: 36px; color: var(--muted); font-size: 13px; }
.public-footer p:first-child { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.public-footer p + p { margin: 6px 0 14px; }
.public-footer a { text-decoration: underline; }

/* Editing: stable hierarchy, roomy controls and a quiet drawing surface. */
:is(.workspace-editor,.workspace-viewer) button { min-height: 44px; }
.workspace-editor .topbar .tag { color: var(--accent-strong); background: var(--accent-soft); border-color: #c8dcf7; }
:is(.workspace-editor,.workspace-viewer) button.active,
:is(.workspace-editor,.workspace-viewer) button[aria-pressed="true"],
dialog .command-list button[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); border-color: #729bcf; }
dialog .command-list button[aria-pressed="true"] { box-shadow: inset 3px 0 0 var(--accent); }
:is(.workspace-editor,.workspace-viewer) :is(input,select,textarea) { border-color: var(--control-line); font-size: 16px; }
.workspace-editor .save-state { color: #256541; }
.workspace-editor .toolbar { background: #fff; }
.workspace-editor .context-strip { background: #f6f9fd; }
.stage-area { background: #edf2f8; }
.canvas-wrap { background-image: radial-gradient(#bccadd .7px,transparent .7px); }
.stage-svg .object:focus-visible .hit { stroke: var(--focus); stroke-width: 3; }
.stage-svg [data-handle]:focus-visible circle { stroke: var(--focus); stroke-width: 4; }
.selection-box { stroke: #2870cc; stroke-width: 2.5; }
.canvas-label { color: var(--muted); background: #ffffffed; border-color: var(--line); font-size: 12px; }
.scale-ruler { color: var(--ink); background: #fffffff0; }
.scale-ruler i { border-color: var(--ink); }
.scale-ruler small { color: var(--muted); font-size: 11px; }
.workspace-editor .stage-footer { background: #fff; color: var(--muted); }
.workspace-editor .inspector-empty { color: var(--muted); }
.workspace-editor .inspector-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-strong); }
.workspace-editor .workflow-steps button.current { color: var(--accent-strong); }
.workspace-editor .workflow-steps button.current .step-number { background: var(--accent); color: #fff; }
.workspace-editor .workflow-steps button.complete .step-number { color: var(--accent-strong); background: #eaf3ff; border-color: #a9c6eb; }
.workspace-viewer .viewer-tools { background: #fff; }
.workspace-viewer .viewer-bottom { color: var(--muted); }
.viewer-bottom .read-only-label { color: var(--ink); }
.countcard { background: #f0f5fc; }
.countcard b { color: var(--accent-strong); }
.ui-icon { flex-shrink: 0; }

/* Dialogs share type, input and focus rules with the page. */
dialog { color: var(--ink); background: var(--paper); border-color: var(--line); padding: 28px; max-width: 660px; max-height: calc(100dvh - 32px); border-radius: 16px; box-shadow: 0 24px 80px #20324a30; }
dialog::backdrop { background: #14283f66; backdrop-filter: blur(2px); }
dialog .modal-head h2 { font-size: 20px; line-height: 1.5; }
dialog .modal-body { font-size: 15px; line-height: 1.75; }
dialog .modal-body :is(.help,.help-text,small) { font-size: 13px; color: var(--muted); }
dialog .modal-body label { font-size: 14px; color: var(--ink); }
dialog .menu-section-title { color: var(--muted); font-size: 13px; }
dialog .command-list small { color: var(--muted); font-size: 13px; }
dialog .command-list button { background: #fff; }
dialog .add-grid button { flex-direction: row; }
dialog .command-list button > .ui-icon, dialog .parts-list button > .ui-icon,
dialog .add-grid .ui-icon { color: var(--accent-strong); }
dialog .command-list button.primary > .ui-icon { color: white; }
dialog .guide-preferences input { accent-color: var(--accent); }
dialog .guide-preferences b { color: var(--ink); }
dialog details > summary { min-height: 44px; color: var(--ink); }
dialog .surface-legend { color: var(--muted); }
dialog .surface-legend strong { color: var(--accent-strong); }
dialog .help-guide .help-intro { margin-top: 0; }
.help-steps { padding-left: 24px; margin: 16px 0 24px; }
.help-steps li { padding-left: 6px; margin-bottom: 18px; }
.help-steps li::marker { color: var(--accent); font-weight: 700; }
dialog .help-steps p { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.help-guide details { border-top: 1px solid var(--line); padding: 5px 0; }
.help-guide details p { color: var(--muted); font-size: 14px; }
#toast { background: #20324a; color: #fff; font-size: 14px; line-height: 1.6; }
.loading, .read-error p { color: var(--muted); }

@media (max-width: 1200px) {
  :is(.workspace-editor,.workspace-viewer) .brand small { display: none!important; }
  .public-home .welcome { gap: 36px; grid-template-columns: minmax(0,1fr) minmax(330px,.95fr); }
  .home-steps .ui-icon { display: none; }
}
@media (max-width: 850px) {
  .public-home .home { padding: 36px 24px 28px; }
  .public-home .welcome { gap: 24px; grid-template-columns: minmax(0,1fr) minmax(310px,1fr); }
  .public-home .home-actions { padding: 24px; }
  .public-home h1 { font-size: 34px; }
  .home-steps { gap: 14px; }
  .home-steps li { gap: 8px; align-items: flex-start; }
  .home-steps h2 { font-size: 14px; }
  #app.workspace-editor .topbar .brand b, #app.workspace-viewer .topbar .brand b { font-size: 18px; }
  #app.workspace-editor .topbar .brand-mark, #app.workspace-viewer .topbar .brand-mark { width: 32px; height: 32px; flex-basis: 32px; border-radius: 8px; }
  .workspace-editor .touch-dock button { min-height: 58px; }
  .workspace-editor .side.right { border-top: 1px solid var(--line); box-shadow: 0 -12px 40px #20324a18; }
}
@media (max-width: 700px) {
  .public-home .topbar { display: grid; grid-template-columns: minmax(0,1fr) auto; padding: 16px 20px; gap: 12px; min-height: 80px; }
  .public-home .topbar .actions { display: flex; }
  .public-home .topbar .tag { display: none; }
  .public-home #home-help { padding: 10px; }
  .public-home #home-help span { display: none; }
  .public-home #home-help::after { content: none; }
  .public-home .brand small { white-space: normal; font-size: 12px; display: block; }
  .public-home .welcome { grid-template-columns: minmax(0,1fr); gap: 26px; }
  .public-home .home { padding: 30px 20px 24px; }
  .public-home .home-intro { padding: 0 4px; }
  .public-home .eyebrow { margin-bottom: 12px; font-size: 13px; }
  .public-home h1 { font-size: clamp(32px,8vw,40px); margin-bottom: 14px; }
  .public-home .home-lead { font-size: 15px; }
  .public-home .home-stage { display: none; }
  .public-home .home-actions { padding: 24px; border-radius: 14px; }
  .home-steps { grid-template-columns: minmax(0,1fr); gap: 20px; padding: 26px 4px; }
  .home-steps li { gap: 14px; align-items: center; }
  .home-steps h2 { font-size: 15px; }
  .home-steps p { font-size: 13px; }
  .home-steps .ui-icon { display: block; }
  .public-home .project-grid { grid-template-columns: 1fr; }
  .recent-empty { align-items: flex-start; padding: 20px; gap: 12px; }
  .recent-empty p { font-size: 13px; }
  .public-footer { font-size: 12px; }
}
@media (max-width: 600px) {
  .workspace-editor .topbar { display: grid; grid-template-columns: minmax(0,1fr) 44px 44px 78px; gap: 4px 6px; padding: 10px 12px 7px; }
  .workspace-editor .topbar .brand { grid-column: 1 / 3; grid-row: 1; gap: 8px!important; }
  #app.workspace-editor .topbar .brand b { font-size: 16px; letter-spacing: 0; }
  .workspace-editor .topbar .top-title { grid-column: 3 / -1; grid-row: 1; padding: 0; font-size: 13px; text-align: right; }
  .workspace-editor .topbar .save-state { grid-column: 1; grid-row: 2; font-size: 12px; }
  .workspace-editor .topbar #save { grid-column: 2; grid-row: 2; }
  .workspace-editor .topbar #preview { grid-column: 3; grid-row: 2; }
  .workspace-editor .topbar #document-menu { grid-column: 4; grid-row: 2; }
  .workspace-editor .topbar .tag, .workspace-editor .topbar .spacer { display: none; }
  .workspace-viewer .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 12px; }
  .workspace-viewer .topbar .brand { flex: 1; }
  .workspace-viewer .topbar .top-title { order: 3; flex-basis: 100%; font-size: 14px; }
  .workspace-viewer .topbar .spacer { display: none; }
  .workspace-editor .canvas-label { font-size: 11px; padding: 6px 10px; }
  dialog { padding: 22px 18px; width: calc(100vw - 24px); border-radius: 14px; }
  dialog .modal-head h2 { font-size: 18px; }
  dialog .modal-body { font-size: 14px; }
  .zoom-controls { right: 10px; bottom: 12px; }
}
@media (max-width: 360px) {
  .public-home .home, .public-home .topbar { padding-left: 16px; padding-right: 16px; }
  .public-home .home-actions { padding: 20px 16px; }
  .public-home #new-guided { font-size: 14px; padding-left: 8px; padding-right: 8px; }
  .workspace-editor .topbar { padding-left: 8px; padding-right: 8px; }
  #app.workspace-editor .topbar .brand b { font-size: 15px; }
  #app.workspace-editor .topbar .brand-mark { width: 28px; height: 28px; flex-basis: 28px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto!important; transition: none!important; animation: none!important; } }
