:root {
  --ink: #1b1f1a;
  --muted: #6b7266;
  --line: #d8d2c4;
  --paper: #f6f1e6;
  --sheet: #fffdf8;
  --navy: #14233a;
  --navy-2: #1d3354;
  --gold: #c9a227;
  --win: #1f6b3a;
  --loss: #a33b32;
  --tie: #5c6570;
  --cut: #e8d9a8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--navy);
  color: #f4efe3;
}

.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 6px;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.03em;
  font-weight: 800;
}

.brand small {
  font-size: 10px;
  color: #c7c1b2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48vw;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: 100%;
  padding: 0;
}

.tabs button {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  color: #c7c1b2;
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 0 8px;
  border-bottom: 2px solid transparent;
  letter-spacing: -0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  touch-action: manipulation;
  cursor: pointer;
}

.tabs button.active {
  color: #fff;
  border-bottom-color: var(--gold);
}

.panel {
  display: none;
  padding: 8px 8px 16px;
}

.panel.active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

#panel-sim .toolbar {
  flex-direction: column;
}

.meta {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 7px;
  border-radius: 4px;
}

.btn:disabled {
  opacity: 0.45;
}

.btn-primary {
  background: var(--navy);
  color: #f4efe3;
  border-color: var(--navy);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 8px 0;
  font-size: 11px;
  font-weight: 700;
}

.field input,
.field select {
  font: inherit;
  font-weight: 500;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--sheet);
}

.field.inline {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.mc-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
}

.mc-toolbar .field.inline select {
  min-height: 40px;
}

#mc-team,
#hist-team {
  min-width: 4.8em;
  max-width: 6.5em;
}

.hist-bar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 4px;
  margin: 4px 0;
  align-items: stretch;
}

.hist-bar .field.inline {
  min-width: 0;
}

.hist-bar select,
.hist-bar #hist-team,
.hist-bar #hist-bucket {
  min-width: 0;
  max-width: none;
  width: 100%;
  min-height: 36px;
  padding: 4px 2px;
  font-size: 12px;
}

.hist-toggles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 4px 0;
}

.hist-months {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.hist-bar button,
.hist-toggles button {
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--sheet);
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 0;
  letter-spacing: -0.04em;
  touch-action: manipulation;
  cursor: pointer;
}

.hist-months button {
  font-size: 11px;
  letter-spacing: -0.06em;
}

.hist-bar button {
  font-size: 10px;
  padding: 4px 1px;
  white-space: nowrap;
}

