/* ===================================================================
   ニュース風ジェネレーター (NewsGen)
=================================================================== */

:root{
  --dark:#0b0f13; --dark-2:#0e1318; --panel:#131920; --panel-2:#171f27;
  --raised:#1c242c; --paper:#eef3f6; --ink:#d7dee4; --ink-dim:#b7c1c9;
  --muted:#7c8894; --line:#26303a; --line-soft:#1c242c;
  --accent:#29e0c4; --accent-2:#12a894; --accent-ink:#04241f; --danger:#e05a3a;
  --mono:"JetBrains Mono","SFMono-Regular",Consolas,monospace;
  --sans:"Zen Kaku Gothic New","Hiragino Sans","Noto Sans JP",sans-serif;
  --serif:"Noto Serif JP",serif;
}
html[data-theme="dark"]{
  --dark:#0b0f13; --dark-2:#0e1318; --panel:#131920; --panel-2:#171f27;
  --raised:#1c242c; --paper:#eef3f6; --ink:#d7dee4; --ink-dim:#b7c1c9;
  --muted:#7c8894; --line:#26303a; --line-soft:#1c242c;
  --accent:#29e0c4; --accent-2:#12a894; --accent-ink:#04241f; --danger:#e05a3a;
}
html[data-theme="light"]{
  --dark:#ffffff; --dark-2:#f3f5f6; --panel:#ffffff; --panel-2:#f1f3f4;
  --raised:#e7eaec; --paper:#12181f; --ink:#222a33; --ink-dim:#4c5866;
  --muted:#828d99; --line:#dbe0e3; --line-soft:#e9ecee;
  --accent:#0f9c8c; --accent-2:#0c7c70; --accent-ink:#ffffff; --danger:#c8442a;
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;height:100%;}
body{
  background:
    radial-gradient(ellipse 800px 460px at 80% -10%, rgba(41,224,196,.07), transparent 60%),
    var(--dark);
  color:var(--ink);
  font-family:var(--sans);
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

/* ---------- ヘッダー ---------- */
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:20px;
  padding:14px 24px;
  border-bottom:1px solid var(--line);
  background:linear-gradient(180deg, var(--panel), var(--dark-2));
  flex-wrap:wrap;
}
.brand{display:flex;align-items:center;gap:10px;}
.back-link{
  font-family:var(--mono); font-size:11.5px; color:var(--muted);
  border:1px solid var(--line); background:var(--panel-2);
  padding:6px 11px; border-radius:20px; text-decoration:none;
  transition:border-color .15s, color .15s; white-space:nowrap;
}
.back-link:hover{ border-color:var(--accent); color:var(--accent); }
.brand-name{ font-weight:900; font-size:16px; color:var(--paper); }
.local-badge{
  position:relative; display:inline-flex; align-items:center; gap:7px;
  font-family:var(--mono); font-size:11px; letter-spacing:.12em; text-transform:uppercase;
  color:var(--ink-dim); border:1px solid var(--line); background:var(--panel-2);
  padding:5px 10px 5px 8px; border-radius:20px; white-space:nowrap;
}
.local-badge::before{
  content:""; width:7px; height:7px; border-radius:50%; background:var(--accent);
  box-shadow:0 0 6px 1px rgba(41,224,196,.9), 0 0 14px 3px rgba(41,224,196,.4);
  animation:nf-pulse 2.6s ease-in-out infinite;
}
@keyframes nf-pulse{ 0%,100%{opacity:1;} 50%{opacity:.45;} }
@media (prefers-reduced-motion: reduce){ .local-badge::before{ animation:none; } }

