/* ダークテーマ（Material Design のダークテーマの考え方：純黒を避け、面の高さで明度を上げ、文字は不透明度で階層化） */
:root {
  --bg: #131722;
  --surface: #1c2030;
  --surface-2: #252a3b;
  --border: #2e3446;
  --text: rgba(255,255,255,.87);
  --text-2: rgba(255,255,255,.60);
  --accent: #4c8dff;
  --up: #26a69a;
  --down: #ef5350;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 13px; }
body { display: flex; flex-direction: column; overflow: hidden; }
button {
  font: inherit; color: var(--text); background: transparent; border: 1px solid transparent;
  border-radius: 6px; padding: 6px 10px; min-height: 32px; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.active, button[aria-pressed="true"] { background: var(--surface-2); color: var(--accent); border-color: var(--border); }

.toolbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 10px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex: none;
}
.search { position: relative; }
.search input {
  width: 280px; height: 32px; padding: 0 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.suggest {
  position: absolute; top: 36px; left: 0; z-index: 20; width: 380px; margin: 0; padding: 4px 0;
  list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.suggest li { display: flex; gap: 10px; padding: 8px 12px; cursor: pointer; }
.suggest li.sel, .suggest li:hover { background: var(--border); }
.suggest .sym { font-weight: 600; min-width: 72px; }
.suggest .nm { flex: 1; color: var(--text-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.suggest .ex { color: var(--text-2); font-size: 11px; }
.intervals { display: flex; gap: 2px; }
.status { margin-left: auto; color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 1100px) { .search input { width: 200px; } .watchlist { width: 220px; } }

.layout { flex: 1; display: flex; min-height: 0; }
.chart-wrap { position: relative; flex: 1; min-width: 0; }
#chart { position: absolute; inset: 0; }
/* 描画ツールのカーソル形（チャート内部の要素より優先させる） */
#chart.c-draw, #chart.c-draw * { cursor: crosshair !important; }
#chart.c-move, #chart.c-move * { cursor: move !important; }
#chart.c-ns, #chart.c-ns * { cursor: ns-resize !important; }
#chart.c-ew, #chart.c-ew * { cursor: ew-resize !important; }
.legend {
  position: absolute; top: 8px; left: 10px; z-index: 5; pointer-events: none;
  line-height: 1.6; font-variant-numeric: tabular-nums; text-shadow: 0 0 4px var(--bg);
}
.legend .title { font-size: 15px; font-weight: 600; }
.legend .title small { font-weight: 400; color: var(--text-2); margin-left: 6px; }
.legend .ohlc span { margin-right: 10px; }
.legend .lbl { color: var(--text-2); margin-right: 2px; }
.up { color: var(--up); } .down { color: var(--down); }
.msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-2); font-size: 14px; background: rgba(19,23,34,.6); z-index: 6;
}

.watchlist {
  width: 260px; flex: none; background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.wl-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--border); }
.wl-head h2 { font-size: 13px; font-weight: 600; margin: 0; }
#wl { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#wl li {
  display: grid; grid-template-columns: 1fr auto 24px; align-items: center; gap: 6px;
  padding: 8px 6px 8px 12px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.04);
}
#wl li:hover { background: var(--surface-2); }
#wl li.current { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
#wl .s { font-weight: 600; }
#wl .n { color: var(--text-2); font-size: 11px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#wl .p { text-align: right; font-variant-numeric: tabular-nums; }
#wl .c { font-size: 11px; }
#wl .rm { min-height: 24px; padding: 0; width: 24px; color: var(--text-2); visibility: hidden; }
#wl li:hover .rm { visibility: visible; }

[hidden] { display: none !important; }

