:root {
  --bg: #0b0f14;
  --panel: #121822;
  --ink: #ffffff;
  --muted: #c8d1de;
  --grid: #1f2734;
  --accent: #5ee1ff;
  --selbg: #103347;
  --sellight: #6fe1ff;
  --stick-top: 86px;
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font: 16px/1.7 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #0c121aee;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--grid)
}

.wrap {
  max-width: 96vw;
  margin: 0 auto;
  padding: 16px
}

h1 {
  margin: 0 0 6px;
  font-size: 26px
}

.lead {
  color: #a9b9cf;
  font-size: 14px
}

.panel {
  background: #121822;
  border: 1px solid var(--grid);
  border-radius: 16px;
  padding: 18px;
  margin: 18px 0
}

.step {
  font-weight: 700;
  font-size: 18px;
  margin: 0 0 12px
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid #2a3242;
  background: linear-gradient(180deg, #1a2331, #151c27);
  color: #eaf6ff
}

.btn.primary {
  background: linear-gradient(180deg, #1f2d3c, #182331)
}

.btn.good {
  background: linear-gradient(180deg, #1f2f24, #19251f)
}

.btn.warn {
  background: linear-gradient(180deg, #3a2b26, #2a1e1a)
}

.btn:disabled {
  opacity: .6;
  cursor: not-allowed
}

input[type=file],
textarea,
input[type=text],
input[type=number],
input[type=month],
input[type=date],
input[type=range],
select {
  width: 100%;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #2a3646;
  background: #0e141d;
  color: #eaf6ff;
}

textarea {
  min-height: 110px;
  font-family: ui-monospace, Consolas, Menlo, monospace
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px
}

@media (max-width:900px) {
  .row {
    grid-template-columns: 1fr
  }
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px
}

@media (max-width:900px) {
  .kpis {
    grid-template-columns: repeat(2, 1fr)
  }
}

.kpi {
  background: #0f1520;
  border: 1px solid #223047;
  border-radius: 12px;
  padding: 10px
}

.kpi h3 {
  margin: 0;
  font-size: 22px
}

.kpi p {
  margin: 6px 0 0;
  color: #a9b9cf;
  font-size: 12px
}

.grid2 {
  display: grid;
  grid-template-columns: 50vw minmax(0, 1fr);
  gap: 12px;
  align-items: start
}

@media (max-width:1100px) {
  .grid2 {
    grid-template-columns: 1fr
  }
}

.grid2even {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start
}

@media (max-width:1100px) {
  .grid2even {
    grid-template-columns: 1fr
  }
}

.grid2>aside {
  position: sticky;
  top: var(--stick-top);
  max-height: calc(100vh - var(--stick-top) - 16px);
  overflow: auto
}

/* 3-column grid layout for co-occurrence tables */
.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  align-items: start;
}
@media (max-width: 1100px) {
  .grid3 {
    grid-template-columns: 1fr;
  }
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 10px
}

.card {
  background: #0f1520;
  border: 1px solid #223047;
  border-radius: 12px;
  padding: 10px
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 6px 0 10px
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #2a3c54;
  border-radius: 999px;
  background: #0f1722;
  color: #cfe7ff;
  font-size: 12px
}

/* ================================================
   ナビゲーション用の pill ボタンを見やすく調整
   nav 要素内の .pill は各ページへのリンクであり、
   PC でもスマホでも押しやすいように一回り大きくする。
   この指定は他の pill には影響しません。  */
nav .pill {
  font-size: 25px;
  padding: 10px 16px;
}

.muted {
  color: #c8d1de
}

/* ===== グラフスクロール領域：下に“物理余白”を確保 ===== */
.scroller {
  width: min(50vw, 100%);
  max-width: 50vw;
  height: 340px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid #223047;
  border-radius: 10px;
  background: #0e131c;
  user-select: none;
  cursor: grab;
  /* Remove bottom padding since vertical centering will handle spacing */
  /* padding-bottom removed */
  /* Center the canvas vertically within the scroller */
  /* Removed flexbox layout as requested */
  /* Provide symmetric top and bottom padding of 30px (10px + additional 20px) */
  padding-top: 30px;
  padding-bottom: 30px;
  /* Add 30px right padding for extra space on the right */
  padding-right: 30px;
  /* ← スクロールバーのさらに下に余白 */
  scrollbar-gutter: stable both-edges;
}

.scroller:active {
  cursor: grabbing
}

.scroller-full {
  width: 100%;
  max-width: 100%
}

.scroller canvas {
  /* Remove bottom margin and use flex alignment to center the canvas vertically */
  margin: 0;
}

/* ← 目盛ラベルの逃げ（下） */
canvas {
  display: block;
  /* Reduce canvas height to accommodate 30px top and bottom padding in the scroller (340px total height) */
  height: 280px
}

.tablewrap {
  overflow: auto;
  border: 1px solid #223047;
  border-radius: 10px
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 560px
}

thead th {
  position: sticky;
  top: 0;
  background: #0f1520;
  z-index: 1;
  cursor: pointer
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px dashed #223047;
  text-align: left;
  font-size: 13px
}

tbody tr:nth-child(even) {
  background: #0b1018
}

#tooltip {
  position: fixed;
  pointer-events: none;
  background: #0f1722;
  border: 1px solid #2a3c54;
  color: #eaf6ff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
  z-index: 9999;
  max-width: 56ch;
  box-shadow: 0 6px 18px #0007
}

/* ===== カレンダー ===== */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  background: #0e131c;
  border: 1px solid #223047;
  border-radius: 10px;
  padding: 8px
}

.cal-head {
  color: #a9b9cf;
  text-align: center;
  font-size: 12px
}

.day {
  min-height: 70px;
  border: 1px solid #1f2734;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  position: relative;
  background: #0b1018;
  transition: box-shadow .12s ease, background .12s ease, transform .06s ease
}

.day.has {
  outline: 2px solid #3bb3ff
}

.day .num {
  position: absolute;
  right: 6px;
  top: 4px;
  font-size: 12px;
  color: #c8d1de
}

.day .badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 11px;
  background: #1e2b3f;
  padding: 2px 6px;
  border-radius: 999px
}

