:root{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#eaf7ff;background:#07101a;--panel:#0d1c29;--line:#24485e;--cyan:#28d8ff;--muted:#94afbf;--danger:#ff667a;}
*{box-sizing:border-box}body{margin:0;background:radial-gradient(circle at top,#102b3b,#060b11 55%);min-height:100vh}.app{max-width:1080px;margin:auto;padding:14px}.hero{display:flex;justify-content:space-between;gap:16px;align-items:end;margin-bottom:12px}.hero h1{font-size:clamp(20px,4vw,34px);margin:0}.hero p{margin:4px 0 0;color:var(--muted)}.free-tag{background:#0b634a;border:1px solid #36dca4;padding:8px 12px;border-radius:999px;font-weight:800;white-space:nowrap}.panel{background:linear-gradient(180deg,rgba(15,34,48,.96),rgba(8,20,30,.96));border:1px solid #24475a;border-radius:16px;padding:14px;box-shadow:0 10px 30px #0007}.top-grid{display:grid;grid-template-columns:minmax(300px,1.1fr) minmax(280px,.9fr);gap:14px}.board-wrap{max-width:620px;margin:auto}.board{display:grid;grid-template-columns:repeat(9,1fr);aspect-ratio:1;border:3px solid #3bcdf8;border-radius:10px;overflow:hidden;background:#03141e}.board-cell{border:1px solid #16435b;background:#072433;position:relative;min-width:0}.board-cell:nth-child(3n){border-right:2px solid #2b89ba}.board-cell:nth-child(9n){border-right:1px solid #16435b}.board-cell:nth-child(n+19):nth-child(-n+27),.board-cell:nth-child(n+46):nth-child(-n+54){border-bottom:2px solid #2b89ba}.board-cell.filled,.board-cell.preview-filled{background:linear-gradient(135deg,#08a8dc,#045b91);box-shadow:inset 0 0 0 2px #47e8ff}.board-cell.suggested{outline:4px solid #fff700;z-index:2;background:var(--piece-color,#1d69ff)!important;box-shadow:inset 0 0 0 2px var(--piece-soft,#fff)}.board-cell.will-clear:after{content:"";position:absolute;inset:14%;border:2px dashed #fff8;border-radius:4px}@keyframes pulse{to{filter:brightness(1.45)}}
.controls{display:grid;grid-template-columns:repeat(2,1fr);gap:10px;margin-bottom:12px}.field{display:flex;flex-direction:column;gap:5px}.field label{font-size:12px;color:var(--muted)}input,select,button{font:inherit}input,select{background:#071722;color:#fff;border:1px solid #315366;border-radius:10px;padding:10px;width:100%}.button-row{display:flex;gap:8px;flex-wrap:wrap}.btn{border:1px solid #31627b;background:#102d3d;color:#fff;border-radius:11px;padding:10px 13px;font-weight:750;cursor:pointer}.btn:hover{filter:brightness(1.15)}.btn.primary{background:linear-gradient(#0cc6ef,#067ba5);border-color:#55e5ff}.btn.good{background:linear-gradient(#22a76f,#116a4c);border-color:#5ee6ac}.btn.warn{background:#4a2831;border-color:#8a4958}.btn:disabled{opacity:.4;cursor:not-allowed}.tips{font-size:13px;color:#b9d2df;line-height:1.55;margin-top:12px}.tips b{color:#fff}
.pieces{margin-top:14px}.pieces h2,.result-panel h2{font-size:18px;margin:0 0 10px}.piece-row{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}.piece-card{border:1px solid #2c5266;border-radius:14px;padding:10px;background:#081722;box-shadow:inset 0 3px 0 var(--piece-color,#2c5266)}.piece-card.used{opacity:1}.piece-title{display:flex;justify-content:space-between;align-items:center;margin-bottom:7px}.piece-title b{font-size:20px}.piece-editor{display:grid;grid-template-columns:repeat(5,1fr);aspect-ratio:1;max-width:190px;margin:8px auto;gap:2px}.piece-cell{border:1px solid #1d4054;border-radius:3px;background:#06111a}.piece-cell.on{box-shadow:inset 0 0 0 1px var(--piece-soft,#a9efff)}.piece-cell.on.dynamic-piece{background:var(--piece-color,#216cff)}.micro{font-size:11px;color:var(--muted);margin:5px 0 0}.result-panel{margin-top:14px}.result-head{display:flex;justify-content:space-between;align-items:center;gap:10px}.result-head h3{margin:4px 0}.badge{font-size:11px;background:#10523e;border:1px solid #35bb8d;padding:3px 8px;border-radius:999px}.gain{font-size:34px;font-weight:900;color:#62f4b9}.gain small{font-size:11px;display:block;color:var(--muted);text-align:right}.step-list{display:grid;gap:7px;margin:10px 0}.step-chip{text-align:left;border:1px solid #335367;background:#0a1b27;color:#dcecf3;border-radius:10px;padding:10px;cursor:pointer}.step-chip.active{border-color:#e8f937;box-shadow:0 0 0 2px #e8f93744}.metrics{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}.metrics div{background:#071722;border:1px solid #203f51;border-radius:10px;padding:8px}.metrics span{display:block;font-size:11px;color:var(--muted)}.metrics b{font-size:18px}.note{font-size:11px;color:#7e9bab}.empty-result,.danger-result{padding:20px;border:1px dashed #3c6073;border-radius:12px;color:#a9bfca}.danger-result{border-color:#8a4554;color:#ffd8de;background:#32141c}.footer-actions{display:flex;gap:8px;justify-content:space-between;align-items:center;flex-wrap:wrap;margin-top:10px}.stats{font-size:11px;color:#7295a7}
@media(max-width:760px){.app{padding:8px}.hero{align-items:start}.free-tag{font-size:11px}.top-grid{grid-template-columns:1fr}.panel{padding:10px;border-radius:12px}.piece-row{grid-template-columns:repeat(3,1fr);gap:5px}.piece-card{padding:6px}.piece-title b{font-size:16px}.piece-editor{gap:1px}.preset{font-size:11px;padding:7px}.metrics{grid-template-columns:repeat(2,1fr)}.btn{padding:9px 10px}.board-wrap{max-width:96vw}}

/* v0.1.2: visual preset picker + drag /* v0.1.1: visual preset picker + drag & drop */ drop + dynamic piece colors */
.pieces-heading{display:flex;justify-content:space-between;gap:12px;align-items:center;margin-bottom:10px}.pieces-heading h2{margin:0}.pieces-heading p{margin:3px 0 0;color:var(--muted);font-size:12px}.drag-badge{font-size:11px;border:1px solid #397896;background:#0a2a3b;padding:5px 9px;border-radius:999px;white-space:nowrap}.preset-open{width:100%;background:#12354a}.current-piece-box{display:flex;min-height:132px;flex-direction:column;align-items:center;justify-content:center;gap:7px;margin:8px 0;border:1px dashed #31596d;border-radius:12px;background:#06131d;padding:8px}.current-piece-label{font-size:12px;color:#cde6f2}.drag-copy{font-size:10px;color:#7fa4b7}.piece-drag-shape,.preset-visual,.drag-ghost{display:grid;grid-template-columns:repeat(var(--shape-cols,1),1fr);grid-template-rows:repeat(var(--shape-rows,1),1fr);gap:3px}.piece-drag-shape{min-width:48px;min-height:48px;max-width:148px;max-height:108px;touch-action:none;user-select:none;-webkit-user-select:none}.piece-drag-shape.empty{display:flex;align-items:center;justify-content:center;color:#5f8193;font-size:11px}.mini-piece-cell{width:25px;height:25px;border-radius:5px;border:1px solid transparent}.mini-piece-cell.blank{opacity:0}.mini-piece-cell.on{border-color:var(--piece-soft,#a9efff);box-shadow:inset 0 0 0 1px #ffffff35}.mini-piece-cell.on.dynamic-piece{background:var(--piece-color,#216cff)}.mini-piece-cell.grab-cell{cursor:grab;touch-action:none}.mini-piece-cell.grab-cell:active{cursor:grabbing}.custom-editor{font-size:11px;color:var(--muted)}.custom-editor summary{cursor:pointer;padding:6px 0}.custom-editor[open] .piece-editor{margin-top:6px}
.drag-hint{margin-top:9px;padding:8px 10px;border-radius:9px;background:#071722;border:1px solid #23495d;color:#9ebdcb;font-size:12px;min-height:34px}.drag-hint.active{border-color:#dfed51;color:#f4f9be}.drag-hint.success{border-color:#36c98e;color:#b8f5da;background:#0b2a20}.drag-hint.error{border-color:#ab5868;color:#ffd2db;background:#2b141a}.board-cell.drag-valid{z-index:3;outline:3px solid #7dff9d;background:#167c58!important;box-shadow:inset 0 0 0 2px #c8ffd5}.board-cell.drag-invalid{z-index:3;outline:3px solid #ff657c;background:#7d2432!important}.drag-ghost{position:fixed;z-index:9999;pointer-events:none;opacity:0;filter:drop-shadow(0 5px 8px #0008)}.drag-ghost.active{opacity:.82}.drag-ghost{gap:var(--ghost-gap,3px)}.drag-ghost .mini-piece-cell{width:var(--ghost-cell,26px);height:var(--ghost-cell,26px)}
.preset-dialog{width:min(760px,calc(100vw - 18px));max-height:86vh;border:1px solid #376276;border-radius:16px;background:#081722;color:#eaf7ff;padding:14px;box-shadow:0 18px 60px #000b}.preset-dialog::backdrop{background:#000b}.preset-dialog-head{display:flex;justify-content:space-between;gap:12px;align-items:start;position:sticky;top:-14px;background:#081722;padding:4px 0 9px;z-index:2;border-bottom:1px solid #203f51}.preset-dialog-head h2{margin:0;font-size:19px}.preset-dialog-head p{margin:4px 0 0;color:var(--muted);font-size:12px}.preset-tools{margin:10px 0}.preset-group{margin:14px 0}.preset-group h3{font-size:14px;margin:0 0 7px;color:#b9d7e6}.preset-options{display:grid;grid-template-columns:repeat(5,1fr);gap:7px}.preset-option{border:1px solid #2d5367;background:#0b2130;color:#eaf7ff;border-radius:11px;padding:8px 5px;min-height:91px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;cursor:pointer}.preset-option:hover,.preset-option:focus-visible{border-color:#54dbff;background:#103349}.preset-visual{min-height:50px;align-content:center;justify-content:center}.preset-visual .mini-piece-cell{width:17px;height:17px;border-radius:3px}.preset-option-name{font-size:10px;color:#b9d1dc;text-align:center}.piece-card.used .current-piece-box{pointer-events:none;opacity:.42}.piece-card.used .custom-editor{opacity:.55}.piece-card.used .preset-open{pointer-events:auto;opacity:1}
@media(max-width:760px){.current-piece-box{min-height:105px;padding:5px}.mini-piece-cell{width:20px;height:20px}.preset-open{font-size:11px;padding:8px 5px}.drag-copy{display:none}.current-piece-label{font-size:10px}.preset-options{grid-template-columns:repeat(4,1fr)}.preset-option{min-height:82px;padding:6px 3px}.preset-visual .mini-piece-cell{width:15px;height:15px}.preset-dialog{padding:10px}.preset-dialog-head{top:-10px}.piece-drag-shape{max-width:92px;max-height:82px}}
@media(max-width:420px){.preset-options{grid-template-columns:repeat(3,1fr)}.piece-row{grid-template-columns:repeat(3,minmax(0,1fr))}.piece-card{min-width:0}.current-piece-box{min-height:92px}.mini-piece-cell{width:17px;height:17px}.piece-title span{font-size:10px}.preset-open{line-height:1.15}.custom-editor summary{font-size:10px}}


/* v0.1.2b: 解析ナビはドラッグ中も消さない。ドラッグ可否の色に上書きされても黄色マーカーを残す。 */
.board-cell.suggested::before{
  content:"◆";
  position:absolute;
  top:2px;
  left:3px;
  z-index:8;
  color:#fff700;
  font-size:clamp(9px,2vw,15px);
  line-height:1;
  text-shadow:0 1px 2px #000,0 0 5px #000;
  pointer-events:none;
}
.board-cell.suggested.drag-valid,
.board-cell.suggested.drag-invalid{
  box-shadow:inset 0 0 0 3px #fff700, inset 0 0 0 6px #0006;
}


/* v0.1.2c: 解析ナビを独立レイヤー化。ドラッグ中も黄色ナビを常時最前面に保持 */
.board-cell.suggested{
  /* outlineはドラッグ側に奪われても、内側の黄色リングは残る */
  box-shadow:inset 0 0 0 3px #fff700, inset 0 0 0 5px #0007 !important;
}
.board-cell.suggested::before{
  content:"◆";
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  z-index:20;
  color:#fff700;
  font-size:clamp(11px,2.5vw,19px);
  line-height:1;
  text-shadow:0 1px 2px #000,0 0 5px #000,0 0 8px #000;
  pointer-events:none;
}
.board-cell.suggested.drag-valid{
  outline:3px solid #7dff9d;
  /* 黄色ナビ + 緑のドラッグ可を同時表示 */
  background:linear-gradient(135deg,#167c58,#0f5d42)!important;
  box-shadow:inset 0 0 0 3px #fff700, inset 0 0 0 6px #134c2e !important;
}
.board-cell.suggested.drag-invalid{
  outline:3px solid #ff657c;
  /* 黄色ナビ + 赤のドラッグ不可を同時表示 */
  background:linear-gradient(135deg,#7d2432,#5e1825)!important;
  box-shadow:inset 0 0 0 3px #fff700, inset 0 0 0 6px #531622 !important;
}


/* v0.1.2d: A/B/Cから解析ナビ位置へワンタップ配置 */
.nav-place{width:100%;margin:0 0 8px;background:#102839;border-color:#355c70;color:#9eb9c7}
.nav-place.nav-ready{background:linear-gradient(180deg,#d7e925,#8fa700);border-color:#f6ff6a;color:#111;font-weight:900;box-shadow:0 0 0 2px #e8f93733,0 0 18px #e8f93722}
.nav-place.nav-ready:hover{filter:brightness(1.08)}
.nav-place:disabled{opacity:.5}
@media(max-width:760px){.nav-place{font-size:10px;line-height:1.15;padding:8px 4px}}

.inline-field{display:flex;gap:8px;align-items:center}.inline-field input{min-width:0;flex:1}.btn.compact{padding:8px 10px;white-space:nowrap}.field-help{display:block;margin-top:5px;opacity:.72;line-height:1.35}.step-chip small{display:block;margin-top:4px;font-weight:500;opacity:.75;font-size:11px}

/* v0.1.4b: ドラッグ/ナビ配置後も色を盤面に保持 */
.board-cell.filled.board-colored,.board-cell.preview-filled.board-colored{background:var(--piece-color,#216cff);box-shadow:inset 0 0 0 2px var(--piece-soft,#a9efff)}

.order-banner{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:10px 0 6px;padding:10px 12px;border:1px solid #3b7895;border-radius:11px;background:#092535}.order-banner span{font-size:12px;color:#8bb8cc}.order-banner strong{font-size:22px;letter-spacing:.04em;color:#fff}.alt-orders{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:0 0 9px;font-size:11px;color:#7698a8}.alt-orders b{padding:4px 7px;border:1px solid #29495a;border-radius:7px;color:#b7ced9;background:#081822}.metrics-6{grid-template-columns:repeat(3,1fr)}.ai-reasons{margin-top:10px;padding:10px 12px;border:1px solid #264a5d;border-radius:11px;background:#071923}.ai-reasons>b{font-size:12px;color:#bfe7f7}.ai-reasons ul{margin:7px 0 0 18px;padding:0;color:#9fc1cf;font-size:12px;line-height:1.55}.ai-reasons li::marker{color:#50d9a4}@media(max-width:760px){.metrics-6{grid-template-columns:repeat(2,1fr)}.order-banner strong{font-size:18px}}


/* v0.1.6a: PC版はv0.1.5のレイアウトを完全維持。以下はスマホだけに適用 */
.mobile-action-bar{display:none}
@media(max-width:760px){
  .hero{margin-bottom:8px}
  .hero p{font-size:11px}
  .free-tag{padding:6px 9px}

  .mobile-action-bar{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:8px;
    position:sticky;
    top:max(4px, env(safe-area-inset-top));
    z-index:120;
    padding:6px;
    margin:0 0 8px;
    border:1px solid #315a6e;
    border-radius:13px;
    background:rgba(5,18,28,.94);
    backdrop-filter:none;
    box-shadow:0 8px 20px #0008;
  }
  .mobile-main-btn{min-height:48px;font-size:16px;font-weight:900;padding:10px 8px}
  .mobile-action-bar .btn:disabled{opacity:.48}

  /* JSで piecesPanel を board と controlPanel の間へ移動する */
  #topGrid{display:flex;flex-direction:column;gap:8px}
  #topGrid>.panel{width:100%}
  #piecesPanel{margin-top:0;padding:8px}
  .board-wrap{max-width:min(100%,620px)}
  .drag-hint{margin-top:6px}
  .footer-actions{margin-top:7px}

  .pieces-heading{margin-bottom:6px}
  .pieces-heading p{font-size:11px}
  .drag-badge{display:none}
  .piece-row{grid-template-columns:1fr;gap:7px}
  .piece-card{
    display:grid;
    grid-template-columns:52px minmax(110px,1fr) minmax(112px,1fr);
    grid-template-areas:
      "title preset nav"
      "title shape nav"
      "details details details";
    gap:5px 7px;
    align-items:stretch;
    padding:7px;
    min-width:0;
  }
  .piece-title{grid-area:title;display:flex;flex-direction:column;justify-content:center;align-items:center;margin:0;border-right:1px solid #224455;padding-right:5px}
  .piece-title b{font-size:25px;line-height:1}
  .piece-title span{font-size:10px;text-align:center;margin-top:5px}
  .preset-open{grid-area:preset;min-height:40px;font-size:12px;padding:7px 5px}
  .current-piece-box{grid-area:shape;min-height:64px;margin:0;padding:4px;gap:3px}
  .piece-drag-shape{max-width:120px;max-height:64px;min-width:40px;min-height:38px}
  .mini-piece-cell{width:18px;height:18px}
  .current-piece-label{font-size:9px}
  .nav-place{grid-area:nav;margin:0;min-height:100%;font-size:12px;line-height:1.25;padding:8px 6px}
  .custom-editor{grid-area:details}
  .custom-editor summary{padding:3px 0;font-size:10px}
  .micro{display:none}
  .control-panel>.button-row .primary,
  .control-panel>.button-row .good{min-height:44px}
}
@media(max-width:390px){
  .piece-card{grid-template-columns:44px minmax(96px,1fr) minmax(100px,1fr);gap:4px}
  .piece-title b{font-size:22px}
  .preset-open,.nav-place{font-size:11px}
  .mini-piece-cell{width:16px;height:16px}
}


/* v0.1.6b: モバイルのA/B/Cを横3列化。ピースは必ず表示枠内へ収める。PC版は変更しない。 */
@media(max-width:760px){
  #piecesPanel{padding:8px 6px 9px}
  #piecesPanel .pieces-heading{margin-bottom:6px}
  #piecesPanel .pieces-heading h2{font-size:16px}
  #piecesPanel .pieces-heading p{font-size:10px;line-height:1.3}

  #piecesPanel .piece-row{
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:5px;
    align-items:stretch;
  }
  #piecesPanel .piece-card{
    display:flex;
    flex-direction:column;
    min-width:0;
    padding:6px 5px;
    gap:5px;
    border-radius:12px;
    overflow:hidden;
  }
  #piecesPanel .piece-title{
    display:flex;
    flex-direction:row;
    justify-content:space-between;
    align-items:center;
    border-right:0;
    border-bottom:1px solid #224455;
    padding:0 1px 5px;
    margin:0;
    min-height:28px;
  }
  #piecesPanel .piece-title b{font-size:21px;line-height:1}
  #piecesPanel .piece-title span{font-size:9px;margin:0;text-align:right;white-space:nowrap}
  #piecesPanel .preset-open{
    width:100%;
    min-height:36px;
    padding:6px 3px;
    font-size:11px;
    line-height:1.05;
  }
  #piecesPanel .current-piece-box{
    width:100%;
    min-width:0;
    height:104px;
    min-height:104px;
    max-height:104px;
    margin:0;
    padding:5px 3px;
    gap:3px;
    overflow:hidden;
    justify-content:flex-start;
  }
  #piecesPanel .current-piece-label{
    width:100%;
    min-height:14px;
    font-size:9px;
    line-height:1.1;
    text-align:center;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  #piecesPanel .piece-drag-shape{
    width:auto;
    min-width:0;
    min-height:0;
    max-width:100%;
    max-height:78px;
    margin:auto;
    gap:2px;
    align-content:center;
    justify-content:center;
  }
  #piecesPanel .piece-drag-shape .mini-piece-cell{width:18px;height:18px;border-radius:4px}
  #piecesPanel .piece-drag-shape.shape-max-3 .mini-piece-cell{width:17px;height:17px}
  #piecesPanel .piece-drag-shape.shape-max-4 .mini-piece-cell{width:15px;height:15px}
  #piecesPanel .piece-drag-shape.shape-max-5 .mini-piece-cell{width:13px;height:13px;border-radius:3px}
  #piecesPanel .nav-place{
    width:100%;
    min-height:48px;
    margin:0;
    padding:6px 3px;
    font-size:9.5px;
    line-height:1.15;
  }
  #piecesPanel .custom-editor{font-size:9px;margin-top:auto}
  #piecesPanel .custom-editor summary{padding:2px 0;font-size:9px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  #piecesPanel .piece-editor{max-width:100%;margin:5px auto;gap:1px}
  #piecesPanel .micro{display:none}
}
@media(max-width:390px){
  #piecesPanel .piece-row{gap:4px}
  #piecesPanel .piece-card{padding:5px 4px}
  #piecesPanel .piece-title b{font-size:19px}
  #piecesPanel .preset-open{font-size:10px;min-height:34px}
  #piecesPanel .current-piece-box{height:96px;min-height:96px;max-height:96px}
  #piecesPanel .piece-drag-shape .mini-piece-cell{width:16px;height:16px}
  #piecesPanel .piece-drag-shape.shape-max-4 .mini-piece-cell{width:14px;height:14px}
  #piecesPanel .piece-drag-shape.shape-max-5 .mini-piece-cell{width:12px;height:12px}
  #piecesPanel .nav-place{font-size:9px;min-height:44px}
}


/* v0.1.6c: タッチドラッグの基準位置を指より上へ。掴んだマスと照準を一致させる。 */
.drag-cursor{
  position:fixed;z-index:10001;width:24px;height:24px;pointer-events:none;
  opacity:0;transform:translate(-50%,-50%);border:2px solid #fff;border-radius:50%;
  box-shadow:0 0 0 2px #00d8ff,0 2px 8px #000b;background:#08213088;
}
.drag-cursor::before,.drag-cursor::after{content:"";position:absolute;left:50%;top:50%;background:#fff;transform:translate(-50%,-50%);border-radius:2px}
.drag-cursor::before{width:14px;height:2px}.drag-cursor::after{width:2px;height:14px}
.drag-cursor.active{opacity:.95}
@media(max-width:760px),(pointer:coarse){
  .drag-ghost.active{opacity:.72;filter:drop-shadow(0 7px 10px #000a)}
  .board-cell.drag-valid,.board-cell.drag-invalid{outline-width:2px}
}
