:root {
  --bg: #0f1218;
  --panel: #171b24;
  --panel-2: #1e2330;
  --text: #e8eaf0;
  --text-dim: #98a1b3;
  --border: #2a3040;
  --accent: #4c8bff;
  --accent-hover: #6ba0ff;
  --danger: #ff5f5f;
  --success: #58d68d;
  --warn: #ffb955;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "LINE Seed JP", "Yu Gothic UI", "游ゴシック", YuGothic,
    "Hiragino Kaku Gothic ProN", "ヒラギノ角ゴ ProN", "Hiragino Sans",
    "Noto Sans JP", "Meiryo", "メイリオ", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
}

code {
  background: #0b0d13;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: Consolas, Menlo, monospace;
}

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background 120ms;
}
button:hover:not(:disabled) {
  background: #2a3245;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(255, 95, 95, 0.4);
}
button.danger:hover:not(:disabled) {
  background: rgba(255, 95, 95, 0.12);
}

input[type="text"],
input[type="number"] {
  background: #0b0d13;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* ---- Landing ---- */

body.landing {
  display: flex;
  justify-content: center;
  padding: 60px 20px;
}
body.landing main {
  max-width: 720px;
  width: 100%;
}
.lead {
  color: var(--text-dim);
}
.note {
  color: var(--text-dim);
  font-size: 13px;
}
.groups-section {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.group-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
}
.group-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}
.url-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 5px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.03);
}
.url-row:first-of-type {
  border-top: none;
}
.url-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.url-link {
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.url-link:hover {
  color: var(--accent);
}
.copy-btn {
  padding: 4px 10px;
  font-size: 12px;
}
.key-form {
  display: flex;
  gap: 8px;
  max-width: 480px;
}
.key-form input {
  flex: 1;
}

/* ---- Operator layout ---- */

body.operator {
  min-height: 100vh;
}
.app-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.conn-status {
  padding: 2px 8px;
  border-radius: 10px;
  background: #2a3040;
}
.conn-status.ok {
  background: rgba(88, 214, 141, 0.18);
  color: var(--success);
}
.conn-status.bad {
  background: rgba(255, 95, 95, 0.18);
  color: var(--danger);
}

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 14px 80px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 20px;
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-header h2 {
  margin: 0;
}
.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.muted {
  color: var(--text-dim);
  font-weight: normal;
  font-size: 13px;
}

/* ---- Settings ---- */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}
@media (max-width: 900px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
.teams-textarea {
  display: block;
  width: 100%;
  min-height: 160px;
  padding: 8px 10px;
  background: #0b0d13;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: Consolas, Menlo, "Meiryo", monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  margin-bottom: 10px;
}
.teams-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.rank-inputs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.rank-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.rank-row label {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 2px;
}

/* ---- Drop zone ---- */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition:
    background 120ms,
    border-color 120ms;
  color: var(--text-dim);
}
.drop-zone:hover,
.drop-zone:focus {
  border-color: var(--accent);
  color: var(--text);
  outline: none;
}
.drop-zone.dragging {
  border-color: var(--accent);
  background: rgba(76, 139, 255, 0.08);
  color: var(--text);
}
.dz-icon {
  font-size: 32px;
  margin-bottom: 6px;
}
.dz-text {
  font-size: 14px;
}

.msg {
  min-height: 18px;
  margin-top: 10px;
  font-size: 13px;
}
.msg.error {
  color: var(--danger);
}
.msg.ok {
  color: var(--success);
}

/* ---- Tables ---- */

.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th,
td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}
th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

#games-tbody td:last-child {
  text-align: right;
}
#games-tbody tr.game-row {
  cursor: pointer;
}
#games-tbody tr.game-row .toggle {
  display: inline-block;
  width: 14px;
  color: var(--text-dim);
  transition: transform 120ms;
}
#games-tbody tr.game-row.expanded .toggle {
  transform: rotate(90deg);
  color: var(--accent);
}
#games-tbody tr.preview-row td {
  background: #12151d;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.preview-table {
  width: auto;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.preview-table th,
.preview-table td {
  border: none;
  padding: 3px 10px;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: top;
}
.preview-table td.preview-players {
  white-space: nowrap;
  line-height: 1.35;
}
.preview-table td.preview-players div {
  padding: 0;
}
.preview-table th {
  color: var(--text-dim);
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.preview-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.preview-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* ---- Scoreboard ---- */

.scoreboard {
  background: var(--panel-2);
  border-radius: 8px;
  padding: 14px;
}
.scoreboard-table {
  font-size: 14px;
}
.scoreboard-table th {
  color: var(--text-dim);
}
.scoreboard-table .col-rank {
  width: 60px;
  text-align: center;
}
.scoreboard-table .col-num {
  width: 90px;
  text-align: right;
}
.scoreboard-table tbody td.col-rank {
  text-align: center;
  font-weight: 700;
  color: var(--accent);
}
.scoreboard-table tbody td.col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.scoreboard-table tbody td.col-total {
  font-weight: 700;
}

.details-block {
  margin-top: 20px;
}
.details-block summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 0;
}

