html, body { margin: 0; padding: 0; background: #f4f4f2; }
body.kkt-locked { overflow: hidden; }
:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --line: #dedcd6;
  --ink: #232320;
  --ink-dim: #6f6d67;
  --accent: #c1601a;
  --accent-ink: #ffffff;
  --danger: #b3413c;
  --radius: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
#kkt-app {
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--ink);
  background: var(--bg);
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
#kkt-app *, .kkt-layer * { box-sizing: border-box; }
#kkt-app .mono { font-variant-numeric: tabular-nums; }
#kkt-app button { font-family: inherit; }
#kkt-app button:disabled { opacity: .45; cursor: default; }

/* ---------- header ---------- */
.kkt-header { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 14px 16px 10px; padding-top: max(14px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.kkt-eyebrow { font-size: 11px; letter-spacing: .06em; color: var(--ink-dim); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kkt-title { font-size: 18px; font-weight: 700; line-height: 1.3; display: flex; align-items: center; gap: 8px; min-height: 30px; }
.kkt-title-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kkt-back { background: none; border: none; color: var(--ink-dim); font-size: 22px; cursor: pointer; padding: 2px 8px 2px 0; line-height: 1; flex-shrink: 0; }
.kkt-pencil { background: var(--surface); border: 1px solid var(--line); color: var(--ink-dim); width: 30px; height: 30px; border-radius: 6px; font-size: 13px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.kkt-head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.kkt-main { padding: 14px 16px calc(110px + var(--safe-b)); }

/* ---------- list ---------- */
.kkt-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.kkt-tab { flex: 1; text-align: center; padding: 9px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-dim); font-size: 13px; font-weight: 700; cursor: pointer; }
.kkt-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.kkt-search { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: var(--ink); padding: 10px 12px; font-size: 16px; font-family: inherit; margin-bottom: 12px; }
.kkt-search:focus { outline: none; border-color: var(--accent); }
.kkt-proj-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px; cursor: pointer; width: 100%; text-align: left; color: inherit; font: inherit; }
.kkt-proj-card:active { background: var(--surface-2); }
.kkt-proj-num { font-size: 12px; color: var(--ink-dim); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; flex-shrink: 0; }
.kkt-proj-info { flex: 1; min-width: 0; }
.kkt-proj-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kkt-proj-part { font-size: 12px; color: var(--accent); margin-top: 1px; }
.kkt-proj-meta { font-size: 12px; color: var(--ink-dim); margin-top: 3px; }
.kkt-empty { text-align: center; color: var(--ink-dim); padding: 60px 20px; font-size: 14px; line-height: 1.8; }
.kkt-empty-mark { font-size: 28px; color: var(--line); margin-bottom: 10px; }
.kkt-error { background: #fbeeed; border: 1px solid rgba(179,65,60,.35); color: var(--danger); border-radius: var(--radius); padding: 16px; font-size: 13.5px; line-height: 1.7; text-align: center; }
.kkt-error .kkt-btn { margin-top: 10px; }
.kkt-footer-links { text-align: center; margin-top: 18px; font-size: 12px; color: var(--ink-dim); }
.kkt-fail-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; cursor: pointer; width: 100%; text-align: left; color: inherit; font: inherit; display: block; }
.kkt-fail-card:active { background: var(--surface-2); }
.kkt-fail-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.kkt-fail-proj { font-size: 11.5px; color: var(--ink-dim); }
.kkt-fail-step { font-weight: 700; font-size: 14.5px; }
.kkt-fail-note { font-size: 12.5px; color: var(--ink-dim); margin-top: 5px; line-height: 1.6; white-space: pre-wrap; }
.kkt-fail-date { font-size: 11px; color: var(--ink-dim); margin-top: 6px; }

/* ---------- buttons ---------- */
.kkt-btn { border: none; border-radius: 8px; font-weight: 700; cursor: pointer; font-family: inherit; font-size: 14px; padding: 12px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.kkt-btn-primary { background: var(--accent); color: var(--accent-ink); }
.kkt-btn-primary:active { background: #a45013; }
.kkt-btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.kkt-btn-ghost:active { background: var(--surface-2); }
.kkt-btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(179,65,60,.35); }
.kkt-btn-sm { padding: 7px 12px; font-size: 12.5px; }
.kkt-fab { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); width: min(448px, calc(100% - 32px)); z-index: 6; }
.kkt-fab .kkt-btn { width: 100%; padding: 15px; font-size: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.14); }
.kkt-linklike { color: var(--accent); background: none; border: none; font-size: 12.5px; cursor: pointer; text-decoration: underline; font-family: inherit; white-space: nowrap; padding: 4px 2px; }
.kkt-linklike.danger { color: var(--danger); }

/* ---------- detail ---------- */
.kkt-section-label { font-size: 12px; letter-spacing: .04em; color: var(--ink-dim); margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }
.kkt-section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.kkt-drawing-box { border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--surface); padding: 26px 18px; text-align: center; color: var(--ink-dim); font-size: 13px; cursor: pointer; width: 100%; font-family: inherit; }
.kkt-drawing-preview { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.kkt-drawing-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: var(--surface-2); font-size: 12px; color: var(--ink-dim); border-bottom: 1px solid var(--line); gap: 8px; }
.kkt-drawing-bar .name { color: var(--ink); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.kkt-bar-right { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }
.kkt-imgwrap { position: relative; width: 100%; line-height: 0; background: #fff; overflow: hidden; }
.kkt-imgwrap img { width: 100%; height: 100%; display: block; object-fit: contain; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.kkt-imgwrap.zoomable { cursor: zoom-in; }
.kkt-imgwrap.pickable { cursor: crosshair; }
.kkt-img-error { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--ink-dim); line-height: 1.5; background: var(--surface); }
.kkt-zoom-hint { position: absolute; right: 8px; bottom: 8px; background: rgba(35,35,32,.72); color: #fff; font-size: 11px; line-height: 1; padding: 6px 8px; border-radius: 12px; pointer-events: none; }
.kkt-marker { position: absolute; display: flex; flex-direction: column; align-items: center; transform: translate(-50%, -100%) scale(var(--inv, 1)); transform-origin: 50% 100%; cursor: pointer; line-height: 1; }
.kkt-marker-bubble { min-width: 22px; height: 22px; padding: 0 3px; border-radius: 11px; background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.kkt-marker-bubble span { font-size: 10px; font-weight: 700; color: #fff; }
.kkt-marker-arrow { width: 0; height: 0; margin-top: -1px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 10px solid var(--accent); filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.kkt-marker.pending .kkt-marker-bubble { background: var(--ink); }
.kkt-marker.pending .kkt-marker-arrow { border-top-color: var(--ink); }
.kkt-marker.flash .kkt-marker-bubble { background: var(--ink); }
.kkt-marker.flash .kkt-marker-arrow { border-top-color: var(--ink); }
.kkt-page-tabs { display: flex; gap: 6px; padding: 8px 10px; background: var(--surface-2); border-top: 1px solid var(--line); flex-wrap: wrap; }
.kkt-page-tab { font-size: 12px; padding: 6px 11px; border-radius: 5px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-dim); cursor: pointer; }
.kkt-page-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700; }
.kkt-hint { font-size: 11.5px; color: var(--ink-dim); margin-top: 6px; line-height: 1.6; }

.kkt-step-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; transition: box-shadow .3s, border-color .3s; }
.kkt-step-card.flash { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(193,96,26,.18); }
.kkt-step-top { display: flex; align-items: flex-start; gap: 10px; }
.kkt-step-no { font-size: 15px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; width: 34px; height: 34px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.kkt-step-body { flex: 1; min-width: 0; }
.kkt-step-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; overflow-wrap: anywhere; }
.kkt-pin { font-size: 11px; color: var(--accent); font-weight: 400; background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline; }
.kkt-step-sub { font-size: 12.5px; color: var(--ink-dim); margin-top: 2px; overflow-wrap: anywhere; white-space: pre-wrap; }
.kkt-step-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.kkt-tag { font-size: 11px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-dim); padding: 3px 7px; border-radius: 5px; overflow-wrap: anywhere; }
.kkt-tag-fail { font-size: 11px; background: #f6e6e5; border: 1px solid rgba(179,65,60,.35); color: var(--danger); padding: 3px 7px; border-radius: 5px; font-weight: 700; }
.kkt-step-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.kkt-icon-btn { background: var(--surface); border: 1px solid var(--line); color: var(--ink-dim); width: 34px; height: 34px; border-radius: 6px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.kkt-icon-btn:active { background: var(--surface-2); }
.kkt-step-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.kkt-step-by { font-size: 11px; color: var(--ink-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kkt-step-footer-btns { display: flex; gap: 8px; flex-shrink: 0; }
.kkt-meta-line { font-size: 11px; color: var(--ink-dim); margin-top: 14px; line-height: 1.7; }

/* ---------- layers (sheets / viewer / busy) : body直下に置くので #kkt-app の外 ---------- */
.kkt-layer { font-family: "Zen Kaku Gothic New", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", sans-serif; color: #232320; -webkit-tap-highlight-color: transparent; }
.kkt-layer button { font-family: inherit; }
.kkt-sheet-backdrop { position: fixed; inset: 0; background: rgba(30,28,24,.42); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.kkt-sheet-backdrop.kkt-center { align-items: center; padding: 20px; }
.kkt-sheet { background: #f4f4f2; border-radius: 14px 14px 0 0; border: 1px solid #dedcd6; border-bottom: none; width: min(480px, 100%); max-height: 90vh; max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain; padding: 6px 16px calc(20px + env(safe-area-inset-bottom, 0px)); }
.kkt-center .kkt-sheet { border-radius: 12px; border-bottom: 1px solid #dedcd6; padding-bottom: 20px; }
.kkt-sheet-handle { width: 36px; height: 4px; background: #dedcd6; border-radius: 2px; margin: 10px auto 6px; }
.kkt-sheet-title { font-size: 16px; font-weight: 700; margin: 8px 0 14px; }
.kkt-field { margin-bottom: 12px; }
.kkt-field > label { display: block; font-size: 12px; color: #6f6d67; margin-bottom: 5px; }
.kkt-field input[type=text], .kkt-field textarea { width: 100%; background: #fff; border: 1px solid #dedcd6; border-radius: 8px; color: #232320; padding: 11px 12px; font-size: 16px; font-family: inherit; }
.kkt-field input:focus, .kkt-field textarea:focus { outline: none; border-color: #c1601a; }
.kkt-field-row { display: flex; gap: 10px; }
.kkt-field-row .kkt-field { flex: 1; min-width: 0; }
.kkt-sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.kkt-sheet-actions .kkt-btn { flex: 1; }
.kkt-sheet-danger { margin-top: 18px; padding-top: 14px; border-top: 1px solid #dedcd6; text-align: center; }
.kkt-checkbox-row { display: flex; align-items: center; gap: 8px; padding: 2px 0 4px; }
.kkt-checkbox-row input { width: 18px; height: 18px; }
.kkt-checkbox-row label { font-size: 13.5px; margin: 0; }
.kkt-pos-box { border: 1px solid #dedcd6; border-radius: 8px; overflow: hidden; background: #fff; }
.kkt-pos-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; font-size: 11.5px; color: #6f6d67; background: #f0efeb; }
.kkt-pos-none { padding: 22px 14px; text-align: center; color: #6f6d67; font-size: 12.5px; background: #fff; border: 1px dashed #dedcd6; border-radius: 8px; }
.kkt-history-item { padding: 10px 0; border-bottom: 1px solid #dedcd6; font-size: 13.5px; }
.kkt-history-item .who { font-size: 11.5px; color: #6f6d67; margin-top: 2px; }

.kkt-marker.dim { opacity: .45; pointer-events: none; }

/* ---------- viewer ---------- */
.kkt-viewer { position: fixed; inset: 0; z-index: 40; background: #1b1b19; display: flex; flex-direction: column; }
.kkt-viewer-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); color: #fff; font-size: 13px; }
.kkt-viewer-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.kkt-viewer-close { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.92); border: none; color: #232320; font-size: 16px; cursor: pointer; flex-shrink: 0; }
.kkt-viewer-stage { position: relative; flex: 1; overflow: hidden; touch-action: none; background: #2a2a27; }
.kkt-viewer-content { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; will-change: transform; }
.kkt-viewer-content img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; pointer-events: none; }
.kkt-viewer-bottom { background: #f0efeb; padding-bottom: env(safe-area-inset-bottom, 0px); }
.kkt-viewer-hint { font-size: 12px; color: #6f6d67; padding: 8px 12px 0; }
.kkt-viewer-actions { display: flex; gap: 10px; padding: 8px 12px 10px; }
.kkt-viewer-actions .kkt-btn { flex: 1; }
.kkt-viewer .kkt-page-tabs { border-top: none; }

/* ---------- busy / toast / banner ---------- */
.kkt-busy { position: fixed; inset: 0; z-index: 60; background: rgba(30,28,24,.5); display: flex; align-items: center; justify-content: center; padding: 24px; }
.kkt-busy-box { background: #fff; border-radius: 12px; padding: 20px 22px; font-size: 14px; display: flex; align-items: center; gap: 12px; max-width: 320px; line-height: 1.5; }
.kkt-spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #dedcd6; border-top-color: #c1601a; animation: kkt-spin .8s linear infinite; flex-shrink: 0; }
@keyframes kkt-spin { to { transform: rotate(360deg); } }
.kkt-toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #232320; color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 13px; z-index: 70; opacity: 0; transition: opacity .25s ease; pointer-events: none; max-width: 90%; text-align: center; line-height: 1.5; }
.kkt-toast.show { opacity: 1; }
.kkt-banner { position: fixed; inset: 0; z-index: 80; background: rgba(244,244,242,.97); display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.kkt-banner-box { max-width: 340px; font-size: 14px; line-height: 1.7; }
.kkt-banner-box .kkt-btn { margin-top: 14px; }

@media (prefers-reduced-motion: reduce) {
  .kkt-spinner { animation-duration: 2s; }
  .kkt-step-card, .kkt-toast { transition: none; }
}

.kkt-layer button:disabled { opacity: .45; cursor: default; }

/* ---------- login ---------- */
.kkt-login-box { width: min(360px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 22px 20px; text-align: left; }
.kkt-login-title { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.kkt-login-msg { font-size: 13.5px; line-height: 1.6; color: var(--ink-dim); margin: 0 0 16px; }
.kkt-login-error { font-size: 12.5px; color: var(--danger); min-height: 1.4em; margin: 0 0 8px; }
.kkt-login-box .kkt-btn { width: 100%; }
.kkt-field input[type=password] { width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); padding: 11px 12px; font-size: 16px; font-family: inherit; }
.kkt-field input[type=password]:focus { outline: none; border-color: var(--accent); }