.toolbar{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
select, input[type=text], input[type=number], input[type=color], textarea{
  font-family:var(--sans); font-size:13px;
  background:var(--panel-2); color:var(--ink);
  border:1px solid var(--line); border-radius:6px; padding:7px 10px;
}
input[type=range]{ width:100%; accent-color:var(--accent); }
select:focus, input:focus, textarea:focus{ outline:2px solid var(--accent); outline-offset:1px; }
.ratio-select{ font-family:var(--mono); font-size:12px; }
.lang-select{ font-family:var(--mono); font-size:11px; padding:6px 8px; }
.theme-toggle{
  width:30px; height:30px; flex:0 0 auto;
  display:flex; align-items:center; justify-content:center;
  border:1px solid var(--line); border-radius:6px; background:var(--panel-2);
  color:var(--ink-dim); font-size:15px; line-height:1; cursor:pointer; padding:0;
}
.theme-toggle:hover{ border-color:var(--accent); color:var(--ink); }
button.primary{
  font-family:var(--sans); font-weight:700; font-size:13px;
  color:var(--accent-ink); background:var(--accent); border:1px solid var(--accent);
  border-radius:6px; padding:8px 16px; cursor:pointer; transition:opacity .15s; white-space:nowrap;
}
button.primary:hover{ opacity:.88; }
button.ghost{
  font-family:var(--sans); font-size:12.5px; color:var(--muted);
  background:var(--panel-2); border:1px solid var(--line); border-radius:6px;
  padding:7px 12px; cursor:pointer; transition:border-color .15s, color .15s;
}
button.ghost:hover{ border-color:var(--accent); color:var(--ink); }
button.ghost.small{ font-size:11.5px; padding:5px 10px; }
button.ghost.danger:hover{ border-color:var(--danger); color:var(--danger); }

/* ---------- メイン ---------- */
main{
  flex:1; display:flex; gap:16px; padding:20px 24px;
  max-width:1560px; width:100%; margin:0 auto; align-items:flex-start;
}
.sidebar{ width:300px; flex:0 0 300px; display:flex; flex-direction:column; gap:18px; }
.col-tools{
  width:240px; flex:1 1 240px; min-width:180px; max-width:240px;
  display:flex; flex-direction:column; gap:18px;
  max-height:calc(100vh - 140px); overflow-y:auto;
}
.col-props{
  width:190px; flex:1 1 190px; min-width:150px; max-width:190px;
  max-height:calc(100vh - 140px); display:flex; flex-direction:column;
}
.props-block{ height:auto; }
.layers-block{ flex:1; display:flex; flex-direction:column; min-height:0; padding-bottom:10px; }
.layers-block h2{ flex:0 0 auto; }
.panel-block{
  background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:16px;
}
.panel-block h2{ font-size:13px; font-weight:900; color:var(--paper); margin:0 0 12px; letter-spacing:.02em; }
.panel-h2{
  display:flex; align-items:center; justify-content:space-between;
  cursor:pointer; user-select:none;
}
.panel-h2 .chev{ font-size:11px; color:var(--muted); transition:transform .15s; flex:0 0 auto; }
.panel-block.collapsed .panel-h2{ margin-bottom:0; }
.panel-block.collapsed .panel-h2 .chev{ transform:rotate(-90deg); }
.panel-block.collapsed .panel-body{ display:none; }
.field{ margin-bottom:12px; }
.field:last-child{ margin-bottom:0; }
.field label{ display:block; font-size:11.5px; color:var(--muted); margin-bottom:5px; font-family:var(--mono); }
.field input, .field textarea, .field select{ width:100%; resize:vertical; }
.field input[type=color]{ height:36px; padding:2px; cursor:pointer; }
.row2{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.hint{ font-size:11.5px; color:var(--muted); line-height:1.6; margin:6px 0 0; }
.layer-list{
  overflow-y:auto; flex:1; min-height:0;
  margin:0 -16px; padding:0 8px;
}
.layer-row{
  display:flex; align-items:center; gap:8px;
  padding:7px 8px; font-size:12px; color:var(--ink-dim);
  cursor:grab; border-bottom:1px solid var(--line-soft);
  border-radius:6px;
  transition:background .1s, color .1s;
}
.layer-row:hover{ background:var(--raised); color:var(--ink); }
.layer-row.selected{ background:rgba(41,224,196,.15); color:var(--paper); font-weight:700; }
.layer-row.dragging-row{ opacity:.4; }
.layer-row.drop-target{ box-shadow:inset 0 2px 0 var(--accent); }
.layer-row-icon{ font-size:13px; flex:0 0 auto; opacity:.85; }
.layer-row-label{
  flex:1 1 auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.layer-row-del{
  width:18px; height:18px; flex:0 0 auto;
  display:flex; align-items:center; justify-content:center;
  border:1px solid var(--line); border-radius:4px;
  background:var(--panel-2); color:var(--ink-dim);
  font-size:10px; line-height:1; cursor:pointer;
}
.layer-row-del:hover{ border-color:var(--danger); color:var(--danger); }
.checkbox-row{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--ink-dim); margin-top:10px; cursor:pointer; }
.checkbox-row input{ width:auto; accent-color:var(--accent); cursor:pointer; }
.add-row{ display:flex; flex-wrap:wrap; gap:8px; }
.add-row button{ flex:1 1 auto; }
.prop-group{ margin-top:12px; padding-top:12px; border-top:1px solid var(--line-soft); }
#propDeleteBtn{ width:100%; margin-top:14px; }

/* ---------- テンプレートギャラリー ---------- */
.template-grid{ display:grid; grid-template-columns:1fr; gap:8px; }
.template-card{
  background:var(--panel-2); border:2px solid var(--line); border-radius:8px; padding:6px;
  cursor:pointer; display:flex; flex-direction:column; align-items:center; gap:6px;
  transition:border-color .15s;
}
.template-card:hover{ border-color:var(--accent); }
.template-card.active{ border-color:var(--accent); background:rgba(41,224,196,.08); }
.template-card canvas{ width:100%; aspect-ratio:16/9; border-radius:4px; display:block; }
.template-card span{ font-size:10.5px; color:var(--ink-dim); text-align:center; line-height:1.3; }

/* ---------- キャンバス（自由編集ステージ） ---------- */
.stage-area{
  flex:3 1 320px; min-width:320px; display:flex; align-items:center; justify-content:center;
  min-height:60vh;
}
.canvas-col{
  display:flex; flex-direction:column; align-items:center; gap:10px;
  max-width:100%; max-height:100%;
}
.add-bar{
  display:flex; align-items:center; gap:8px; flex-wrap:wrap;
  width:100%; padding:8px 10px;
  background:var(--panel); border:1px solid var(--line); border-radius:8px;
}
.add-bar-sep{ width:1px; align-self:stretch; background:var(--line); margin:0 2px; }
.checkbox-row.inline{ margin-top:0; white-space:nowrap; }
.stage-wrap{
  background:var(--dark-2); border:1px solid var(--line); border-radius:8px;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.02), inset 0 1px 18px rgba(0,0,0,.35);
  padding:0; max-width:100%; max-height:100%;
  overflow:hidden;
  position:relative;
}
.stage{
  position:absolute; top:0; left:0; overflow:visible; background:#14181d;
  transform-origin:top left;
  border-radius:4px;
}
.stage.dragover{ outline:2px dashed var(--accent); outline-offset:-2px; }

.stage-item{
  position:absolute; box-sizing:border-box;
  cursor:move; user-select:none;
  display:flex; overflow:visible;
}
.stage-item.selected{ outline:2px solid var(--accent); outline-offset:1px; }
.stage-item img{ width:100%; height:100%; object-fit:cover; display:block; pointer-events:none; }
.frame-bg{ position:absolute; inset:0; z-index:0; pointer-events:none; filter:drop-shadow(0 3px 9px rgba(0,0,0,.32)); }
.underline-bar{ position:absolute; left:0; right:0; bottom:0; height:10%; z-index:0; display:none; pointer-events:none; }
.stage-item .text-inner{
  position:relative; z-index:1;
  width:100%; height:100%; display:flex; align-items:center;
  white-space:pre-wrap; word-break:break-word; outline:none;
  overflow:hidden;
}
.stage-item .text-inner.outlined{
  -webkit-text-stroke:0.06em #000;
  paint-order:stroke fill;
}
.stage-item.editing{ cursor:text; }
.stage-item.editing .text-inner{ cursor:text; user-select:text; }

.resize-handle{
  position:absolute; width:12px; height:12px; background:var(--accent);
  border:2px solid #fff; border-radius:50%; z-index:20;
  pointer-events:auto;
}
.delete-handle{
  position:absolute; top:-24px; left:50%; transform:translateX(-50%);
  width:22px; height:22px; border-radius:50%;
  background:var(--danger); color:#fff; border:2px solid #fff;
  display:flex; align-items:center; justify-content:center;
  font-size:14px; line-height:1; cursor:pointer; z-index:21;
  pointer-events:auto;
}
.resize-handle.nw{ top:-7px; left:-7px; cursor:nwse-resize; }
.resize-handle.ne{ top:-7px; right:-7px; cursor:nesw-resize; }
.resize-handle.sw{ bottom:-7px; left:-7px; cursor:nesw-resize; }
.resize-handle.se{ bottom:-7px; right:-7px; cursor:nwse-resize; }

/* ---------- ワイプ ---------- */
.wipe-mask{
  position:relative; width:100%; height:100%;
  overflow:hidden; box-sizing:border-box;
  border-style:solid; border-color:#ffffff; border-width:6px;
  background-color:transparent;
  background-image:
    linear-gradient(45deg,rgba(255,255,255,.08) 25%,transparent 25%),
    linear-gradient(-45deg,rgba(255,255,255,.08) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,rgba(255,255,255,.08) 75%),
    linear-gradient(-45deg,transparent 75%,rgba(255,255,255,.08) 75%);
  background-size:16px 16px;
  background-position:0 0,0 8px,8px -8px,-8px 0;
}
.wipe-mask.shape-circle{ border-radius:50%; }
.wipe-mask.shape-square{ border-radius:6px; }
.wipe-img{
  position:absolute; left:50%; top:50%;
  max-width:none; pointer-events:none;
  transform:translate(-50%,-50%);
}
.stage-item.grabbing .wipe-mask{ cursor:grabbing; }
.wipe-mask{ cursor:grab; }
.move-handle{
  position:absolute; top:-24px; left:-24px;
  width:22px; height:22px; border-radius:50%;
  background:var(--accent); color:var(--accent-ink); border:2px solid #fff;
  display:flex; align-items:center; justify-content:center;
  font-size:12px; line-height:1; cursor:move; z-index:21;
  pointer-events:auto;
}

/* ---------- 選択ハンドル用オーバーレイ（常に最前面） ---------- */
.selection-overlay{
  position:absolute; top:0; left:0;
  transform-origin:top left;
  pointer-events:none;
  z-index:1000;
}
.sel-frame{ position:absolute; box-sizing:border-box; pointer-events:none; }

.history-btns{ display:flex; gap:4px; }
.history-btns button{ width:32px; font-size:15px; padding:5px 0; }
.history-btns button:disabled{ opacity:.35; cursor:not-allowed; }
.history-btns button:disabled:hover{ border-color:var(--line); color:var(--muted); }

@media (max-width:850px){
  main{ flex-direction:column; }
  .stage-area{ order:-1; width:100%; min-height:0; min-width:0; }
  .col-tools, .col-props{ width:100%; max-width:none; min-width:0; flex:none; max-height:none; }
}

@media (max-width:640px){
  .topbar{ padding:10px 14px; }
  .toolbar{ gap:6px; }
  main{ padding:14px 12px; gap:12px; }
  .add-bar{ gap:6px; padding:6px 8px; }
}

.dl{ display:none; }
footer{
  text-align:center; color:var(--muted); font-size:11px; font-family:var(--mono);
  padding:20px; border-top:1px solid var(--line-soft);
}
.footer-copyright{ margin-top:6px; opacity:.7; font-size:10px; }
