:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #6b7682;
  --line: #e8edf3;
  --accent: #3a7afe;
  --accent-soft: #eaf1ff;
  --shadow: 0 8px 30px rgba(23, 32, 42, 0.06);
}

body.dark {
  --bg: #0f141a;
  --panel: #151c24;
  --text: #e8eef5;
  --muted: #9aabba;
  --line: #2a3643;
  --accent: #4d8dff;
  --accent-soft: #1a2636;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

body.modal-open {
  overflow: hidden;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 44px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 34px;
}

.header p {
  margin: 0;
  color: var(--muted);
}

.muted-links {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.muted-links a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}

.muted-links a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.muted-links .dot {
  color: var(--line);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  margin-top: 18px;
  box-shadow: var(--shadow);
}

.status {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) 180px;
  gap: 14px;
  align-items: end;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input[type="text"],
textarea,
input[type="file"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}

input[type="text"],
input[type="file"],
select,
button {
  height: 44px;
}

textarea {
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
  align-self: end;
}

button:hover {
  opacity: 0.92;
}

.player-link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 0;
  height: auto;
  font: inherit;
  cursor: pointer;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--accent-soft);
  min-height: 88px;
}

.card .key {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.card .value {
  font-size: 22px;
  font-weight: 700;
}

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

.subcontrols {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.7fr 180px;
  gap: 12px;
  margin-bottom: 12px;
  align-items: end;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: auto;
}

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 11px 10px;
  white-space: nowrap;
}

thead th {
  color: var(--muted);
  font-weight: 600;
}

.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(980px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
}

.modal-summary {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

#playerTrendChart {
  width: 100%;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  background: #fff;
}

.positive {
  color: #1f9d55;
  font-weight: 600;
}

.negative {
  color: #d64545;
  font-weight: 600;
}

.neutral {
  color: #7a8794;
  font-weight: 600;
}

.saved-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.round-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.round-btn {
  min-width: 38px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-weight: 700;
  padding: 0 10px;
}

.round-btn.nav {
  min-width: 34px;
  font-weight: 600;
}

.round-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.saved-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--text);
  padding: 12px;
  text-align: left;
  height: auto;
  min-height: 92px;
}

.saved-item .title {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

.saved-item .meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.name-with-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.flag-emoji {
  font-size: 15px;
  line-height: 1;
  display: inline-block;
  width: 18px;
  text-align: center;
  flex: 0 0 auto;
}

.viewer-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
  align-items: start;
}

#gameModal .modal-card {
  max-height: 88vh;
  overflow: hidden;
}

#gameModal .viewer-layout > div:first-child {
  position: sticky;
  top: 0;
}

#gameModal .viewer-layout {
  height: 520px;
}

.viewer-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(90px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
  align-items: end;
}

.viewer-controls button {
  height: 38px;
}

.viewer-controls label {
  font-size: 12px;
}

.viewer-controls select {
  height: 38px;
}

.game-board {
  width: 320px;
  height: 320px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  background-image: url("https://assets-themes.chess.com/image/46oep/200.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.board-piece {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  display: grid;
  place-items: center;
  font-size: 28px;
  user-select: none;
  line-height: 1;
}

.moves-list {
  height: 440px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.move-btn {
  background: #fff !important;
  color: var(--text) !important;
  border: 1px solid var(--line) !important;
  margin: 2px;
  padding: 4px 8px !important;
  height: auto !important;
  min-height: 28px;
  font-weight: 500;
  border-radius: 8px;
  display: inline-block;
}

.move-btn.active {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: var(--text) !important;
}

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

  .subcontrols {
    grid-template-columns: 1fr;
  }

  .viewer-layout {
    grid-template-columns: 1fr;
  }

  .viewer-controls {
    grid-template-columns: 1fr;
  }

  .game-board {
    width: 100%;
    max-width: 360px;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  button {
    width: 100%;
  }
}

@media print {
  button,
  .controls,
  .subcontrols,
  .status,
  #playerModal {
    display: none !important;
  }
  .panel {
    box-shadow: none;
    page-break-inside: avoid;
  }
}
