:root {
  --page-bg: #f5f7f8;
  --panel-bg: #ffffff;
  --panel-fg: #172026;
  --muted-fg: #68747d;
  --line: #dbe2e6;
  --field-bg: #f8fafb;
  --hover-bg: #eef3f5;
  --accent: #1f7a8c;
  --accent-soft: rgba(31, 122, 140, 0.12);
  --danger: #b4232a;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--panel-fg);
  background: var(--page-bg);
  font-family: system-ui, sans-serif;
  overflow: hidden;
}

button,
input,
select,
textarea {
  min-width: 0;
  max-width: 100%;
  font: inherit;
}

button {
  min-height: 32px;
  padding: 6px 10px;
  color: var(--panel-fg);
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
}

button:hover {
  background: var(--hover-bg);
}

input,
select,
textarea {
  width: 100%;
  padding: 7px 9px;
  color: var(--panel-fg);
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.app-shell {
  width: min(1600px, 100%);
  height: 100vh;
  min-height: 0;
  margin: 0 auto;
  padding: 10px;
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 320px;
  gap: 10px;
}

.side-panel,
.detail-panel,
.flow-stage {
  min-width: 0;
  min-height: 0;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 0;
}

.side-panel,
.detail-panel {
  max-height: calc(100vh - 20px);
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
}

.brand-block {
  display: grid;
  gap: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  color: var(--muted-fg);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 13px;
}

.panel-section {
  display: grid;
  gap: 12px;
}

.panel-section label {
  display: grid;
  gap: 6px;
  color: var(--muted-fg);
  font-size: 12px;
  font-weight: 800;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tool-grid.is-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.danger-button {
  color: var(--danger);
}

.toggle-button.is-active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.status-text {
  min-height: 1.3em;
  margin: 0;
  color: var(--muted-fg);
  font-size: 12px;
}

.flow-stage {
  height: calc(100vh - 20px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.stage-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.stage-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.stage-header h2 {
  font-size: 18px;
}

.stage-meta {
  margin: 0;
  color: var(--muted-fg);
  font-size: 12px;
  font-weight: 800;
}

.flow-canvas {
  position: relative;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-color: #fbfcfd;
}

.flow-world {
  position: relative;
}

.flow-space {
  position: relative;
  width: 3900px;
  height: 1400px;
  transform-origin: 0 0;
}

.flow-lines {
  position: absolute;
  inset: 0;
  width: 3900px;
  height: 1400px;
  overflow: visible;
  pointer-events: none;
}

.flow-line {
  fill: none;
  stroke: rgba(31, 122, 140, 0.58);
  stroke-width: 2;
  pointer-events: stroke;
}

.flow-line.is-temp {
  stroke-dasharray: 6 5;
}

.bend-handle {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 2;
  cursor: move;
  pointer-events: all;
}

.node-layer {
  position: relative;
  width: 3900px;
  min-height: 1400px;
}

.flow-node {
  position: absolute;
  width: 190px;
  min-height: 92px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 0;
  cursor: grab;
  user-select: none;
}

.flow-node.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.flow-node.is-connecting {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.flow-node:active {
  cursor: grabbing;
}

.node-port {
  position: absolute;
  top: 40px;
  width: 14px;
  min-height: 14px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: #ffffff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 900;
  cursor: crosshair;
}

.input-port {
  left: -8px;
}

.route-ports {
  position: absolute;
  top: 22px;
  right: -16px;
  display: grid;
  gap: 4px;
}

.route-port {
  position: static;
  width: 24px;
  min-height: 24px;
  color: var(--route-color);
  border-color: var(--route-color);
  background: #ffffff;
  font-size: 10px;
  line-height: 1;
}

.node-port:hover {
  color: #ffffff;
  background: var(--route-color, var(--accent));
}

.node-kind {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.node-schedule {
  min-height: 1em;
  color: var(--muted-fg);
  font-size: 10px;
  font-weight: 800;
}

.node-title {
  font-size: 15px;
  font-weight: 850;
}

.node-body {
  color: var(--muted-fg);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.settings-block {
  padding-top: 12px;
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.settings-block[hidden],
.branch-controls[hidden] {
  display: none;
}

.settings-block h3 {
  margin: 0;
  font-size: 13px;
}

.settings-fields {
  display: grid;
  gap: 10px;
}

.settings-fields .code-field {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
}

.score-template-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--field-bg);
  border: 1px solid var(--line);
}

.score-template-panel h3,
.score-template-panel h4,
.score-template-summary {
  margin: 0;
}

.score-template-panel h3,
.score-template-panel h4 {
  font-size: 12px;
}

.score-template-summary {
  color: var(--muted-fg);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.score-template-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.overlay-panel {
  display: grid;
  gap: 10px;
  padding: 10px;
  background: var(--field-bg);
  border: 1px solid var(--line);
}

.overlay-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.overlay-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-link {
  min-height: 32px;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  background: var(--panel-bg);
  border: 1px solid var(--line);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.tool-link:hover {
  background: var(--hover-bg);
}

.overlay-panel h3,
.overlay-panel p {
  margin: 0;
}

.overlay-panel h3 {
  font-size: 12px;
}

.overlay-inline-fields {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

/* .taqf 側ではオーバーレイの編集を不可にする（.taqw で作成・編集する）。
   HTML の hidden 属性が display 指定で打ち消されないよう明示的に隠す。 */
.overlay-panel [hidden] {
  display: none !important;
}

.overlay-editor {
  display: grid;
  gap: 8px;
}

.overlay-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  color: #ffffff;
  background: #050505;
  border: 1px solid var(--panel-fg);
}

.overlay-canvas-item {
  position: absolute;
  max-width: 92%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: move;
  user-select: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.overlay-canvas-item.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.overlay-canvas-item.is-image img {
  display: block;
  width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.overlay-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.overlay-item-editor {
  display: grid;
  gap: 8px;
}

.branch-controls {
  display: grid;
  gap: 10px;
}

.connection-panel {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.connection-panel h3,
.connection-title,
.connection-empty {
  margin: 0;
}

.connection-panel h3 {
  font-size: 13px;
}

.connection-title {
  color: var(--muted-fg);
  font-size: 12px;
  font-weight: 800;
}

.connection-empty {
  color: var(--muted-fg);
  font-size: 12px;
}

.connection-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(82px, auto) 56px;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: var(--field-bg);
  border: 1px solid var(--line);
}

.connection-row.is-simple {
  grid-template-columns: minmax(0, 1fr) 56px;
}

.connection-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.route-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.route-picker button {
  min-width: 0;
  padding-inline: 8px;
  white-space: nowrap;
}

.zoom-controls {
  display: grid;
  grid-template-columns: 28px minmax(90px, 140px) 28px 54px;
  align-items: center;
  gap: 6px;
}

.zoom-controls button {
  min-height: 28px;
  padding: 0 8px;
}

.zoom-controls input {
  min-height: 28px;
}

.ranking-label {
  gap: 8px;
}

/* 参加者の管理（一覧・削除・CSVから追加） */
.participant-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.participant-tools button { min-height: 28px; padding: 3px 8px; font-size: 13px; }
.rank-input textarea#rankingInput { white-space: pre; overflow-x: auto; }
.participant-tools strong { font-size: 14px; }
.participant-count { color: var(--muted-fg); font-size: 13px; margin-right: auto; }
.danger-button { color: #fff; background: var(--danger); border-color: var(--danger); }
.danger-button:hover { background: #8f1b21; }
.primary-button { color: #fff; background: var(--accent); border-color: var(--accent); }
.primary-button:hover { background: #17606e; }
.primary-button:disabled { opacity: .45; cursor: default; }
.participant-table { max-height: 280px; margin-top: 8px; overflow: auto; border: 1px solid var(--line); background: var(--panel-bg); }
.participant-table table, .csv-map-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.participant-table th, .participant-table td, .csv-map-table th, .csv-map-table td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.participant-table th, .csv-map-table th { position: sticky; top: 0; z-index: 1; color: var(--muted-fg); background: #eef3f5; font-weight: 600; }
.participant-table table { table-layout: fixed; }
.participant-table th:first-child, .participant-table td:first-child { width: 40px; color: var(--muted-fg); text-align: right; }
.participant-table th:last-child, .participant-table td:last-child { width: 38px; padding: 2px 4px; }
.participant-table td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.participant-table td:nth-child(3) { color: var(--muted-fg); }
.participant-remove { min-height: 26px; width: 30px; padding: 0; color: var(--danger); font-weight: 700; }
.participant-remove:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.participant-table .connection-empty { margin: 0; padding: 10px; }
.csv-map-dialog { width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); color: var(--panel-fg); background: var(--panel-bg); }
.csv-map-dialog::backdrop { background: rgba(10, 20, 26, .45); }
.csv-map-form { display: grid; gap: 10px; padding: 16px 18px; }
.csv-map-form h2 { margin: 0; font-size: 17px; }
.csv-source-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted-fg); font-size: 13px; }
.csv-options { display: flex; flex-wrap: wrap; gap: 16px; }
.csv-check { display: inline-flex !important; align-items: center; gap: 6px; font-size: 13px; }
.csv-check input { width: auto; }
.csv-hint, .csv-summary { margin: 0; color: var(--muted-fg); font-size: 12px; }
.csv-summary { color: var(--panel-fg); font-weight: 600; font-size: 13px; }
.csv-map-table { max-height: 300px; overflow: auto; border: 1px solid var(--line); }
.csv-map-table td:nth-child(2) { color: var(--muted-fg); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csv-map-table td:nth-child(3) { width: 270px; }
.csv-map-table select, .csv-map-table input { padding: 4px 6px; }
.csv-var-key { margin-top: 4px; }
.csv-var-key.is-invalid { border-color: var(--danger); outline: 1px solid var(--danger); }
.csv-preview { margin: 0; max-height: 140px; padding: 8px 10px; overflow: auto; border: 1px solid var(--line); background: var(--field-bg); font-size: 12px; white-space: pre; }
.csv-actions { display: flex; justify-content: flex-end; gap: 8px; }

.rank-input {
  min-height: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  border: 1px solid var(--line);
  background: var(--field-bg);
}

.rank-input textarea {
  min-height: 190px;
  border: 0;
  background: transparent;
}

.ranking-guide {
  max-height: 100%;
  padding: 9px 6px;
  overflow: hidden;
  color: var(--muted-fg);
  background: #eef3f5;
  border-right: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
  user-select: none;
}

.ranking-guide div {
  height: 1.5em;
}

.inline-fields {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
}

.group-output,
.schedule-output {
  display: grid;
  gap: 8px;
}

.group-row,
.schedule-row {
  padding: 10px;
  display: grid;
  gap: 6px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 0;
}

.group-row h3,
.schedule-row h3 {
  margin: 0;
  font-size: 12px;
}

.group-row p,
.schedule-row p {
  margin: 0;
  color: var(--muted-fg);
  font-size: 12px;
  line-height: 1.5;
}

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 160px;
  display: grid;
  padding: 4px;
  background: #ffffff;
  border: 1px solid var(--panel-fg);
}

.context-menu button {
  width: 100%;
  justify-content: start;
  text-align: left;
  background: #ffffff;
  border-color: transparent;
}

.context-menu button:hover {
  background: var(--hover-bg);
}

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

  .flow-stage {
    min-height: 640px;
  }
}