/* 左の描画ツールバー */
.drawbar {
  width: 48px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  background: var(--surface); border-right: 1px solid var(--border);
}
.drawbar button { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; }
.drawbar svg { width: 22px; height: 22px; fill: var(--text); }
.drawbar svg .st { fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.drawbar svg .g { fill: rgba(38,166,154,.55); }
.drawbar svg .r { fill: rgba(239,83,80,.55); }
.drawbar button.active svg { fill: var(--accent); }
.drawbar button.active svg .st { stroke: var(--accent); }
.drawbar hr { width: 28px; border: none; border-top: 1px solid var(--border); margin: 6px 0; }

/* ウォッチリストの並び替え */
#wl li[draggable="true"] { cursor: grab; }
#wl li.dragging { opacity: .4; }
#wl li.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
#wl li.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.credit { margin: 0; padding: 8px 12px; font-size: 10px; color: var(--text-2); border-top: 1px solid var(--border); }
.credit a { color: var(--text-2); }

/* 決算・権利付最終日 */
.legend .events:empty { display: none; }
.legend .events > span:not(.ev) { margin-right: 10px; }
.legend .events { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.legend .ev {
  display: inline-grid; place-items: center; width: 16px; height: 16px; margin: 0 4px 0 0;
  border-radius: 50%; font-size: 10px; font-weight: 700; color: #131722; vertical-align: -3px;
}
.legend .ev.e { background: #f5a623; }
.legend .ev.k { background: #42a5f5; border-radius: 3px; }
.legend .events .ev ~ .ev { margin-left: 12px; }

/* 取得単価ボタンのアイコン */
.drawbar svg .st.thick { stroke-width: 3.2; }

/* ウォッチリストのタブ（日本株／米国株） */
.wl-head > div { display: flex; gap: 4px; }
.wl-tabs { display: flex; border-bottom: 1px solid var(--border); }
.wl-tabs button {
  flex: 1; min-height: 36px; border-radius: 0; background: none; color: var(--text-2);
  box-shadow: inset 0 -2px 0 transparent;
}
.wl-tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.wl-tabs button span { font-size: 11px; color: var(--text-2); margin-left: 2px; }

/* 操作のヒント（描画ツールを選んだとき、チャートの下に出す） */
.hint {
  position: absolute; left: 50%; bottom: 36px; transform: translateX(-50%); z-index: 7; pointer-events: none;
  max-width: calc(100% - 24px); padding: 6px 12px; border-radius: 16px; font-size: 12px; white-space: nowrap;
  background: rgba(76,141,255,.92); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.tabbar { display: none; }

/* ---------- スマホ（幅700px以下） ----------
   Material Design の Bottom navigation（下のタブ）と、Apple HIG の「タップ領域は44pt以上」に合わせる */
@media (max-width: 700px) {
  html, body { font-size: 14px; }
  body { height: 100dvh; }

  .toolbar { gap: 6px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
  .search { flex: 1; min-width: 0; }
  .search input { width: 100%; height: 40px; font-size: 16px; /* 16px未満だとiPhoneが入力時に拡大する */ }
  .suggest { width: calc(100vw - 16px); top: 44px; }
  .suggest li { padding: 12px; }
  .intervals { gap: 0; }
  .intervals button { min-height: 40px; padding: 0 10px; }
  #btn-fit, .status { display: none; }

  .layout { flex-direction: column; }
  .chart-wrap { flex: 1; min-height: 0; }

  /* 描画ツールは、チャートの下の横長のバー（横にスクロールできる） */
  .drawbar {
    order: 2; width: auto; height: 52px; flex-direction: row; align-items: center; gap: 2px; padding: 4px 6px;
    overflow-x: auto; border-right: none; border-top: 1px solid var(--border); -webkit-overflow-scrolling: touch;
  }
  .drawbar button { width: 44px; height: 44px; flex: none; }
  .drawbar hr { width: 0; height: 28px; border: none; border-left: 1px solid var(--border); margin: 0 6px; flex: none; }

  /* 凡例は小さく。決算の次回予定は、印のある足を触ったときだけ見る */
  .legend { top: 4px; font-size: 11px; line-height: 1.45; max-width: calc(100% - 90px); }
  .legend .title { font-size: 13px; }
  .legend .title small { display: block; margin: 0; font-size: 11px; }
  .legend .ohlc span { margin-right: 6px; }
  .legend .events.next { display: none; }

  /* ウォッチリストは全画面（下のタブで切り替え） */
  .watchlist {
    position: fixed; inset: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 30; width: auto;
    border-left: none; display: none;
  }
  body.show-wl .watchlist { display: flex; }
  .wl-head { padding: 8px 8px 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); }
  .wl-head h2 { font-size: 16px; }
  .wl-head button { min-height: 40px; }
  .wl-tabs button { min-height: 44px; font-size: 14px; }
  #wl li { grid-template-columns: 1fr auto 40px; padding: 12px 4px 12px 14px; }
  #wl .s { font-size: 16px; }
  #wl .n { font-size: 12px; }
  #wl .p { font-size: 15px; }
  #wl .c { font-size: 12px; }
  #wl .rm { visibility: visible; width: 40px; min-height: 40px; font-size: 18px; }
  .credit { padding: 8px 14px; }

  /* 下のタブ */
  .tabbar {
    display: flex; flex: none; height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); position: relative; z-index: 31;
  }
  .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: none; border-radius: 0; font-size: 11px; color: var(--text-2); min-height: 56px;
  }
  .tabbar button svg { width: 24px; height: 24px; }
  .tabbar button svg .st { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar button[aria-pressed="true"] { color: var(--accent); background: none; border: none; }
  .hint { bottom: 12px; }
}