.hist-bar button.on {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.hist-months button {
  background: #f3ead2;
  border-color: #c9b27a;
  color: #6d5620;
}

.hist-months button.on {
  background: #8d6b1f;
  border-color: #8d6b1f;
  color: #fffaf0;
}

.mc-toolbar .btn {
  flex: 1 0 auto;
  min-height: 40px;
  touch-action: manipulation;
}

.mc-cards {
  display: grid;
  grid-template-columns: repeat(var(--mc-card-cols, 4), minmax(0, 1fr));
  gap: 4px;
  margin: 6px 0 2px;
}

.mc-card {
  background: #fff9f7;
  border: 1px solid #f0d6d2;
  border-radius: 6px;
  padding: 6px 3px 7px;
  text-align: center;
  min-width: 0;
}

.mc-card.max {
  border-color: #c53030;
  box-shadow: 0 0 0 1px #c53030;
}

.mc-card-k {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: var(--mc-muted, #8a6a66);
  letter-spacing: -0.02em;
}

.mc-card b {
  display: block;
  margin: 2px 0 1px;
  font-size: 15px;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.mc-card small {
  display: block;
  font-size: 9px;
  font-weight: 500;
  color: var(--mc-muted, #8a6a66);
  letter-spacing: -0.03em;
}

.mc-cards-note {
  margin: 0 0 6px;
  font-size: 10px;
  color: var(--muted);
}

.hist-caption {
  margin: 2px 0 4px;
}

.hist-chart {
  width: 100%;
  height: auto;
  display: block;
}

.hist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.hist-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hist-legend span.on {
  font-weight: 800;
  color: var(--ink, #2b2722);
}

.hist-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.mc-block {
  margin: 10px 0 12px;
}

.mc-block h3 {
  margin: 0 0 2px;
  font-size: 12px;
}

table.slim tbody tr.mc-focus td {
  background: color-mix(in srgb, var(--mc-focus, #c30452) 9%, #fff);
}

table.slim tbody tr.mc-focus td.team {
  background: color-mix(in srgb, var(--mc-focus, #c30452) 16%, #fff);
  box-shadow: inset 3px 0 0 var(--mc-focus, #c30452);
}

.mc-meta {
  margin: 0 0 4px;
  font-size: 10px;
  color: var(--muted);
}

table.slim td.mc-p1 {
  font-weight: 800;
}

.admin-log {
  min-height: 1.4em;
  margin-top: 8px;
  white-space: pre-wrap;
}

code {
  font-size: 10px;
  background: #efe8d8;
  padding: 1px 3px;
  border-radius: 3px;
}

table.slim thead th.sortable {
  cursor: pointer;
  user-select: none;
}

table.slim thead th.sortable:hover {
  color: var(--ink);
}

table.slim thead th.sorted::after {
  content: attr(data-dir);
  margin-left: 2px;
  color: var(--gold);
}

.ladder {
  display: grid;
  grid-template-columns: 32px 1fr 1fr 1fr 1fr;
  gap: 3px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 4px 6px;
  overflow-x: auto;
}

.ladder-head {
  font-size: 10px;
  font-weight: 800;
  text-align: center;
  padding: 2px 0 6px;
}

.ladder-col {
  position: relative;
}

.ladder-axis {
  position: relative;
}

.ladder-tick {
  position: absolute;
  left: 0;
  right: 0;
  font-size: 9px;
  color: var(--muted);
  transform: translateY(-50%);
}

.ladder-cell {
  position: absolute;
  left: 0;
  right: 0;
  border: 1px solid var(--line);
  border-left: 3px solid var(--navy);
  background: #fffdf8;
  border-radius: 2px;
  padding: 0 2px;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.ladder-cell.focus {
  font-weight: inherit;
}

.ladder-wl {
  font-weight: 800;
  color: var(--ink);
}

.ladder-wp {
  font-weight: 400;
  color: #8a8374;
}

.remain-board {
  margin: 6px 0 4px;
}

.remain-board h3 {
  margin: 0 0 2px;
  font-size: 11px;
}

.remain-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr));
  width: 100%;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.remain-cell {
  padding: 2px 1px;
  background: var(--sheet);
  text-align: center;
  font-size: 9px;
  line-height: 1.1;
  letter-spacing: -0.04em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remain-cell.name {
  font-weight: 800;
  background: #efe8d8;
}

.remain-cell.rec {
  color: var(--muted);
}

.remain-cell.empty {
  color: #ccc;
}

.contrib {
  overflow-x: auto;
  padding-bottom: 4px;
}

.contrib-grid {
  display: grid;
  grid-template-columns: 32px repeat(31, 12px);
  gap: 2px;
  width: max-content;
  align-items: center;
}

.contrib-corner,
.contrib-day,
.contrib-month {
  font-size: 9px;
  line-height: 12px;
  color: var(--muted);
  text-align: center;
}

.contrib-month {
  position: sticky;
  left: 0;
  text-align: right;
  padding-right: 4px;
  background: var(--paper);
}

.contrib-cell {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #ebedf0;
}

.contrib-cell.out {
  background: transparent;
}

.contrib-cell.lv1 {
  background: #9be9a8;
}

.contrib-cell.lv2 {
  background: #40c463;
}

.contrib-cell.lv3 {
  background: #30a14e;
}

.contrib-cell.lv4 {
  background: #216e39;
}

a.contrib-cell {
  text-decoration: none;
}

.contrib-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--muted);
}

.hint {
  margin: 0 0 4px;
  font-size: 10px;
  color: var(--muted);
}

.tab-notes {
  margin-top: 14px;
}

.tab-notes .hint {
  margin: 0;
  line-height: 1.45;
}

.tab-notes .hint + .hint {
  margin-top: 6px;
}

.legend {
  margin: 0 0 5px;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.35;
}

.section h3 {
  margin: 10px 0 4px;
  font-size: 12px;
  letter-spacing: -0.02em;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
  gap: 8px;
  margin: 8px 0;
}

.formula-col {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 7px 8px;
}

.formula-col h3 {
  margin: 0 0 4px;
}

.formula {
  margin: 3px 0;
  padding: 3px 4px;
  background: #f6f1e6;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow-x: auto;
}

.formula .katex,
.formula .katex-display {
  margin: 0;
  font-size: 8.5px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
}

table.slim {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  line-height: 1.1;
  table-layout: auto;
}

table.slim th,
table.slim td {
  padding: 2px 3px;
  border-bottom: 1px solid #eee8da;
  white-space: nowrap;
  text-align: center;
  vertical-align: middle;
}

table.slim thead th {
  background: #efe8d8;
  font-size: 9px;
  font-weight: 800;
  color: #4d5348;
  position: sticky;
  top: 0;
  letter-spacing: -0.02em;
}

table.slim td.team,
table.slim th.team,
table.slim td.rank,
table.slim th.rank {
  text-align: left;
}

table.slim td.rank,
table.slim th.rank {
  width: 18px;
  padding-left: 3px;
}

table.slim td.team,
table.slim th.team {
  width: 3.6em;
}

table.slim .sticky-1,
table.slim .sticky-2 {
  position: sticky;
  background: var(--sheet);
  z-index: 1;
}

table.slim thead .sticky-1,
table.slim thead .sticky-2 {
  background: #efe8d8;
  z-index: 2;
}

table.slim .sticky-1 {
  left: 0;
}

table.slim .sticky-2 {
  left: 16px;
}

table.slim tbody tr.total {
  background: #f3eee2;
  font-weight: 700;
}

table.slim tbody tr.moved-up td.rank {
  color: var(--win);
}

table.slim tbody tr.moved-down td.rank {
  color: var(--loss);
}

.team-cell {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 800;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mini-btns {
  display: inline-flex;
  gap: 2px;
}

.chip {
  appearance: none;
  border: 0;
  width: 22px;
  height: 20px;
  padding: 0;
  border-radius: 3px;
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
}

.chip.win {
  background: var(--win);
}

.chip.loss {
  background: var(--loss);
}

.chip.tie {
  background: var(--tie);
}

.chip.undo {
  background: #8a8374;
}

.chip:disabled {
  opacity: 0.3;
}

.section {
  margin-top: 12px;
}

.section h2 {
  margin: 0 0 4px;
  font-size: 13px;
  letter-spacing: -0.02em;
}

.section .src {
  display: block;
  margin: 0 0 4px;
  font-size: 10px;
  color: var(--muted);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-live {
  color: var(--win);
  font-weight: 700;
}

.status-snap {
  color: #9a6b12;
  font-weight: 700;
}

.empty {
  padding: 18px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

@media (min-width: 720px) {
  .panel {
    max-width: 980px;
    margin: 0 auto;
    padding: 12px 16px 24px;
  }

  .brand,
  .tabs {
    max-width: 980px;
    margin: 0 auto;
  }
}
