/* Wonder Scan — 暗い作業台の上に白い紙が載っていく、という見立て */
:root{
  --ink:#0D141C;
  --panel:#16202C;
  --line:#27333F;
  --navy:#1F4E79;
  --azure:#58A6E8;
  --text:#E6EDF5;
  --muted:#8FA0B2;
  --dock-h:84px;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0;height:100%}
body{
  font-family:"Meiryo UI","Meiryo","Hiragino Sans","Yu Gothic",sans-serif;
  background:var(--ink);
  color:var(--text);
  -webkit-text-size-adjust:100%;
  -webkit-tap-highlight-color:transparent;
  overscroll-behavior-y:none;
}
button,input,a{font-family:inherit}
[hidden]{display:none !important}
:focus-visible{outline:2px solid var(--azure);outline-offset:2px}

/* ---- 上部 ---- */
.topbar{
  display:flex;align-items:center;gap:9px;
  padding:calc(9px + env(safe-area-inset-top)) 16px 9px;
  background:linear-gradient(180deg,#1F4E79,#173c5e);
  position:sticky;top:0;z-index:20;
}
.topbar .mark{width:24px;height:24px;display:block}
.topbar h1{font-size:16px;font-weight:bold;margin:0;letter-spacing:.04em}
.topbar .tally{
  margin-left:auto;font-size:12px;color:#cfe1f2;
  border:1px solid rgba(255,255,255,.28);border-radius:999px;padding:3px 10px;
}

.controls{
  background:var(--ink);
  padding:12px 16px 10px;
  display:flex;flex-direction:column;gap:11px;
  border-bottom:1px solid var(--line);
}
.seg{display:flex;background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:3px;gap:3px}
.seg button{
  flex:1;border:0;background:transparent;color:var(--muted);
  font-size:13.5px;padding:9px 4px;border-radius:7px;cursor:pointer;
}
.seg button.on{background:var(--azure);color:#07121d;font-weight:bold}

.switch{display:flex;align-items:center;gap:10px;font-size:13.5px;color:var(--muted);cursor:pointer}
.switch input{position:absolute;opacity:0;width:0;height:0}
.switch .track{
  width:42px;height:25px;border-radius:999px;background:#2A3744;
  position:relative;flex:0 0 auto;transition:background .15s;
}
.switch .knob{
  position:absolute;top:3px;left:3px;width:19px;height:19px;border-radius:50%;
  background:#8FA0B2;transition:transform .15s,background .15s;
}
.switch input:checked + .track{background:rgba(88,166,232,.35)}
.switch input:checked + .track .knob{transform:translateX(17px);background:var(--azure)}
.switch input:focus-visible + .track{outline:2px solid var(--azure);outline-offset:2px}

/* ---- 作業台 ---- */
.desk{
  min-height:calc(100dvh - 200px);
  padding:16px 16px calc(var(--dock-h) + env(safe-area-inset-bottom) + 20px);
}
.empty{text-align:center;padding:12vh 0 10px}
.empty .lead{font-size:15px;margin:26px 0 6px}
.empty .sub{font-size:12.5px;color:var(--muted);margin:0;line-height:1.8}
.empty .guide{width:150px;height:120px;display:block;margin:0 auto}
.empty .guide .paper{fill:#fff;opacity:.9}
.empty .guide .rule{stroke:#B9C6D4;stroke-width:2.6;stroke-linecap:round;fill:none}
.empty .guide .corner{stroke:var(--azure);stroke-width:2.6;fill:none;stroke-linecap:round}

/* シャッター */
.shutter{
  width:66px;height:66px;border-radius:50%;
  border:3px solid rgba(255,255,255,.85);background:transparent;
  padding:0;cursor:pointer;display:grid;place-items:center;flex:0 0 auto;
}
.shutter span{width:50px;height:50px;border-radius:50%;background:#fff;transition:transform .1s}
.shutter:active span{transform:scale(.88)}

/* 紙 */
.sheets{display:flex;flex-direction:column;gap:18px;max-width:560px;margin:0 auto}
.sheet{
  background:#fff;border-radius:3px;
  box-shadow:0 14px 26px rgba(0,0,0,.45),0 2px 4px rgba(0,0,0,.4);
  overflow:hidden;position:relative;
}
.sheet img{width:100%;display:block;min-height:120px;background:#f0f2f5}
.sheet .num{
  position:absolute;top:0;left:0;
  background:rgba(13,20,28,.72);color:#fff;font-size:11.5px;
  padding:4px 9px;border-bottom-right-radius:6px;
}
.sheet .ops{display:flex;background:#fff;border-top:1px solid #e4e8ee}
.sheet .ops button{
  flex:1;min-height:46px;border:0;border-right:1px solid #e4e8ee;
  background:#fff;color:var(--navy);font-size:16px;cursor:pointer;
}
.sheet .ops button:last-child{border-right:0}
.sheet .ops button.del{color:#b3261e}
.sheet.pending{min-height:180px;background:var(--panel);box-shadow:none;border:1px dashed var(--line)}
.sheet.pending .bar{
  position:absolute;inset:auto 0 0 0;height:3px;background:var(--azure);
  animation:sweep 1.1s linear infinite;transform-origin:left;
}
.sheet.pending .waiting{color:var(--muted);font-size:13px;text-align:center;padding:76px 0}
@keyframes sweep{0%{transform:scaleX(0)}60%{transform:scaleX(1)}100%{transform:scaleX(1);opacity:.2}}
.sheet.arrive{animation:arrive .22s ease-out}
@keyframes arrive{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}

.note{
  max-width:560px;margin:14px auto 0;
  background:#3a1f22;border:1px solid #6b3237;color:#ffc9c9;
  border-radius:9px;padding:11px 13px;font-size:13px;
}

/* ---- 下部の操作バー ---- */
.dock{
  position:fixed;left:0;right:0;bottom:0;z-index:30;
  height:calc(var(--dock-h) + env(safe-area-inset-bottom));
  padding-bottom:env(safe-area-inset-bottom);
  display:flex;align-items:center;justify-content:space-around;
  background:rgba(13,20,28,.93);
  backdrop-filter:blur(12px);
  border-top:1px solid var(--line);
}
.dockbtn{
  display:flex;flex-direction:column;align-items:center;gap:5px;
  width:92px;padding:6px 0;border:0;background:transparent;
  color:var(--text);font-size:11.5px;cursor:pointer;
}
.dockbtn svg{width:25px;height:25px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linejoin:round;stroke-linecap:round}
.dockbtn svg .f{fill:currentColor;stroke:none}
.dockbtn:disabled{color:#4E5C6B;cursor:default}

/* ---- 結果パネル ---- */
.result{
  position:fixed;left:0;right:0;bottom:0;z-index:40;
  background:var(--panel);border-top:1px solid var(--line);
  border-radius:16px 16px 0 0;
  padding:16px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow:0 -12px 34px rgba(0,0,0,.5);
  animation:rise .2s ease-out;
}
@keyframes rise{from{transform:translateY(100%)}to{transform:none}}
.rtop{display:flex;align-items:center;margin-bottom:4px}
.rtop strong{font-size:15.5px}
.result .rmeta{font-size:12.5px;color:var(--muted);margin:0 0 14px}
.rbtns{display:flex;flex-direction:column;gap:9px}
.wide{
  width:100%;
  display:flex;align-items:center;justify-content:center;
  min-height:52px;border-radius:11px;border:0;
  background:var(--azure);color:#07121d;
  font-size:15.5px;font-weight:bold;text-decoration:none;cursor:pointer;
}
.wide.ghost{background:transparent;border:1px solid var(--line);color:var(--text);font-weight:normal}
.rhint{font-size:12px;color:var(--muted);line-height:1.65;margin:12px 0 0}
.x{
  margin-left:auto;width:34px;height:34px;border:0;border-radius:50%;
  background:transparent;color:var(--muted);font-size:15px;cursor:pointer;
}

/* ---- 拡大表示 ---- */
.viewer{
  position:fixed;inset:0;z-index:60;background:#05090d;
  display:flex;align-items:center;justify-content:center;
  overflow:auto;padding:52px 8px;
}
.viewer img{max-width:100%;height:auto;box-shadow:0 8px 30px rgba(0,0,0,.6)}
.viewer .x{
  position:fixed;top:calc(10px + env(safe-area-inset-top));right:10px;
  background:rgba(255,255,255,.12);color:#fff;width:40px;height:40px;
}

@media (min-width:700px){
  .sheets{max-width:620px}
  .desk{padding-bottom:calc(var(--dock-h) + 40px)}
}
@media (prefers-reduced-motion:reduce){
  *{animation:none !important;transition:none !important}
}

/* ---- 設定（保存先） ---- */
.gear{margin-left:10px;width:34px;height:34px;border:0;background:transparent;padding:0;cursor:pointer}
.gear svg{width:22px;height:22px;fill:none;stroke:#dbe8f5;stroke-width:1.6;stroke-linejoin:round}
.topbar .tally + .gear{margin-left:8px}
.topbar .gear:only-of-type{margin-left:auto}
.tally ~ .gear{margin-left:8px}

.sheetwrap{position:fixed;inset:0;z-index:50;background:rgba(5,9,13,.6);display:flex;align-items:flex-end}
.sheetwrap .panel{
  width:100%;max-height:88vh;overflow:auto;
  background:var(--panel);border-radius:16px 16px 0 0;border-top:1px solid var(--line);
  padding:16px 16px calc(20px + env(safe-area-inset-bottom));
  animation:rise .2s ease-out;
}
.dest{
  display:flex;gap:11px;align-items:flex-start;
  border:1px solid var(--line);border-radius:12px;padding:13px;margin-bottom:11px;cursor:pointer;
}
.dest.on{border-color:var(--azure);background:rgba(88,166,232,.08)}
.dest.off{opacity:.45}
.dest input[type=radio]{width:20px;height:20px;margin:1px 0 0;accent-color:var(--azure);flex:0 0 auto}
.dest .body{display:block;flex:1}
.dest .nm{display:block;font-size:14.5px;margin-bottom:3px}
.dest .nm em{font-style:normal;font-size:11.5px;color:var(--muted)}
.dest .nm em.ok{color:#6FD08C}
.dest .ds{display:block;font-size:12px;color:var(--muted);line-height:1.65}
.dest .sub{
  display:none;width:100%;margin-top:9px;padding:9px 10px;
  background:#0E1721;border:1px solid var(--line);border-radius:8px;
  color:var(--text);font-size:14px;
}
.dest.on .sub{display:block}
.dest .connect{
  display:none;margin-top:9px;padding:9px 14px;border-radius:8px;
  border:1px solid var(--azure);background:transparent;color:var(--azure);
  font-size:13.5px;cursor:pointer;
}
.dest .connect.show{display:inline-block}

.rbtns .row{display:flex;gap:9px}
.half{
  flex:1;display:flex;align-items:center;justify-content:center;
  min-height:46px;border-radius:10px;border:1px solid var(--line);
  background:transparent;color:var(--text);font-size:14px;text-decoration:none;cursor:pointer;
}
.wide.done{background:#2C7A4B;color:#fff}

.toast{
  position:fixed;left:50%;top:calc(56px + env(safe-area-inset-top));transform:translateX(-50%);
  z-index:70;max-width:90%;
  background:#0B2E1C;border:1px solid #2C7A4B;color:#CFEFDC;
  padding:11px 16px;border-radius:999px;font-size:13.5px;white-space:nowrap;
  overflow:hidden;text-overflow:ellipsis;
}
.toast.err{background:#3a1f22;border-color:#6b3237;color:#ffc9c9}

/* ---- 追加機能 ---- */
#readmode button{font-size:13px}
.fname{
  width:100%;margin:2px 0 10px;padding:10px 11px;
  background:#0E1721;border:1px solid var(--line);border-radius:9px;
  color:var(--text);font-size:14.5px;
}
.howto{display:none;margin-top:9px;font-size:12.5px;color:var(--azure)}
.dest.off .howto{display:inline-block}
.opt2{
  display:flex;gap:11px;align-items:flex-start;
  border-top:1px solid var(--line);padding:14px 2px 4px;margin-top:4px;cursor:pointer;
}
.opt2 input{width:20px;height:20px;margin:1px 0 0;accent-color:var(--azure);flex:0 0 auto}
.opt2 .nm{display:block;font-size:14.5px;margin-bottom:3px}
.opt2 .ds{display:block;font-size:12px;color:var(--muted);line-height:1.65}
.opt2.off{display:none}
.cardstep{
  max-width:560px;margin:0 auto 14px;
  background:rgba(88,166,232,.1);border:1px solid rgba(88,166,232,.4);
  color:#CFE4F6;border-radius:10px;padding:12px 14px;font-size:13.5px;line-height:1.7;
}
.cardstep button{
  margin-top:9px;padding:8px 14px;border-radius:8px;
  border:1px solid var(--azure);background:transparent;color:var(--azure);
  font-size:13px;cursor:pointer;
}

/* ---- アカウント ---- */
.account{margin-bottom:14px}
.account .ds{font-size:12.5px;color:var(--muted);margin:0 0 10px;line-height:1.7}
.account input{
  width:100%;margin-bottom:9px;padding:11px;
  background:#0E1721;border:1px solid var(--line);border-radius:9px;
  color:var(--text);font-size:15px;
}
.signed{
  display:flex;align-items:center;gap:10px;
  background:#0E1721;border:1px solid var(--line);border-radius:10px;padding:11px 13px;
  font-size:13.5px;
}
.signed button{
  margin-left:auto;border:0;background:transparent;color:var(--azure);
  font-size:13px;cursor:pointer;padding:4px;
}
.dest.locked{opacity:.45}
.dest.locked .howto{display:none}
