:root {
  --bg: #0d1117;
  --bg-elevated: #161b22;
  --bg-input: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --win: #3fb950;
  --loss: #f85149;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.title {
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.title-link {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  text-decoration: none;
}

.title-link:hover {
  color: var(--text);
}

.title-link-icon {
  width: 100%;
  height: 100%;
  background-color: currentColor;
  -webkit-mask: url("../icons/github.svg") center / contain no-repeat;
  mask: url("../icons/github.svg") center / contain no-repeat;
}

.config {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.config-label {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.input-stack {
  -webkit-appearance: none;
  -moz-appearance: textfield;
  appearance: none;
  /* width: 7rem; */
  min-height: 2.5rem;
  padding: 0.65rem 0.85rem;
  background-color: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.05rem;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.input-stack:hover {
  background-color: rgba(0, 0, 0, 0.5);
}

.input-stack:focus {
  outline: none;
  border-color: rgba(88, 166, 255, 0.5);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
  background-color: rgba(0, 0, 0, 0.55);
}

.input-stack::-webkit-outer-spin-button,
.input-stack::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.btn-add {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-add:hover {
  background: var(--accent-hover);
}

.btn-reset {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--loss);
  border-radius: var(--radius);
  color: var(--loss);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-reset:hover {
  background: rgba(248, 81, 73, 0.15);
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.grid-footer {
  margin-top: 1rem;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elevated);
  table-layout: fixed;
}

.col-name {
  width: 7rem;
}

.col-start {
  width: 4rem;
}

.col-restacks {
  width: 5rem;
}

.col-final {
  width: 5rem;
}

.col-net {
  width: 6rem;
}

.col-adjusted {
  width: 5rem;
}

.col-settlements {
  width: 10rem;
}

.col-actions {
  width: 3.25rem;
}

.grid th,
.grid td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.grid th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
}

.grid tbody tr:last-child td {
  border-bottom: none;
}

.grid tbody tr:not(.row-total):hover {
  background: rgba(255, 255, 255, 0.02);
}

.row-total td {
  font-weight: 500;
  background: rgba(0, 0, 0, 0.15);
  border-top: 2px solid var(--border);
}

.row-total-error td {
  color: var(--loss);
}

.cell-name,
.cell-restacks,
.cell-final {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 5rem;
  min-height: 2rem;
  height: 100%;
  padding: 0.45rem 0.6rem;
  background-color: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: var(--text);
  font-size: 1.05rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.cell-name:hover,
.cell-restacks:hover,
.cell-final:hover {
  background-color: rgba(0, 0, 0, 0.5);
}

.cell-restacks,
.cell-final,
.cell-pnl,
.cell-adjusted {
  text-align: right;
}

/* Custom +/- buttons for restacks */
.td-name,
.td-final,
.td-restacks {
  padding: 0.25rem;
}

.td-restacks {
  white-space: nowrap;
}

.restacks-control {
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 100%;
  width: 100%;
  min-height: 2.15rem;
  min-width: 0;
}

.restacks-control .cell-restacks {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  padding: 0.45rem 0.35rem;
  border-right: none;
  border-radius: 6px 0 0 6px;
  text-align: center;
}

.restacks-btns {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.restacks-btns .btn-spin {
  flex: 1;
  min-height: 1rem;
  padding: 0 0.45rem;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-left: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.restacks-btns .btn-spin:first-child {
  border-radius: 0 6px 0 0;
  border-bottom: none;
}

.restacks-btns .btn-spin:last-child {
  border-radius: 0 0 6px 0;
}

.restacks-btns .btn-spin:hover {
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
}

.restacks-control .cell-restacks::-webkit-outer-spin-button,
.restacks-control .cell-restacks::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.restacks-control .cell-restacks {
  appearance: textfield;
  -moz-appearance: textfield;
}

/* No spin buttons for final balance */
.cell-final {
  appearance: textfield;
  -moz-appearance: textfield;
}

.cell-final::-webkit-outer-spin-button,
.cell-final::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cell-name:focus,
.cell-restacks:focus,
.cell-final:focus {
  outline: none;
  border-color: rgba(88, 166, 255, 0.5);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
  background-color: rgba(0, 0, 0, 0.55);
}

.cell-start,
.cell-pnl {
  font-variant-numeric: tabular-nums;
}

.cell-restacks,
.cell-final {
  font-variant-numeric: tabular-nums;
}

.cell-pnl {
  min-width: 5rem;
}

.cell-adjusted {
  min-width: 5rem;
}

.cell-pnl.pnl-win {
  color: var(--win);
  font-weight: 500;
}

.cell-pnl.pnl-loss {
  color: var(--loss);
  font-weight: 500;
}

.cell-settlements {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 0;
  line-height: 1.2;
}

.cell-settlements span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid tbody tr[data-player-id] {
  min-height: 3.15rem;
}

.btn-remove {
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.btn-remove:hover {
  color: var(--loss);
  border-color: var(--loss);
  background: rgba(248, 81, 73, 0.1);
}
