:root {
  color-scheme: light;
  --ink: #1f2722;
  --muted: #69736d;
  --line: #d9dfda;
  --paper: #f4f6f3;
  --surface: #ffffff;
  --green: #315f4e;
  --green-soft: #e8f0eb;
  --gold: #b88436;
  --red: #a34b43;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button {
  min-height: 38px;
  padding: 0 15px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--green);
  font-weight: 750;
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: wait; }

.admin-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px max(20px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
}

.brand-block, .header-actions, .system-state { display: flex; align-items: center; }
.brand-block { gap: 11px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #fff;
  background: var(--green);
  font-family: serif;
  font-size: 22px;
  font-weight: 900;
}
.brand-block div { display: grid; gap: 2px; }
.brand-block strong { font-size: 16px; }
.brand-block span:last-child { color: var(--muted); font-size: 12px; }
.header-actions { gap: 9px; }
.header-actions a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  text-decoration: none;
  font-weight: 750;
}
.quiet-button { color: var(--green); background: transparent; border: 1px solid var(--line); }
.system-state { gap: 7px; margin-right: 4px; color: var(--muted); font-size: 13px; }
.system-state i { width: 8px; height: 8px; border-radius: 50%; background: #a8afa9; }
.system-state i.online { background: #3e8c67; box-shadow: 0 0 0 4px rgba(62, 140, 103, .12); }
.system-state i.error { background: var(--red); }

.admin-shell { width: min(1240px, calc(100vw - 36px)); margin: 0 auto; padding: 34px 0 60px; }
.dashboard[hidden], .login-panel[hidden], .drawer-backdrop[hidden] { display: none; }

.login-panel { min-height: calc(100vh - 150px); display: grid; place-items: center; }
.login-panel form {
  width: min(390px, 100%);
  display: grid;
  gap: 15px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(36, 54, 43, .08);
}
.login-panel p, .page-heading p, .section-title p, .drawer-head p { margin: 0; color: var(--green); font-size: 12px; font-weight: 850; }
.login-panel h1, .page-heading h1, .section-title h2, .drawer-head h2 { margin: 4px 0 0; letter-spacing: 0; }
.login-panel h1 { font-size: 25px; }
.login-panel label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 750; }
.login-panel input, .table-tools input, .table-tools select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
.login-panel input:focus, .table-tools input:focus, .table-tools select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(49, 95, 78, .1); }
.login-panel small { min-height: 18px; color: var(--muted); }
.login-panel small.error { color: var(--red); }

.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-heading h1 { font-size: 30px; }
.updated-time { color: var(--muted); font-size: 13px; }
.updated-time strong { color: var(--ink); }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.metric-grid article {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.metric-grid span, .metric-grid small { display: block; color: var(--muted); font-size: 12px; }
.metric-grid strong { display: block; margin: 7px 0 5px; color: var(--green); font-size: 30px; font-variant-numeric: tabular-nums; }

.data-section { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.section-title h2 { font-size: 20px; }
.section-title > span { color: var(--muted); font-size: 12px; }
.table-tools { display: flex; align-items: center; gap: 8px; }
.table-tools input { width: 210px; }

.online-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.online-person {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
  box-shadow: none;
  cursor: pointer;
}
.online-person i, .status-dot { width: 8px; height: 8px; border-radius: 50%; background: #3e8c67; }
.online-person div { min-width: 0; display: grid; gap: 3px; }
.online-person strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-person span, .online-person small { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 15px; border-bottom: 1px solid #e8ece8; text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #fafbf9; font-size: 11px; font-weight: 800; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfa; }
.user-cell { display: grid; gap: 3px; }
.user-cell small, .device-cell, .muted-cell { color: var(--muted); }
.status-cell { display: inline-flex; align-items: center; gap: 7px; }
.status-cell.offline .status-dot { background: #aeb5af; }
.detail-button { min-height: 30px; padding: 0 10px; color: var(--green); background: var(--green-soft); box-shadow: none; }
.empty-state { padding: 24px; text-align: center; color: var(--muted); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 19; background: rgba(22, 31, 26, .22); }
.user-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(450px, 94vw);
  height: 100vh;
  padding: 24px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 45px rgba(30, 45, 36, .12);
  transform: translateX(102%);
  transition: transform .2s ease;
}
.user-drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.drawer-head button { width: 38px; padding: 0; color: var(--green); background: var(--green-soft); font-size: 24px; }
.detail-content { display: grid; gap: 22px; padding-top: 20px; }
.detail-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.detail-summary div { padding: 12px; border-radius: 6px; background: var(--paper); }
.detail-summary span { display: block; color: var(--muted); font-size: 11px; }
.detail-summary strong { display: block; margin-top: 5px; font-size: 18px; }
.detail-block h3 { margin: 0 0 10px; font-size: 14px; }
.detail-list { display: grid; gap: 0; margin: 0; }
.detail-list div { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid #edf0ed; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; }

.game-list, .move-timeline { display: grid; gap: 8px; }
.game-row {
  min-height: 58px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  text-align: left;
  box-shadow: none;
}
.game-row > span:nth-child(2) { min-width: 0; display: grid; gap: 3px; }
.game-row small { color: var(--muted); font-size: 11px; }
.game-row b { color: var(--muted); font-size: 11px; }
.game-result {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #7d8981;
  font-weight: 900;
}
.game-result.win { background: var(--green); }
.game-result.loss { background: var(--red); }
.game-result.draw { background: var(--gold); }
.back-button { justify-self: start; min-height: 34px; color: var(--green); background: var(--green-soft); box-shadow: none; }
.move-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-left: 3px solid #c1c9c3;
  background: var(--paper);
}
.move-row.red { border-left-color: var(--red); }
.move-row.black { border-left-color: #303834; }
.move-row > span { color: var(--muted); font-size: 11px; line-height: 1.45; }
.move-row > div { min-width: 0; display: grid; gap: 3px; }
.move-row strong { font-size: 13px; }
.move-row small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.move-row > b { text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.move-row > b.positive { color: var(--green); }
.move-row > b.negative { color: var(--red); }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .online-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .system-state { display: none; }
}

@media (max-width: 620px) {
  .admin-header { align-items: flex-start; padding: 10px 12px; }
  .brand-block span:last-child, .header-actions .quiet-button { display: none; }
  .header-actions { gap: 5px; }
  .header-actions a, .header-actions button { min-height: 36px; padding: 0 9px; font-size: 12px; }
  .admin-shell { width: calc(100vw - 24px); padding-top: 22px; }
  .page-heading { align-items: start; }
  .page-heading h1 { font-size: 25px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid article { padding: 14px; }
  .metric-grid strong { font-size: 25px; }
  .online-list { grid-template-columns: 1fr; }
  .users-title { align-items: stretch; flex-direction: column; }
  .table-tools { display: grid; grid-template-columns: 1fr 120px; }
  .table-tools input { width: auto; min-width: 0; }
  th, td { padding: 11px 12px; }
  .detail-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