/* ---- Matrix + BAN table ---- */

.matrix-table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
}
.matrix-table th,
.matrix-table td {
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  height: 28px; /* header rows: 2×28 = 56 to match totals thead */
}
.matrix-table tbody td {
  height: 39px; /* team rows: matches totals tbody rows */
}
.matrix-table tr.ban-row td,
.matrix-table tr.ban-row th {
  height: 30px;
}
.matrix-table thead th {
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.matrix-table thead th.round-col {
  color: var(--accent);
  font-weight: 700;
}
.matrix-table thead th.total-col {
  color: var(--warn);
}
.matrix-table thead th.num {
  min-width: 42px;
}
.matrix-table td.team-col,
.matrix-table th.team-col {
  text-align: left;
  min-width: 140px;
  padding-left: 12px;
  font-weight: 700;
  border-right: 1px solid var(--border);
}
.matrix-table tr.ban-row td.ban-cell {
  background: rgba(255, 95, 95, 0.08);
  color: var(--danger);
  font-weight: 600;
  border-right: 1px solid var(--border);
  text-align: center;
  padding: 6px 10px;
  white-space: normal;
  line-height: 1.35;
}
.matrix-table tr.ban-row th.team-col {
  color: var(--danger);
}
.matrix-table td.num {
  font-variant-numeric: tabular-nums;
}
.matrix-table tbody td {
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}
.matrix-table tbody td:nth-child(3n + 1) {
  border-right: 1px solid var(--border);
}

/* ---- Matrix + totals layout ---- */

.matrix-layout {
  display: flex;
  gap: 14px;
  align-items: stretch;
}
.matrix-block {
  flex: 1;
  min-width: 0;
}
.side-block {
  flex: 0 0 320px;
  background: var(--panel-2);
  border-radius: 6px;
  overflow: hidden;
}
.totals-block {
  padding: 0 8px;
}
/* Row heights are aligned with the matrix table by explicit min-heights,
   so team rows appear at the same Y positions on both tables. */
.totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  display: flex;
  flex-direction: column;
}
.totals-table thead,
.totals-table tbody {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.totals-table tr {
  display: flex;
  width: 100%;
  align-items: center;
}
.totals-table thead tr {
  min-height: 58px; /* matches matrix's 2-row header (28 + 28 + border) */
  border-bottom: 1px solid var(--border);
}
.totals-table tbody tr {
  min-height: 40px; /* matches matrix team row (39 + border) */
  flex: 0 0 auto;
}
.totals-table th,
.totals-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.totals-table thead th {
  border-bottom: none;
}
.totals-table thead th {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.totals-table th.t-rank,
.totals-table td.t-rank {
  flex: 0 0 32px;
  text-align: center;
  font-weight: 700;
  color: var(--text-dim);
}
.totals-table tr.top-1 td.t-rank {
  color: #ffd257;
}
.totals-table tr.top-2 td.t-rank {
  color: #cfd6e4;
}
.totals-table tr.top-3 td.t-rank {
  color: #e59f6a;
}
.totals-table th.t-team,
.totals-table td.t-team {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.totals-table th.t-num,
.totals-table td.t-num {
  flex: 0 0 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.totals-table td.t-total {
  font-weight: 700;
  color: var(--accent);
}
.totals-table tbody tr:last-child td {
  border-bottom: none;
}
@media (max-width: 1200px) {
  .matrix-layout {
    flex-direction: column;
  }
  .side-block {
    flex: 1 1 auto;
    width: 100%;
  }
}

/* ---- Penalty controls (matrix table) ---- */

.matrix-table thead th.penalty-col {
  color: var(--danger);
  min-width: 130px;
}
.matrix-table td.penalty-cell {
  border-left: 1px solid var(--border);
  padding: 4px 4px;
}
.penalty-ctrl {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.penalty-input {
  width: 48px !important;
  padding: 3px 5px !important;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.penalty-btn {
  padding: 3px 6px;
  font-size: 11px;
  min-width: 26px;
}

/* Penalty column in scoreboard */
.scoreboard-table tbody td.col-penalty {
  color: var(--danger);
}

/* Penalty in summary card */
.summary-card .sum-penalty {
  color: #ff8b8b;
  font-weight: 700;
}

/* ---- Fixed BAN checkbox grid ---- */

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 12px;
  margin: 12px 0;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  background: #0b0d13;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  border-radius: 3px;
}
.checkbox-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.checkbox-item input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

/* ---- Overlay URL fields ---- */

.overlay-url-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.overlay-url-field label {
  flex: 0 0 130px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}
.overlay-url-field input {
  flex: 1;
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
  cursor: text;
  padding: 6px 8px;
}

/* ---- Summary title input ---- */

.input-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.summary-title-input {
  max-width: 480px;
  margin-bottom: 10px;
}

/* ---- Game IDs auto-view ---- */

.game-ids-view {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 8px 0 10px;
}
.game-ids-pre {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  background: #0b0d13;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: Consolas, Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  min-height: 40px;
  overflow-x: auto;
}
#games-tbody td.gameid {
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---- Daily summary capture card ---- */

.summary-card {
  width: 1080px;
  padding: 24px 28px;
  background: #12141b;
  color: #f2f4f8;
  border-radius: 12px;
  font-family:
    "LINE Seed JP", "Yu Gothic UI", "游ゴシック", YuGothic,
    "Hiragino Kaku Gothic ProN", sans-serif;
}
.summary-card .sum-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #3a4560;
}
.summary-card .sum-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 20px;
}
.summary-card .sum-table th,
.summary-card .sum-table td {
  padding: 6px 6px;
  border-bottom: 1px solid #2a3040;
  text-align: center;
  white-space: nowrap;
}
.summary-card .sum-table thead th {
  color: #98a3bb;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  border-bottom: 1px solid #3a4560;
  border-right: 1px solid #2a3040;
}
.summary-card .sum-table th.sum-round {
  color: #4c8bff;
  font-size: 12px;
}
.summary-card .sum-gid {
  color: #98a3bb;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.summary-card .sum-num {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.summary-card .sum-team-col,
.summary-card .sum-team {
  text-align: left;
  padding-left: 10px;
  font-weight: 700;
  border-right: 1px solid #2a3040;
}
.summary-card .sum-team-col {
  min-width: 160px;
}
.summary-card .sum-ban {
  background: rgba(255, 95, 95, 0.08);
}
.summary-card .sum-ban th.sum-team-col {
  color: #ff5f5f;
}
.summary-card .sum-ban-cell {
  color: #ff8b8b;
  font-weight: 600;
  border-right: 1px solid #2a3040;
  white-space: normal;
  line-height: 1.3;
}
.summary-card .sum-dim {
  color: #4c5468;
}
.summary-card .sum-total {
  color: #ffffff;
  font-weight: 700;
}
.summary-card .sum-lb-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #98a3bb;
  margin: 14px 0 6px;
}
.summary-card .sum-lb {
  width: 60%;
  border-collapse: collapse;
  font-size: 14px;
}
.summary-card .sum-lb th,
.summary-card .sum-lb td {
  padding: 6px 10px;
  border-bottom: 1px solid #2a3040;
}
.summary-card .sum-lb th {
  color: #98a3bb;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: left;
}
.summary-card .sum-lb .sum-team {
  border-right: none;
}

/* ---- Capture card (compact, thumbnail-legible) ---- */

#capture-stage {
  position: fixed;
  left: -10000px;
  top: 0;
  pointer-events: none;
  opacity: 0;
}
.capture-card {
  width: 520px;
  background: #12141b;
  color: #f2f4f8;
  font-family:
    "LINE Seed JP", "Yu Gothic UI", "游ゴシック", YuGothic,
    "Hiragino Kaku Gothic ProN", "ヒラギノ角ゴ ProN", "Hiragino Sans",
    "Noto Sans JP", "Meiryo", "メイリオ", "Segoe UI", sans-serif;
  padding: 20px 22px 18px;
  border-radius: 12px;
  overflow: hidden;
}
.capture-card .cap-head {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  padding-bottom: 8px;
  border-bottom: 2px solid #3a4560;
  margin-bottom: 8px;
}
.capture-card .cap-round {
  font-size: 16px;
  font-weight: 700;
  color: #98a3bb;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.capture-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 18px;
}
.capture-card th {
  color: #98a3bb;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid #2a3040;
  font-weight: 700;
  white-space: nowrap;
}
.capture-card th.num {
  text-align: left;
}
.capture-card td {
  padding: 8px 8px;
  border-bottom: 1px solid #1e2330;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.capture-card td.rank {
  font-size: 22px;
  font-weight: 700;
  width: 46px;
  text-align: center;
  color: #7a879e;
}
.capture-card tr.top-1 td.rank {
  color: #ffd257;
}
.capture-card tr.top-2 td.rank {
  color: #cfd6e4;
}
.capture-card tr.top-3 td.rank {
  color: #e59f6a;
}
.capture-card td.team {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.capture-card td.breakdown {
  font-size: 12px;
  color: #7f8ba3;
  text-align: left;
  width: 96px;
}
.capture-card td.total {
  font-size: 24px;
  font-weight: 700;
  text-align: left;
  color: #ffffff;
  width: 80px;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #202634;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms,
    transform 180ms;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  border-color: rgba(255, 95, 95, 0.5);
}
.toast.ok {
  border-color: rgba(88, 214, 141, 0.5);
}
