:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #202531;
  --surface-3: #2b313f;
  --ink: #f7f0e8;
  --muted: #a9b1c0;
  --line: rgba(255, 255, 255, .12);
  --line-strong: rgba(255, 255, 255, .22);
  --accent: #38bdf8;
  --accent-2: #f472b6;
  --danger: #fb7185;
  --ok: #34d399;
  --broken: #5d6473;
  --faction-color: #22c55e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, #111827 0%, #18181b 46%, #1e293b 100%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 48px);
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

.topBody,
.operatorBody {
  display: block;
  min-height: 100vh;
  padding: 32px 16px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(100vw, 720px);
  height: min(100vh, 980px);
  min-height: 640px;
  display: grid;
  grid-template-columns: 136px 1fr;
  grid-template-rows: 1fr 74px;
  overflow: hidden;
  background: rgba(15, 17, 23, .96);
  border: 1px solid var(--line-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .38);
}

.tabs {
  grid-row: 1 / 2;
  display: grid;
  grid-auto-rows: minmax(76px, auto);
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding: 12px 10px;
  background: #11141c;
  border-right: 1px solid var(--line);
}

.tabButton {
  min-height: 76px;
  border: 1px solid color-mix(in srgb, var(--faction-color), white 22%);
  background: linear-gradient(145deg, color-mix(in srgb, var(--faction-color), #11141c 72%), #171a23);
  color: var(--ink);
  display: grid;
  align-content: center;
  gap: 5px;
  text-align: left;
  padding: 10px;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.18;
  position: relative;
  overflow: hidden;
}

.tabButton::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--faction-color);
}

.tabButton span,
.tabButton small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 5px;
}

.tabButton small {
  color: color-mix(in srgb, var(--faction-color), white 46%);
  font-size: 11px;
  font-weight: 800;
}

.tabButton.active {
  background: linear-gradient(145deg, color-mix(in srgb, var(--faction-color), #11141c 48%), #242b38);
  border-color: color-mix(in srgb, var(--faction-color), white 54%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--faction-color), white 16%);
}

.tabButton.allBroken,
.tabButton.hiddenTab {
  background: linear-gradient(145deg, #3b414d, #252a34);
  border-color: rgba(255, 255, 255, .16);
  color: #c6cad3;
}

.tabButton.allBroken::before,
.tabButton.hiddenTab::before {
  background: #8a909c;
}

.tabButton.hiddenTab {
  opacity: .55;
}

.board {
  grid-row: 1 / 2;
  overflow-y: auto;
  padding: 0 24px 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .04), transparent 180px),
    var(--bg);
}

.characterHeader {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .04), transparent 180px),
    var(--bg);
}

.sessionTitle {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.characterHeader h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 54px);
  line-height: 1;
  letter-spacing: 0;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.actionBox {
  min-width: 118px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 12px;
  text-align: right;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
}

.actionBox strong {
  display: block;
  margin-top: 2px;
  font-size: 35px;
  line-height: 1;
  color: var(--ink);
}

.partsList {
  padding-bottom: 24px;
}

.characterMeta {
  position: sticky;
  top: 126px;
  z-index: 3;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
  padding: 10px 0;
  background: var(--bg);
}

.factionBadge,
.damageBadge,
.playerBadge,
.actionBadge {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 900;
}

.factionBadge {
  background: color-mix(in srgb, var(--faction-color), #171a23 68%);
  border-color: color-mix(in srgb, var(--faction-color), white 20%);
  color: color-mix(in srgb, var(--faction-color), white 64%);
}

.damageBadge {
  background: var(--surface);
  color: var(--muted);
}

.playerBadge {
  background: #111827;
  color: var(--muted);
}

.actionBadge {
  background: #172033;
  color: #d7e6f5;
}

.damageBadge.critical {
  background: #3b414d;
  color: #f1f5f9;
}

.partSection {
  margin-top: 16px;
}

.partSection h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  font-weight: 900;
}

.partRows {
  display: grid;
  gap: 8px;
}

.partRow {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: clamp(15px, 3.4vw, 20px);
  font-weight: 900;
  line-height: 1.12;
  text-align: left;
}

.partRow:hover,
.partRow:focus-visible {
  border-color: var(--accent);
  background: var(--surface-2);
}

.partRow.broken {
  background: #10141d;
  border-color: rgba(255, 255, 255, .08);
  color: #8f98a8;
}

.partRow.broken .partName {
  opacity: .72;
}

.partRow.broken .checkBox {
  border-color: #4d5666;
  background: #0b0e14;
}

.partRow.reference {
  cursor: default;
  background: #141925;
  color: #d9dde6;
}

.partRow.reference:hover,
.partRow.reference:focus-visible {
  border-color: var(--line);
  background: #141925;
}

.checkBox {
  width: 28px;
  height: 28px;
  border: 2px solid #788294;
  background: #11141c;
  position: relative;
}

.partRow:not(.broken) .checkBox {
  border-color: var(--ok);
}

.partRow:not(.broken) .checkBox::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 2px;
  width: 9px;
  height: 17px;
  border: solid var(--ok);
  border-width: 0 3px 3px 0;
  transform: rotate(42deg);
}

.infoDot {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line-strong);
  background: #202738;
  position: relative;
}

.infoDot::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 999px;
  background: var(--accent);
}

.partName {
  min-width: 0;
  overflow-wrap: anywhere;
}

.bottomBar {
  grid-column: 1 / 3;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #0b0d12;
  border-top: 1px solid var(--line);
}

.bottomBar button {
  min-height: 48px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: #e7edf7;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.12;
}

.bottomBar button:hover,
.bottomBar button:focus-visible {
  border-color: var(--accent);
  background: #253042;
}

