:root {
  --cols: 4;
  --page: #e4e4e4;
  --hatch: rgba(255, 255, 255, 0.55);
  --panel: #ffffff;
  --card: #ffffff;
  --card-head: linear-gradient(#fff, #e9e9e9);
  --card-border: #cfcfcf;
  --text: #111;
  --muted: #666;
  --border: #c9c9c9;
  --band: #ffffc4;
  --band-up: #e9ffb8;
  --band-down: #ffe9dc;
  --grid: #e8e8d8;
  --chart-line: #0000ee;
  --pct: #0099ee;
  --accent: #1a6a1a;
  --up: #008000;
  --down: #cc0000;
  --flat: #666666;
  --danger: #cc0000;
  --fill-up: rgba(190, 235, 60, 0.38);
  --fill-dn: rgba(255, 150, 50, 0.38);
  --pill-hi: #dfffdf;
  --pill-lo: #ffdede;
  --pill-text: #222;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page: #14161a;
  --hatch: rgba(255, 255, 255, 0.03);
  --panel: #1c2027;
  --card: #1c2027;
  --card-head: linear-gradient(#2c313b, #20242c);
  --card-border: #343a46;
  --text: #eceef2;
  --muted: #9aa1b0;
  --border: #343a46;
  --band: #3b3a14;
  --band-up: #24391a;
  --band-down: #3d2519;
  --grid: #2b303a;
  --chart-line: #6aa6ff;
  --pct: #4cc3ff;
  --up: #3ddc5a;
  --down: #ff5a5a;
  --flat: #9aa1b0;
  --danger: #ff6b6b;
  --fill-up: rgba(120, 200, 60, 0.3);
  --fill-dn: rgba(255, 140, 50, 0.3);
  --pill-hi: #1f3d22;
  --pill-lo: #4a2323;
  --pill-text: #e6e6e6;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --page: #14161a;
    --hatch: rgba(255, 255, 255, 0.03);
    --panel: #1c2027;
    --card: #1c2027;
    --card-head: linear-gradient(#2c313b, #20242c);
    --card-border: #343a46;
    --text: #eceef2;
    --muted: #9aa1b0;
    --border: #343a46;
    --band: #3b3a14;
    --band-up: #24391a;
    --band-down: #3d2519;
    --grid: #2b303a;
    --chart-line: #6aa6ff;
    --pct: #4cc3ff;
    --up: #3ddc5a;
    --down: #ff5a5a;
    --flat: #9aa1b0;
    --danger: #ff6b6b;
    --fill-up: rgba(120, 200, 60, 0.3);
    --fill-dn: rgba(255, 140, 50, 0.3);
    --pill-hi: #1f3d22;
    --pill-lo: #4a2323;
    --pill-text: #e6e6e6;
    color-scheme: dark;
  }
}
:root[data-jp-color="1"] {
  --up: #cc0000;
  --down: #008000;
}
:root[data-jp-color="1"][data-theme="dark"] { --up: #ff5a5a; --down: #3ddc5a; }
@media (prefers-color-scheme: dark) {
  :root[data-jp-color="1"]:not([data-theme="light"]):not([data-theme="dark"]) { --up: #ff5a5a; --down: #3ddc5a; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page) repeating-linear-gradient(135deg, transparent 0 3px, var(--hatch) 3px 5px);
  color: var(--text);
  font-family: Meiryo, "メイリオ", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 14px 8px 24px; }

/* green glossy buttons (top bar) */
.btnbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.btn-gap { width: 18px; }
.gbtn {
  display: inline-block;
  padding: 9px 18px;
  min-height: 44px;
  border: 1px solid #0d3d0d;
  border-radius: 6px;
  background: linear-gradient(#4f9a4f 0%, #2f7a2f 48%, #145214 52%, #1f6b1f 100%);
  color: #fff;
  font-size: 17px;
  line-height: 1.4;
  text-decoration: none;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  cursor: pointer;
  white-space: nowrap;
}
.gbtn b { font-size: 26px; line-height: 1; padding: 0 2px; }
.gbtn:hover { filter: brightness(1.12); }
.gbtn:active { transform: translateY(1px); }
.gbtn.on { outline: 2px solid #ffe14d; outline-offset: -4px; }
.status { color: var(--muted); font-size: 12px; white-space: nowrap; }
.live { width: 10px; height: 10px; border-radius: 50%; background: #2fa84f; margin-left: auto; flex: none; opacity: 0.55; transition: opacity 0.2s; }
.live.busy { opacity: 1; animation: live-pulse 0.8s ease-in-out infinite; }
.live.fail { background: var(--danger); opacity: 1; }
@keyframes live-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.5); } }
@media (prefers-reduced-motion: reduce) { .live.busy { animation: none; } }

/* dark tab bar */
.tabs {
  display: flex; align-items: flex-end; gap: 2px;
  padding: 6px 6px 0;
  background: linear-gradient(#555, #222);
  border-bottom: 1px solid #000;
  box-shadow: 0 3px 4px rgba(0, 0, 0, 0.3);
  min-height: 52px;
}
.tabs .brand { color: #ddd; font-size: 14px; font-weight: 700; align-self: center; margin: 0 14px 4px 6px; white-space: nowrap; }
.tabs .status { align-self: center; margin: 0 8px 4px auto; color: #bbb; }
.tab {
  padding: 8px 16px 8px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(#4a4a4a, #171717);
  border: 1px solid #000;
  border-bottom: none;
  color: #fff;
  font-size: 17px;
  text-decoration: none;
  white-space: nowrap;
}
.tab:hover { filter: brightness(1.25); }
.tab.active { background: linear-gradient(#fff, #e4e4e4); color: #111; font-weight: 700; }

/* board */
.boardwrap { padding: 8px 0; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 8px;
}
.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  min-width: 0;
  transition: box-shadow 0.12s ease, transform 0.12s ease;
}
.card:hover { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.38); transform: translateY(-1px); z-index: 1; }

.card-head {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 6px 2px;
  background: var(--card-head);
  min-width: 0;
}
.badge {
  flex: none;
  min-width: 30px;
  padding: 1px 4px;
  border-radius: 3px;
  background: #2f5fa8;
  color: #fff;
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.3);
}
.card-name { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card-ex { flex: none; margin-left: auto; font-size: 10px; font-weight: 700; color: var(--muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-price {
  padding: 0 8px 0 10px;
  background: var(--band);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 0.3s;
}
.card-price .dec { font-size: 0.78em; }
.is-up .card-price { background: var(--band-up); }
.is-down .card-price { background: var(--band-down); }
.card.loading .card-price { opacity: 0.45; }

.chart { display: block; width: 100%; height: auto; }
.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-pct { stroke: #00c8ff; stroke-width: 1; }
.c-pctl { fill: var(--pct); font-size: 10px; }
.c-prev { stroke: #ee1111; stroke-width: 1.4; }
.c-line { fill: none; stroke: var(--chart-line); stroke-width: 1.4; stroke-linejoin: round; }
.c-fill-up { fill: var(--fill-up); }
.c-fill-dn { fill: var(--fill-dn); }
.c-last { fill: var(--card); stroke: var(--text); stroke-width: 1; }
.c-lbl { fill: var(--muted); font-size: 12px; }
.c-pill-hi rect { fill: var(--pill-hi); }
.c-pill-lo rect { fill: var(--pill-lo); }
.c-pill-hi text, .c-pill-lo text { fill: var(--pill-text); font-size: 12px; font-family: Tahoma, Arial, sans-serif; }

.card-foot { display: flex; align-items: baseline; justify-content: center; position: relative; padding: 0 6px 3px; }
.card-pct { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--flat); }
.pct-mark { font-size: 0.6em; margin-left: 1px; }
.is-up .card-pct { color: var(--up); }
.is-down .card-pct { color: var(--down); }
.card-fresh { display: flex; justify-content: center; gap: 6px; padding: 0 6px 2px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.card-state { font-weight: 700; white-space: nowrap; }
.card-fresh { flex-wrap: wrap; }
.card-time { text-align: center; }
.card-time.late { color: var(--danger); font-weight: 700; }
.card-state.st-regular { color: var(--up); }
.card-state.st-pre, .card-state.st-post { color: #b8860b; }
.card-state.st-closed { color: var(--muted); }
.card-ranges { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 3px 6px 6px; }
.rng {
  min-width: 24px; min-height: 28px; padding: 0 2px;
  font-size: 13px; font-weight: 700; line-height: 1; white-space: nowrap;
  border: 1.5px solid var(--accent); border-radius: 5px;
  background: var(--card); color: var(--accent); cursor: pointer;
}
.rng:hover { filter: brightness(0.92); }
.rng.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.c-axis { fill: var(--muted); font-size: 9px; }
.card-src { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 0 6px 6px; }
.srcbtn {
  min-height: 24px; padding: 0 2px; font-size: 12px; font-weight: 700; line-height: 1; white-space: nowrap;
  border: 1.5px solid #b8860b; border-radius: 5px; background: var(--card); color: #8a6508; cursor: pointer;
}
.srcbtn.on { background: #b8860b; border-color: #b8860b; color: #fff; }
:root[data-theme="dark"] .srcbtn { color: #e6c15a; border-color: #e6c15a; }
:root[data-theme="dark"] .srcbtn.on { background: #8a6508; border-color: #8a6508; color: #fff; }
.c-now { stroke: var(--chart-line); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
.status.err { color: var(--danger); font-weight: 700; }
:root[data-theme="dark"] .rng { color: #8fd68f; border-color: #8fd68f; }
:root[data-theme="dark"] .rng.on { background: #2f7a2f; border-color: #2f7a2f; color: #fff; }
.card-error { padding: 4px 8px 8px; color: var(--danger); font-size: 12px; }

/* 値が動いた時の点滅 */
@keyframes flash-up { 0% { box-shadow: inset 0 0 0 3px var(--up), 0 1px 3px rgba(0,0,0,.25); } 100% { box-shadow: inset 0 0 0 0 transparent, 0 1px 3px rgba(0,0,0,.25); } }
@keyframes flash-down { 0% { box-shadow: inset 0 0 0 3px var(--down), 0 1px 3px rgba(0,0,0,.25); } 100% { box-shadow: inset 0 0 0 0 transparent, 0 1px 3px rgba(0,0,0,.25); } }
.card.flash-up { animation: flash-up 1.2s ease-out 2; }
.card.flash-down { animation: flash-down 1.2s ease-out 2; }
@media (prefers-reduced-motion: reduce) { .card.flash-up, .card.flash-down { animation: none; } }

/* 6列: 少し縮めて価格・ボタンが潰れないようにする */
:root[style*="--cols: 6"] .card-name { font-size: 15px; }
:root[style*="--cols: 6"] .card-price { font-size: 27px; }
:root[style*="--cols: 6"] .card-pct { font-size: 22px; }
:root[style*="--cols: 6"] .rng { font-size: 12px; }
:root[style*="--cols: 6"] .card-fresh { font-size: 10px; flex-wrap: wrap; gap: 0 4px; }
/* 列数が多い時は文字を縮める */
:root[style*="--cols: 9"] .card-name,
:root[style*="--cols: 8"] .card-name,
:root[style*="--cols: 7"] .card-name { font-size: 12px; }
:root[style*="--cols: 9"] .card-price,
:root[style*="--cols: 8"] .card-price,
:root[style*="--cols: 7"] .card-price { font-size: 20px; }
:root[style*="--cols: 9"] .card-pct,
:root[style*="--cols: 8"] .card-pct,
:root[style*="--cols: 7"] .card-pct { font-size: 17px; }
:root[style*="--cols: 9"] .badge,
:root[style*="--cols: 9"] .card-ex,
:root[style*="--cols: 8"] .badge,
:root[style*="--cols: 8"] .card-ex { display: none; }
:root[style*="--cols: 9"] .card-fresh,
:root[style*="--cols: 8"] .card-fresh { font-size: 9px; gap: 3px; }
:root[style*="--cols: 9"] .rng,
:root[style*="--cols: 8"] .rng { font-size: 11px; min-height: 24px; }
:root[style*="--cols: 9"] .card-ranges,
:root[style*="--cols: 8"] .card-ranges { gap: 2px; padding: 2px 3px 4px; }

.foot { padding: 12px 8px 4px; color: var(--muted); font-size: 11px; text-align: center; }

/* fullscreen: カードだけ */
body.fullscreen .btnbar .gbtn:not(#btn-fullscreen):not(.col-btn),
body.fullscreen .tabs,
body.fullscreen .foot { display: none; }
body.fullscreen .wrap { max-width: none; padding: 8px; }

/* ---------- edit page ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-top: none; padding: 14px 16px 20px; }
.sec { padding: 10px 0 14px; border-bottom: 1px solid var(--border); }
.sec:last-of-type { border-bottom: none; }
.sec h2 { margin: 0 0 10px; font-size: 16px; }
.sec h2 small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.note { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.setting { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.setting select, .btn {
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
}
.btn { cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(0.96); }
.btn-danger { color: var(--danger); }

.search { position: relative; max-width: 640px; }
.search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  outline: none;
  font-size: 16px;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31, 107, 31, 0.25); }
.search-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  max-height: 60vh; overflow-y: auto; z-index: 30;
}
.search-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.search-list li[aria-selected="true"], .search-list li:hover { background: rgba(128, 128, 128, 0.18); }
.search-list li.disabled { opacity: 0.5; cursor: default; }
.search-list .s-symbol { font-weight: 700; min-width: 90px; font-variant-numeric: tabular-nums; }
.search-list .s-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-list .s-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.search-list .s-empty { color: var(--muted); cursor: default; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
}
.item.dragging { opacity: 0.4; }
.item.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31, 107, 31, 0.3); }
.grip { color: var(--muted); letter-spacing: -2px; user-select: none; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tools { display: flex; gap: 2px; }
.icon-btn {
  width: 32px; height: 32px; padding: 0;
  border-radius: 6px; border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover:not(:disabled) { border-color: var(--border); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.remove:hover { color: var(--danger); }

/* ---------- phone ---------- */
@media (max-width: 640px) {
  .wrap { padding: 8px 4px 20px; }
  .gbtn { padding: 6px 10px; min-height: 40px; font-size: 14px; }
  .btn-gap, .col-btn { display: none; }
  .tabs .brand { display: none; }
  .tab { font-size: 15px; padding: 7px 12px; }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .board .card-name { font-size: 15px !important; }
  .board .card-price { font-size: 26px !important; }
  .board .card-pct { font-size: 22px !important; }
  .card-ex { display: none !important; }
  .card-fresh { font-size: 10px; flex-wrap: wrap; gap: 0 4px; }
  .panel { padding: 10px 10px 16px; }
}
