:root {
  --bg: #eef5ff;
  --surface: #ffffff;
  --surface-soft: #f4f8ff;
  --ink: #17213b;
  --muted: #687187;
  --line: #d5deee;
  --blue: #2d65c8;
  --green: #14895b;
  --red: #d72f2f;
  --yellow: #f1b91f;
  --violet: #6d4bc3;
  --deep-blue: #1d3f86;
  --shadow: 0 14px 36px rgba(29, 63, 134, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #eaf3ff 0%, #f7fbff 38%, #fff8e1 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  border-color: var(--blue);
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

button.danger {
  color: var(--red);
  border-color: #f2a1a1;
  background: #fff4f4;
}

button.ghost {
  background: transparent;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 7px;
  min-height: 36px;
  padding: 7px 9px;
}

textarea {
  min-height: 58px;
  resize: vertical;
}

.app-shell {
  width: min(1540px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 32px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  align-items: center;
  justify-items: center;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 2px solid var(--deep-blue);
  border-radius: 8px;
  padding: 26px;
  box-shadow: var(--shadow);
  border-top: 8px solid var(--red);
}

.login-panel h1,
.page-title h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.login-panel p,
.page-title p {
  margin: 8px 0 0;
  color: var(--muted);
}

.login-panel form {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.error-text {
  color: var(--red);
  min-height: 20px;
  margin: 0;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 8px solid var(--red);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.control-strip {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(2, minmax(150px, 0.8fr)) auto;
  gap: 10px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--yellow);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.field span,
.checkline span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(118px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 24px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tracker-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tab {
  min-height: 34px;
  padding: 0 10px;
}

.tab.active {
  background: var(--deep-blue);
  border-color: var(--deep-blue);
  color: #fff;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

th {
  padding: 10px 12px;
  font-size: 12px;
  color: #ffffff;
  background: var(--deep-blue);
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  padding: 12px;
}

tr:last-child td {
  border-bottom: 0;
}

tr.row-rip {
  background: #fff1f1;
}

tr.row-missed {
  background: #fff8df;
}

.area-cell {
  width: 190px;
}

.area-order {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--yellow);
  color: #2d2400;
  font-size: 12px;
  margin-bottom: 8px;
}

.area-name {
  font-weight: 700;
  line-height: 1.2;
}

.area-meta,
.slot-meta,
.timestamp {
  color: var(--muted);
  font-size: 12px;
}

.slot {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
}

.sprite {
  width: 76px;
  height: 76px;
  object-fit: contain;
  image-rendering: pixelated;
  border: 2px solid #c6d6ef;
  border-radius: 7px;
  background: #f7fbff;
  padding: 4px;
}

.sprite.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
}

.slot-main {
  display: grid;
  gap: 7px;
}

.slot-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, 0.75fr);
  gap: 7px;
  align-items: start;
}

.status-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.status-group button {
  min-height: 30px;
  padding: 0 6px;
  font-size: 12px;
}

.status-group button.active[data-status="Team"] {
  background: #e9f7f0;
  border-color: #79c5a0;
  color: var(--green);
}

.status-group button.active[data-status="Box"] {
  background: #edf3ff;
  border-color: #9eb9f3;
  color: var(--blue);
}

.status-group button.active[data-status="RIP"] {
  background: #fff0ef;
  border-color: #e69b95;
  color: var(--red);
}

.type-row,
.warning-list {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.type-chip,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.badge.red {
  color: var(--red);
  border-color: #efb7b3;
  background: #fff3f2;
}

.badge.yellow {
  color: var(--yellow);
  border-color: #e5c56f;
  background: #fff9e9;
}

.badge.green {
  color: var(--green);
  border-color: #9fd3b8;
  background: #effaf4;
}

.type-normal { background: #f1f1ea; }
.type-fire { background: #ffe8d9; }
.type-water { background: #e5f0ff; }
.type-electric { background: #fff6cb; }
.type-grass { background: #e5f6df; }
.type-ice { background: #e7f8f8; }
.type-fighting { background: #ffe2df; }
.type-poison { background: #f2e2ff; }
.type-ground { background: #f4ead2; }
.type-flying { background: #ece8ff; }
.type-psychic { background: #ffe2ee; }
.type-bug { background: #eef4cf; }
.type-rock { background: #eee5c3; }
.type-ghost { background: #e7e1f1; }
.type-dragon { background: #e8ddff; }
.type-dark { background: #e0dbd8; }
.type-steel { background: #e8eaf0; }

.pair-tools {
  width: 190px;
}

.pair-tools .button-stack {
  display: grid;
  gap: 6px;
}

.split-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.split-buttons button {
  min-height: 32px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--yellow);
  background: var(--deep-blue);
  border-color: var(--deep-blue);
}

.pair-select {
  display: grid;
  gap: 4px;
}

.pair-select span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.pair-select select {
  min-height: 32px;
  padding: 4px 7px;
  font-size: 12px;
}

.autocomplete {
  position: relative;
  display: grid;
  gap: 4px;
}

.autocomplete-menu {
  display: none;
  gap: 4px;
  padding: 5px;
  background: #f6f9ff;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 10px 18px rgba(29, 63, 134, 0.12);
}

.autocomplete-menu.active {
  display: grid;
}

.autocomplete-menu button {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 4px 7px;
  text-align: left;
  font-weight: 700;
}

.autocomplete-menu img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  image-rendering: pixelated;
}

.autocomplete-menu small {
  color: var(--muted);
  font-size: 11px;
}

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

.side-section {
  padding: 14px;
}

.side-section + .side-section {
  border-top: 1px solid var(--line);
}

.side-section h2 {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--deep-blue);
}

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

.score-card {
  display: grid;
  grid-template-columns: 1fr repeat(3, auto);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 5px solid var(--red);
  border-radius: 7px;
  padding: 9px;
  background: #fffdf5;
}

.score-card span {
  color: var(--muted);
  font-size: 12px;
}

.score-card b {
  color: var(--ink);
}

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

.checkline {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
}

.checkline input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}

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

details {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  background: #fbfcfb;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

details p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 34px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--ink);
  color: #fff;
  padding: 10px 12px;
  border-radius: 7px;
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100% - 32px));
  z-index: 5;
}

.hidden {
  display: none;
}

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

  .side-panel {
    grid-row: 1;
  }

  .metrics {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 1480px);
    padding-top: 10px;
  }

  .topbar,
  .control-strip,
  .tracker-toolbar {
    grid-template-columns: 1fr;
  }

  .actions,
  .tabs {
    justify-content: stretch;
  }

  .actions > *,
  .tabs > * {
    flex: 1;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .slot-row {
    grid-template-columns: 1fr;
  }
}
