:root {
  /* 深緑基調 */
  --bg: #081209;
  --panel: #0D1B10;
  --panel-2: #122616;
  --line: #1E3B26;
  --line-soft: #172E1D;
  --accent: #46E08C;
  --accent-deep: #177A4A;
  --ink: #E2F1E6;
  --muted: #7E9C88;
  --red: #FF6470;
  --amber: #EFAF3E;
  --blue: #5FA8F5;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --jp: 'Zen Kaku Gothic New', system-ui, -apple-system, 'Hiragino Kaku Gothic ProN', sans-serif;

  --r: 4px;
}

* { box-sizing: border-box; }

/* .gate や .overlay は display を指定しているため、
   これが無いと hidden 属性が効かず出しっぱなしになる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--jp);
  font-size: 15px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(70rem 40rem at 15% -10%, rgba(70, 224, 140, .07), transparent 60%),
    radial-gradient(50rem 30rem at 110% 10%, rgba(70, 224, 140, .04), transparent 60%);
  z-index: 0;
}

h1, h2 { font-weight: 900; letter-spacing: .02em; margin: 0; }

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .32em;
  color: var(--accent);
  margin: 0 0 18px;
  text-transform: uppercase;
}

/* ── 合言葉ゲート ─────────────────────────────── */

.gate {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.gate__inner { width: 100%; max-width: 470px; }

.gate__title { font-size: clamp(24px, 6vw, 34px); line-height: 1.35; }

.gate__lead {
  color: var(--muted);
  font-size: 14px;
  margin: 12px 0 30px;
}

.gate__form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px;
}

.gate__error {
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
}

.gate__line {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--muted);
}

.gate__line b { color: var(--accent); font-weight: 700; }
.gate__line p { margin: 0 0 14px; }

/* ── 共通パーツ ─────────────────────────────── */

.field { display: block; margin-bottom: 14px; }

.field__label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

input[type=text], input[type=number], select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  padding: 10px 12px;
  appearance: none;
}

select {
  font-family: var(--jp);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus, select:focus { border-color: var(--accent-deep); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--ink);
  font-family: var(--jp);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.btn:hover { border-color: var(--accent-deep); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04170C;
}
.btn--primary:hover { background: #63EBA1; border-color: #63EBA1; }

.btn--line { background: transparent; border-color: var(--line); color: var(--accent); }

.btn--ghost {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-weight: 500;
}
.btn--ghost:hover { color: var(--accent); }
.btn--ghost:disabled { opacity: .35; cursor: not-allowed; }

.btn--run {
  background: var(--accent);
  border-color: var(--accent);
  color: #04170C;
  font-size: 15px;
  padding: 16px;
  letter-spacing: .04em;
}
.btn--run:hover { background: #63EBA1; border-color: #63EBA1; }
.btn--run:disabled { opacity: .4; cursor: not-allowed; }

.hint { color: var(--muted); font-size: 12px; line-height: 1.65; margin: 12px 0 0; }
.empty { color: var(--muted); font-size: 13px; margin: 0; grid-column: 1 / -1; background: var(--panel); padding: 4px 0; }

/* ── レイアウト ─────────────────────────────── */

.app { position: relative; z-index: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 18, 9, .85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__brand { display: flex; align-items: baseline; gap: 12px; }

.topbar__mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .22em;
  color: var(--accent);
}

.topbar__name { font-size: 13px; color: var(--muted); }

.topbar__meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .06em;
}

.demo-banner {
  margin: 0;
  padding: 9px 20px;
  background: rgba(239, 175, 62, .12);
  border-bottom: 1px solid rgba(239, 175, 62, .3);
  color: var(--amber);
  font-size: 12px;
  text-align: center;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px;
}

.rig, .readout { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel__title { font-size: 14px; letter-spacing: .06em; }
.panel__head .panel__title { margin: 0; }
.panel > .panel__title { margin-bottom: 14px; }

.panel__note { font-size: 11px; color: var(--muted); font-family: var(--mono); }

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

.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }

.segmented button {
  flex: 1;
  background: var(--bg);
  border: 0;
  color: var(--muted);
  font-family: var(--jp);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 0;
  cursor: pointer;
}

.segmented button.is-active { background: var(--accent-deep); color: #EAFFF3; }

/* ── プリセット ─────────────────────────────── */

.presets { display: flex; flex-wrap: wrap; gap: 8px; }

.preset {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-family: var(--jp);
  font-size: 12px;
  padding: 7px 14px;
  cursor: pointer;
}
.preset:hover { border-color: var(--accent-deep); color: var(--accent); }

/* ── 条件ブロック ────────────────────────────── */

.conditions { display: flex; flex-direction: column; gap: 0; margin-bottom: 14px; }

.cond {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
}

.cond__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.cond__tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--muted);
}

.cond__remove {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
}
.cond__remove:hover { color: var(--red); }

.cond__params { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }

.cond__note { color: var(--muted); font-size: 11px; margin: 10px 0 0; line-height: 1.6; }

.cond__mirror {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-left: 2px solid var(--accent-deep);
  background: var(--panel);
  border-radius: 0 var(--r) var(--r) 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.cond__mirror b { color: var(--ink); font-weight: 700; }

.cond .field { margin-bottom: 10px; }
.cond__params .field { margin-bottom: 0; }


.andbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .3em;
}
.andbar::before, .andbar::after {
  content: '';
  height: 1px;
  background: var(--line);
  flex: 1;
}

/* ── ゲージ(この画面の主役) ───────────────────── */

.panel--gauge { padding-bottom: 22px; }

.gauge { margin: 6px 0 0; }

.gauge__track {
  position: relative;
  height: 104px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}

.gauge__zone { position: absolute; top: 0; bottom: 0; }
.gauge__zone--lose { left: 0; right: 0; background: rgba(255, 100, 112, .06); }
.gauge__zone--win { background: rgba(70, 224, 140, .09); right: 0; }

.gauge__break {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 2px dashed var(--accent);
  z-index: 3;
}

.gauge__break span {
  position: absolute;
  top: 3px;
  left: 5px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .16em;
  color: var(--accent);
  white-space: nowrap;
}

.gauge__row {
  position: absolute;
  left: 0; right: 0;
  top: 0;
  height: 50%;
  border-bottom: 1px solid var(--line-soft);
  z-index: 2;
}
.gauge__row--low { top: 50%; border-bottom: 0; }

.gauge__side {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--muted);
  opacity: .7;
  z-index: 1;
}

