/* graph.css — 高精度グラフ計算機 */

/* ===== CSS変数 ===== */
:root {
  --blue: #3b82f6;
  --blue-dk: #2563eb;
  --text: #1e293b;
  --text-sub: #64748b;
  --text-dim: #94a3b8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --border: #e2e8f0;
  --radius: 10px;
  --panel-w: 320px;
  --header-h: 52px;
  --font: "Noto Sans JP","Hiragino Kaku Gothic ProN",Meiryo,sans-serif;
  min-height: 0;
}

html[data-theme="dark"] {
  --text: #e2e8f0;
  --text-sub: #94a3b8;
  --text-dim: #475569;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #0f172a;
  --border: #334155;
}

/* ===== リセット ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  user-select: none;
}

/* グラデーション背景を無効化（このツールでは不要） */
body::before { display: none !important; }

/* ===== アプリ全体 ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ===== ヘッダー ===== */
.graph-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.backmenu-button {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sub);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.backmenu-button:hover { background: var(--surface2); color: var(--text); }
.backmenu-button svg { width: 16px; height: 16px; flex-shrink: 0; }

.header-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== ワークスペース ===== */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
}

/* ===== サイドパネル ===== */
.side-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* モバイル */
@media (max-width: 639px) {
  .workspace { flex-direction: column; }
  .side-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }
  .side-panel.panel-open {
    max-height: 55vh;
    overflow-y: auto;
  }
}

/* ===== パネルセクション ===== */
.p-section {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.p-section:last-child { border-bottom: none; }

.p-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.p-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.p-section-hint {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0;
}

.p-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--text-sub);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.p-add-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.p-add-btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.p-add-btn svg { width: 14px; height: 14px; }

/* ===== 関数リスト ===== */
.func-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* ===== 関数行 ===== */
.func-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.4rem;
  transition: border-color 0.15s;
}
.func-row:focus-within { border-color: var(--blue); }
.func-row.error { border-color: #f87171; }
.func-row.disabled { opacity: 0.4; }

.func-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.func-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font-size: 0.86rem;
  font-family: 'Courier New', Courier, monospace;
  color: var(--text);
  outline: none;
  user-select: text;
}
.func-input::placeholder { color: var(--text-dim); font-size: 0.76rem; }

.func-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-sub);
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.func-icon-btn:hover { background: var(--border); color: var(--text); }
.func-icon-btn svg { width: 15px; height: 15px; }

.func-error-footer {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0.15rem 0.1rem 0;
  gap: 0.4rem;
}
.func-row.error .func-error-footer { display: flex; }

.func-error-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #ef4444;
}

.copy-fix-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border: 1.5px solid #ef4444;
  border-radius: 5px;
  background: none;
  color: #ef4444;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
  white-space: nowrap;
}
.copy-fix-btn:hover { background: rgba(239,68,68,0.08); }
.copy-fix-btn.copied { border-color: #22c55e; color: #22c55e; }
.copy-fix-btn.copied:hover { background: rgba(34,197,94,0.08); }
.copy-fix-btn svg { width: 11px; height: 11px; flex-shrink: 0; }

/* ===== パラメータスライダー ===== */
.param-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.param-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface2);
  border-radius: 7px;
}

.param-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.param-name {
  font-family: 'Courier New', Courier, monospace;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--blue);
  width: 14px;
}

.param-value {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  color: var(--text-sub);
  min-width: 40px;
  text-align: right;
}

.param-slider {
  width: 100%;
  accent-color: var(--blue);
  height: 4px;
  cursor: pointer;
}

/* ===== 設定（範囲・トグル） ===== */
.range-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.range-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sub);
  width: 14px;
  flex-shrink: 0;
}
.range-input {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0.4rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.82rem;
  font-family: 'Courier New', Courier, monospace;
  outline: none;
  text-align: center;
  user-select: text;
}
.range-input:focus { border-color: var(--blue); }
.range-sep {
  font-size: 0.78rem;
  color: var(--text-sub);
  flex-shrink: 0;
}
.p-apply-btn {
  width: 100%;
  padding: 0.4rem;
  border: none;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s;
}
.p-apply-btn:hover { opacity: 0.85; }

/* ===== トグルスイッチ ===== */
.sw-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}
.sw-input { display: none; }
.sw-track {
  position: relative;
  width: 34px;
  height: 18px;
  background: var(--border);
  border-radius: 9px;
  flex-shrink: 0;
  transition: background 0.2s;
}
.sw-input:checked + .sw-track { background: var(--blue); }
.sw-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.sw-input:checked + .sw-track .sw-thumb { transform: translateX(16px); }
.sw-label {
  font-size: 0.82rem;
  color: var(--text-sub);
}

/* ===== 記法ガイド（details） ===== */
.p-section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}
.p-section-summary::-webkit-details-marker { display: none; }

.p-summary-arrow {
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  transition: transform 0.2s;
  flex-shrink: 0;
}
details[open] .p-summary-arrow { transform: rotate(180deg); }

.guide-table {
  margin-top: 0.4rem;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
}
.guide-table tr { border-bottom: 1px solid var(--border); }
.guide-table tr:last-child { border-bottom: none; }
.guide-table td { padding: 0.22rem 0.25rem; color: var(--text-sub); vertical-align: middle; }
.guide-expr {
  font-family: 'Courier New', Courier, monospace;
  color: var(--blue) !important;
  white-space: nowrap;
  width: 1%;
  padding-right: 0.6rem !important;
}

/* ===== グラフエリア ===== */
.graph-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
}

#graph-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ===== モバイル用パネルトグル ===== */
.panel-toggle {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-sub);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  z-index: 5;
  transition: background 0.15s;
}
.panel-toggle:hover { background: var(--surface2); }
.panel-toggle svg { width: 18px; height: 18px; }

@media (max-width: 639px) {
  .panel-toggle { display: flex; }
}

/* ===== トレースポップアップ ===== */
.trace-popup {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.3rem 0.6rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  font-size: 0.76rem;
  font-family: 'Courier New', Courier, monospace;
  white-space: nowrap;
  display: none;
  z-index: 5;
  line-height: 1.55;
}
.trace-popup.visible { display: block; }

/* ===== 座標バー ===== */
.coord-bar {
  position: absolute;
  bottom: 0.5rem;
  left: 0.6rem;
  font-size: 0.72rem;
  font-family: 'Courier New', Courier, monospace;
  color: var(--text-sub);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.18rem 0.5rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 5;
}
.coord-bar.visible { opacity: 1; }

/* ===== ズームパネル ===== */
.zoom-panel {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  z-index: 5;
}

.zoom-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-sub);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: background 0.15s, color 0.15s;
}
.zoom-btn:hover { background: var(--surface2); color: var(--text); }
.zoom-btn svg { width: 16px; height: 16px; }

.zoom-level {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-sub);
  padding: 0.1rem 0;
}

/* ===== ダークモード細調整 ===== */
html[data-theme="dark"] .range-input { background: #0f172a; }
html[data-theme="dark"] .func-row { background: #0f172a; }
html[data-theme="dark"] .param-item { background: #0f172a; }

/* ===== 軽量モード ===== */
html[data-performance="low"] * { transition: none !important; animation: none !important; }