.app[data-connection="offline"] .bottomBar {
  box-shadow: inset 0 3px 0 var(--danger);
}

dialog {
  width: min(94vw, 560px);
  max-height: 88vh;
  padding: 0;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(0, 0, 0, .62);
}

.modalFrame {
  margin: 0;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #0d1017;
  border-bottom: 1px solid var(--line);
}

.modalHeader h2 {
  margin: 0;
  font-size: 20px;
}

.closeButton {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.modalBody {
  max-height: calc(88vh - 67px);
  overflow: auto;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field span,
.label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.field input,
.field select,
.field textarea,
.editRow input,
.editRow select,
.factionEditRow input[type="text"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  background: #0f131b;
  color: var(--ink);
  padding: 9px 10px;
}

.field textarea {
  min-height: 120px;
}

.buttonRow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.primaryButton,
.plainButton,
.dangerButton {
  border: 1px solid var(--line-strong);
  padding: 9px 13px;
  min-height: 42px;
  font-weight: 900;
}

.primaryButton {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent), white 20%);
  color: #06111a;
}

.plainButton {
  background: var(--surface-2);
  color: var(--ink);
}

.dangerButton {
  background: var(--danger);
  border-color: color-mix(in srgb, var(--danger), white 20%);
  color: #20040a;
}

.editList {
  display: grid;
  gap: 8px;
  margin: 12px 0 18px;
}

.editRow {
  display: grid;
  grid-template-columns: 1fr 88px 42px 42px;
  gap: 7px;
  align-items: center;
}

.miniButton {
  width: 42px;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 900;
}

.miniButton.isOn {
  background: var(--broken);
}

.miniTag {
  width: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  background: #111827;
  color: var(--muted);
  font-weight: 900;
}

.factionEditor,
.adminBox {
  border: 1px solid var(--line);
  background: #121721;
  padding: 14px;
  margin: 6px 0 16px;
}

.factionEditor h3,
.adminBox h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.factionRows {
  display: grid;
  gap: 8px;
}

.factionEditRow {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 8px;
  align-items: center;
}

.factionEditRow input[type="color"] {
  width: 46px;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  background: #0f131b;
  padding: 4px;
}

.adminNote {
  border-left: 4px solid var(--accent);
  background: #121721;
  padding: 9px 10px;
}

.historyList {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.historyList li {
  border-left: 4px solid var(--accent);
  background: #121721;
  padding: 10px 11px;
}

.historyList time {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 2px;
}

.smallText {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.warningText {
  color: #fbbf24;
}

.topPage,
.operatorPage {
  width: min(100%, 980px);
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

.topHero,
.topSection,
.operatorPanel,
.operatorLogin {
  border: 1px solid var(--line);
  background: rgba(23, 26, 35, .92);
  padding: 20px;
}

.topHero {
  padding: 28px;
}

.topEyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topHero h1,
.operatorHeader h1 {
  margin: 0 0 10px;
  font-size: clamp(32px, 8vw, 56px);
  line-height: 1;
}

.topHero p,
.topSection p,
.topSection li {
  color: var(--muted);
  line-height: 1.75;
}

.roomForm {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
  gap: 10px;
  align-items: end;
  margin-top: 20px;
}

.roomForm label {
  display: grid;
  gap: 7px;
}

.roomForm span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.roomForm input {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  background: #0f131b;
  color: var(--ink);
  padding: 9px 10px;
}

.topSection h2,
.operatorPanel h2,
.operatorLogin h2 {
  margin: 0 0 10px;
}

.operatorHeader {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

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

.operatorPanel.wide {
  grid-column: 1 / -1;
}

.operatorList {
  display: grid;
  gap: 10px;
}

.operatorCard {
  border: 1px solid var(--line);
  background: #111721;
  padding: 12px;
}

.operatorCard h3 {
  margin: 0 0 6px;
}

.logBox,
.detailBox {
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #0f131b;
  padding: 12px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.logBox div {
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  padding: 5px 0;
}

.logBox div:last-child {
  border-bottom: 0;
}

.emptyState {
  min-height: 360px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: 12px;
  color: var(--muted);
}

.emptyState h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(25px, 6vw, 36px);
}

.emptyState p {
  max-width: 360px;
  margin: 0;
  line-height: 1.7;
}

.noticeToast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  background: #0b0d12;
  color: #fff;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  z-index: 10;
  font-weight: 900;
  box-shadow: 0 16px 38px rgba(0, 0, 0, .36);
}

@supports not (color: color-mix(in srgb, white, black)) {
  .tabButton,
  .tabButton.active,
  .factionBadge {
    background: var(--surface-2);
    border-color: var(--faction-color);
  }
}

@media (max-width: 560px) {
  .app {
    grid-template-columns: 92px 1fr;
    min-height: 100vh;
    box-shadow: none;
  }

  .tabs {
    padding: 8px 7px;
    gap: 7px;
  }

  .tabButton {
    min-height: 70px;
    padding: 8px 7px;
    font-size: 14px;
  }

  .tabButton small {
    font-size: 10px;
  }

  .board {
    padding: 0 14px 20px;
  }

  .characterHeader {
    top: 0;
    align-items: stretch;
    flex-direction: column;
    padding-top: 18px;
  }

  .characterMeta {
    top: 177px;
  }

  .actionBox {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
  }

  .actionBox strong {
    margin: 0;
    font-size: 30px;
  }

  .bottomBar {
    gap: 7px;
    padding: 9px 8px;
  }

  .bottomBar button {
    font-size: 13px;
  }

  .editRow {
    grid-template-columns: 1fr 76px 38px 38px;
    gap: 5px;
  }

  .roomForm,
  .operatorGrid {
    grid-template-columns: 1fr;
  }
}