.day.selected {
  background: var(--selbg);
  border-color: var(--sellight);
  outline: 3px solid var(--sellight);
  box-shadow: 0 0 0 3px #000 inset, 0 0 14px 2px rgba(111, 225, 255, .45)
}

.day.selected .num {
  color: #fff;
  font-weight: 700
}

/* 新しいカレンダーセグメント（複数配信日に対応） */
/* Segments representing multiple streams on a single day. Each segment is a
   rounded rectangle that can be clicked individually. */
.day .cal-segment {
  /* Highlight multiple-stream segments with only a light-blue border and no fill */
  background: transparent;
  color: #c8d1de;
  font-size: 11px;
  padding: 2px 6px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border-radius: 6px;
  border: 1px solid #3bb3ff;
  box-sizing: border-box;
}
/* 日付数字はクリックを透過させる */
.day .num {
  pointer-events: none;
}

.day:active {
  transform: scale(.995)
}

#busy {
  position: fixed;
  inset: 0;
  background: #0009;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  color: #eaf6ff;
  flex-direction: column;
  gap: 12px
}

#busy.show {
  display: flex
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #2a3c54;
  border-top-color: #5ee1ff;
  border-radius: 50%;
  animation: spin 1s linear infinite
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

#statusBox {
  white-space: pre-line;
  font-size: 12px;
  background: #0f1520;
  border: 1px solid #223047;
  padding: 8px;
  border-radius: 10px;
  height: 72px;
  overflow: auto
}

/* ===== セトリの尤度・驚き度＋予測 ===== */
.grid-lk {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto auto;
  gap: 12px;
  grid-template-areas:
    "builder breakdown"
    "builder next"
    "routine clicked";
}

#lkBuilderCard {
  grid-area: builder
}

#lkBreakCard {
  grid-area: breakdown
}

#lkNextCard {
  grid-area: next
}

#lkRoutineCard {
  grid-area: routine
}

#lkClickedCard {
  grid-area: clicked
}

/* 入力ビルダー */
.builder .b-controls {
  display: flex;
  gap: 6px;
  margin: 0 0 8px
}

.builder .rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px dashed #2a3c54;
  border-radius: 10px;
  background: #0b1018;
  padding: 8px;
  max-height: 420px;
  overflow: auto
}

.builder .row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  position: relative
}

/* サジェストを viewport 固定で最前面に。親の overflow に裁断されない */
.sugg {
  position: fixed;
  /* ← ここがキモ */
  left: 0;
  top: 0;
  /* JSで座標を都度上書き */
  z-index: 10000;
  max-height: 220px;
  overflow: auto;
  background: #0f1722;
  border: 1px solid #2a3c54;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .4);
}

.sugg .item {
  padding: 8px 10px;
  cursor: pointer;
}

.sugg .item:hover {
  background: #102235;
}


/* ==== ここから：インラインstyleの置き換え（見た目不変） ==== */
#data details {
  margin-top: 8px;
}

#data summary {
  cursor: pointer;
}

/* カレンダーパネル内で、カレンダーの入った最初のカードだけ padding:8px */
#calGrid>.cards>.card:first-child {
  padding: 8px;
}

/* latest セクション内 */
#latestLikeBreakdown {
  margin-top: 10px;
}

#latest aside h3:nth-of-type(2) {
  margin-top: 12px;
}

#latest>.cards {
  margin-top: 10px;
}

/* 入力幅（元の style="width:..." の再現） */
#barWidth {
  width: 180px;
}

#topNCount,
#topNRecent {
  width: 80px;
}

#halfLife {
  width: 90px;
}

#calJump {
  width: 150px;
}

#predBaseDate {
  width: 160px;
}

#latestSimK {
  width: 80px;
}

#coTopN {
  width: 80px;
}

#coMin {
  width: 90px;
}

#coDetails .controls {
  margin-top: 0;
}

#coSongQ {
  width: 220px;
}

#propS {
  width: 70px;
}

#propBeta {
  width: 80px;
}

#propK {
  width: 80px;
}

#propG,
#propHL {
  width: 90px;
}

#propRand {
  width: 80px;
}

#revMinCount,
#revLimit {
  width: 90px;
}

#propDetails {
  margin-top: 10px;
}

#lkInputTable {
  margin-bottom: 10px;
}

#weekdayTable {
  margin-top: 10px;
}

#lkDiscount,
#lkAlpha {
  width: 90px;
}

#lkAWrap {
  display: none;
}

#routineTopN {
  width: 90px;
}

/* iOS Safari 落ち対策：sticky×backdrop-filterを無効化 */
@supports (-webkit-touch-callout: none) {
  header {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: #0c121a; /* 透過やめて不透明に */
  }
}

