/* ===== 配色(テーマ) ===== */
:root {
  --accent: #1e9bff; --accent-ink: #fff; --accent-soft: #e3f3ff;
  --bg: #f3f9ff; --stage: #dfeaf6; --line: #cfe1f3; --ink: #1f2d3d; --sub: #5d7186;
  --title-a: #1e9bff; --title-b: #7c5cff;
}
/* ツールごとの色 */
.tools button[data-tool="line"]   { --tc: #3b82f6; }
.tools button[data-tool="rect"]   { --tc: #f59e0b; }
.tools button[data-tool="pen"]    { --tc: #8b5cf6; }
.tools button[data-tool="brush"]  { --tc: #ec4899; }
.tools button[data-tool="eraser"] { --tc: #14b8a6; }
.tools button[data-tool="pan"]    { --tc: #64748b; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  font-family: "Yu Gothic UI", "Meiryo", sans-serif; font-size: 14px; color: var(--ink); background: var(--bg);
  accent-color: var(--accent);
}
[hidden] { display: none !important; }

/* ===== 上バー ===== */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 14px; background: #fff; border-bottom: 2px solid var(--line);
  box-shadow: 0 2px 8px rgba(30, 60, 100, .06);
}
.topbar h1 {
  display: flex; align-items: center; gap: 8px; margin: 0 10px 0 0; font-size: 18px; letter-spacing: .02em;
  background: linear-gradient(90deg, var(--title-a), var(--title-b)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar h1 svg { width: 28px; height: 28px; flex: none; }
.group { display: flex; align-items: center; gap: 6px; }
.group.right { margin-left: auto; }

button, select, input[type=number] {
  font: inherit; padding: 6px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; color: inherit;
}
select { padding-right: 8px; }
button { cursor: pointer; transition: background .12s, transform .12s, box-shadow .12s; }
button:hover:not(:disabled) { background: var(--accent-soft); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(30, 60, 100, .12); }
button:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: bold; }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #000); }

.layout { flex: 1; display: flex; min-height: 0; }

/* ===== 左: ツール ===== */
.tools { width: 82px; padding: 10px 8px; display: flex; flex-direction: column; gap: 8px; background: #fff; border-right: 2px solid var(--line); overflow: auto; }
.tools button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 2px 7px; font-size: 12px; line-height: 1.2; border-radius: 16px; border: 2px solid transparent;
  background: color-mix(in srgb, var(--tc) 12%, #fff); color: var(--ink);
}
.tools button svg { width: 28px; height: 28px; fill: none; stroke: var(--tc); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tools button svg .dot { fill: var(--tc); stroke: none; }
.tools button svg .thick { stroke-width: 4.2; }
.tools button:hover:not(:disabled) { background: color-mix(in srgb, var(--tc) 22%, #fff); }
.tools button.active { background: var(--tc); border-color: var(--tc); color: #fff; font-weight: bold; box-shadow: 0 4px 10px color-mix(in srgb, var(--tc) 45%, transparent); }
.tools button.active svg { stroke: #fff; }
.tools button.active svg .dot { fill: #fff; }

/* ===== 中央: 作業エリア ===== */
.stage { flex: 1; overflow: auto; position: relative; padding: 18px; background: var(--stage); }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.empty p {
  margin: 0; padding: 32px 40px; text-align: center; line-height: 1.9; color: var(--sub); font-size: 15px;
  border: 3px dashed var(--accent); border-radius: 24px; background: rgba(255, 255, 255, .65);
}
.stage.drag { outline: 4px dashed var(--accent); outline-offset: -10px; background: var(--accent-soft); }
.canvas-wrap {
  position: relative; display: inline-block; line-height: 0; border-radius: 4px; box-shadow: 0 4px 16px rgba(30, 60, 100, .25);
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%),
    linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
#canvas, #overlay { display: block; }
#overlay { position: absolute; left: 0; top: 0; cursor: crosshair; touch-action: none; }

/* ===== 右: 設定パネル(縦タブ) ===== */
.panel { width: 340px; display: flex; background: #fff; border-left: 2px solid var(--line); min-height: 0; }
.tabbody { flex: 1; min-width: 0; padding: 14px; overflow: auto; }
.tabs { width: 38px; display: flex; flex-direction: column; gap: 6px; padding: 8px 0 8px 4px; background: var(--bg); border-left: 2px solid var(--line); }
.tabs button {
  flex: none; writing-mode: vertical-rl; padding: 14px 6px; min-height: 8.5em;
  border: 0; border-radius: 12px 0 0 12px; background: transparent; box-shadow: none;
  font-size: 13px; letter-spacing: 0; white-space: nowrap; color: var(--sub);
}
.tabs button:hover:not(:disabled) { background: var(--accent-soft); transform: none; box-shadow: none; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); font-weight: bold; }

.panel label { display: flex; align-items: center; gap: 6px; margin: 12px 0; }
.panel label.rng { display: grid; grid-template-columns: 6.8em 1fr 4em 1.4em; gap: 6px; }
.panel label.rng input[type=range] { min-width: 0; width: 100%; }
.panel label.rng .unit { font-size: 12px; color: var(--sub); }
.panel input.num { width: 100%; padding: 3px 6px; text-align: right; border-radius: 10px; }
.panel input[type=color] { width: 56px; height: 34px; padding: 2px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.panel label.check { margin: 8px 0; }
.panel label.check input { margin: 0; width: 17px; height: 17px; }
.btnrow { display: flex; gap: 8px; margin: 12px 0; }
.btnrow button { flex: 1; }
.btnrow button.active, .btnrow #btnToneApply:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: bold; }
.resize input[type=number] { width: 90px; border-radius: 10px; }
.resize > button { width: 100%; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: bold; }
.resize > button:disabled { background: #fff; color: inherit; font-weight: normal; border-color: var(--line); }
.hint { font-size: 12px; color: var(--sub); margin: 8px 0; padding: 8px 10px; background: var(--bg); border-radius: 12px; line-height: 1.6; }

/* ===== 下バー ===== */
.status { display: flex; gap: 20px; padding: 5px 14px; background: #fff; border-top: 2px solid var(--line); font-size: 12px; color: var(--sub); }
.status .msg { margin-left: auto; color: #e0670a; font-weight: bold; }
/* メッセージ(画面の中央上に数秒だけ出す。操作の邪魔をしないよう、クリックは下に通す) */
.toast { position: fixed; top: 64px; left: 50%; z-index: 50; max-width: min(640px, calc(100vw - 32px)); padding: 10px 18px; border-radius: 12px; font-size: 14px; font-weight: bold; line-height: 1.5; text-align: center; pointer-events: none; opacity: 0; transform: translate(-50%, -8px); transition: opacity .2s, transform .2s; box-shadow: 0 6px 18px rgba(30, 60, 100, .22); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.info { background: #0369a1; color: #fff; }
.toast.warn { background: #c2410c; color: #fff; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

#brushCursor { position: fixed; display: none; pointer-events: none; z-index: 10; transform: translate(-50%, -50%); border-radius: 50%; border: 1px solid #fff; box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #000; }

/* ===== スマホ幅 ===== */
@media (max-width: 800px) {
  body { min-height: 100vh; height: auto; }
  .topbar { gap: 8px; padding: 6px 8px; }
  .group.right { margin-left: 0; }
  .layout { flex-direction: column; min-height: 0; }
  .tools { width: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 2px solid var(--line); }
  .tools button { flex: 1 1 56px; }
  .stage { min-height: 50vh; flex: none; padding: 8px; }
  .panel { width: auto; flex-direction: column; border-left: 0; border-top: 2px solid var(--line); }
  .tabs { order: -1; width: auto; flex-direction: row; gap: 4px; padding: 6px 6px 0; border-left: 0; border-bottom: 2px solid var(--line); }
  .tabs button { flex: 1; writing-mode: horizontal-tb; min-height: 40px; padding: 10px 4px; border-radius: 12px 12px 0 0; }
  .tabbody { overflow: visible; }
  .status { flex-wrap: wrap; gap: 8px 16px; }
  .status .msg { margin-left: 0; }
  button, select, input[type=number] { min-height: 40px; }
}

.logo-bg { fill: var(--accent); }

/* ===== 選択状態はホバーより優先する ===== */
.tools button.active:hover:not(:disabled) { background: var(--tc); color: #fff; }
.tabs button[aria-selected="true"]:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.resize > button:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #000); color: var(--accent-ink); }
.btnrow button.active:hover:not(:disabled), .btnrow #btnToneApply:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #000); color: var(--accent-ink); }

/* ===== スライダー(明るい線 + 丸いつまみ) ===== */
input[type=range] { -webkit-appearance: none; appearance: none; height: 8px; padding: 0; border: 0; border-radius: 999px; background: var(--line); }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: var(--line); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 999px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; margin-top: -6px; border-radius: 50%; border: 3px solid #fff; background: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #fff; background: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }

/* ===== ログイン画面 ===== */
.gate { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--stage); }
.gate[hidden] { display: none !important; }
.gate-card { width: 100%; max-width: 380px; padding: 32px 28px; text-align: center; background: #fff; border-radius: 28px; box-shadow: 0 8px 28px rgba(30, 60, 100, .2); }
.gate-card svg { width: 56px; height: 56px; }
.gate-card h2 { margin: 8px 0 12px; font-size: 22px; background: linear-gradient(90deg, var(--title-a), var(--title-b)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate-card p { margin: 10px 0; line-height: 1.7; }
.gate-card button { width: 100%; padding: 10px 14px; margin: 8px 0; font-size: 15px; }

/* ===== 色のプリセット(PDFEditor と同じ配置) ===== */
.colorField { display: grid; gap: 8px; margin: 12px 0; }
.colorField > label { margin: 0; }
.colorPresetGrid { display: grid; grid-template-columns: repeat(6, minmax(26px, 1fr)); gap: 6px; }
.colorPresetButton {
  min-width: 0; height: 28px; padding: 0; background: var(--preset-color);
  border: 1.5px solid #b8c6d6; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55);
}
.colorPresetButton:hover:not(:disabled) { background: var(--preset-color); transform: translateY(-1px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55), 0 3px 6px rgba(30, 60, 100, .25); }
.colorPresetButton[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }

/* ===== 切り抜き ===== */
.tools button[data-tool="crop"] { --tc: #65a30d; }
.cropGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.cropGrid label { margin: 6px 0; white-space: nowrap; }
.cropGrid .unit { font-size: 12px; color: var(--sub); }
.cropGrid input[type=number] { width: 100%; min-width: 0; padding: 4px 6px; text-align: right; border-radius: 10px; }
button.wide { width: 100%; padding: 9px 14px; font-weight: bold; }
button.wide:disabled { background: #fff; color: inherit; border-color: var(--line); font-weight: normal; }

/* ===== 回転・反転 ===== */
.subhead { margin: 18px 0 8px; padding-top: 14px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--ink); }
.btnrow.tri button { padding-left: 6px; padding-right: 6px; white-space: nowrap; }
.resize input#rotAngle { width: 90px; }
.resize > button.primary.wide { margin-top: 4px; }

/* ===== 選択ツール(描いたものの一覧) ===== */
.tools button[data-tool="select"] { --tc: #0ea5e9; }
.objList { display: grid; gap: 4px; max-height: 190px; overflow: auto; margin: 6px 0 10px; padding: 2px; }
.objItem { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 5px 10px; border-radius: 10px; font-size: 12px; }
.objItem .sw { width: 14px; height: 14px; border-radius: 50%; background: var(--sw, #888); border: 1px solid rgba(0, 0, 0, .25); flex: none; }
.objItem .sw.erase { background: repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 50% / 8px 8px; }
.objItem .sw.image { border-radius: 3px; background: linear-gradient(135deg, #7dd3fc 0 50%, #22c55e 50% 100%); }
.objItem.active, .objItem.active:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.objList .none { font-size: 12px; color: var(--sub); padding: 6px 8px; }