.gauge__ci {
  position: absolute;
  top: 50%;
  height: 2px;
  background: rgba(226, 241, 230, .28);
  transform: translateY(-50%);
}
.gauge__ci::before, .gauge__ci::after {
  content: '';
  position: absolute;
  top: -5px;
  width: 1px;
  height: 12px;
  background: rgba(226, 241, 230, .4);
}
.gauge__ci::before { left: 0; }
.gauge__ci::after { right: 0; }

.gauge__pin {
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--red);
  transform: translateX(-50%);
  transition: left .5s cubic-bezier(.2, .8, .3, 1);
  z-index: 2;
}
.gauge__pin.is-win { background: var(--accent); }

.gauge__pin span {
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--red);
  white-space: nowrap;
}
.gauge__pin.is-win span { color: var(--accent); }
.gauge__pin.is-flip span { left: auto; right: 8px; }

.gauge__scale {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

.gauge__verdict {
  margin: 16px 0 0;
  font-size: 13px;
  line-height: 1.75;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 12px;
}
.gauge__verdict.is-warn { border-left-color: var(--amber); color: var(--amber); }
.gauge__verdict.is-win { border-left-color: var(--accent); color: var(--accent); }

/* ── ハイ/ロー 2列の数値表示 ─────────────────── */

.dual {
  display: grid;
  grid-template-columns: minmax(92px, auto) 1fr 1fr;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  overflow: hidden;
}

.dual--split { grid-template-columns: minmax(92px, auto) 1fr 1fr; }

.dg { background: var(--panel); padding: 9px 12px; min-width: 0; }

.dg--head {
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--muted);
  display: flex;
  align-items: center;
}
.dg--head.is-hi, .dg--head.is-lo { justify-content: center; font-weight: 700; font-size: 11px; }
.dg--head.is-hi { color: var(--accent); }
.dg--head.is-lo { color: var(--blue); }

.dg--label {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  line-height: 1.4;
}

.dg--section {
  grid-column: 1 / -1;
  background: var(--panel-2);
  font-size: 11px;
  color: var(--muted);
  padding: 6px 12px;
}

.dg__v {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  letter-spacing: .01em;
}
.dg__v.is-good { color: var(--accent); }
.dg__v.is-bad { color: var(--red); }
.dg__v.is-amber { color: var(--amber); }
.dg__sub {
  display: block;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

.warnbox {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(239, 175, 62, .35);
  background: rgba(239, 175, 62, .08);
  border-radius: var(--r);
  color: var(--amber);
  font-size: 12px;
  line-height: 1.65;
}

/* ── 資金推移 ─────────────────────────────── */

#equityCanvas { width: 100%; display: block; }

.legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
.legend__dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: 8px;
}
.legend__dot--hi { background: var(--accent); margin-left: 0; }
.legend__dot--lo { background: var(--blue); }

.disclaimer { font-size: 11px; color: var(--muted); line-height: 1.7; margin: 0; padding: 0 2px 8px; }

/* ── オーバーレイ ────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(8, 18, 9, .8);
  backdrop-filter: blur(3px);
}

.overlay__box { text-align: center; font-family: var(--mono); font-size: 12px; color: var(--accent); letter-spacing: .12em; }

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

/* ── レスポンシブ ────────────────────────────── */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 14px; gap: 16px; }
  .topbar { padding: 12px 14px; }
  .topbar__meta { width: 100%; }
  .panel { padding: 15px; }
  .gauge__track { height: 96px; }
  .dual { grid-template-columns: minmax(78px, auto) 1fr 1fr; }
  .dg__v { font-size: 14px; }
}

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
