* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #f4f5f7;
  color: #1f2937;
}

a {
  color: inherit;
  text-decoration: none;
}

.navbar {
  height: 64px;
  padding: 0 24px;
  background: #111827;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-left,
.navbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  font-weight: bold;
  font-size: 20px;
  margin-right: 20px;
}

.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
}

.hero,
.page-card,
.auth-card {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.hero h1,
.page-card h1,
.auth-card h1 {
  margin-top: 0;
}

.auth-card {
  max-width: 420px;
  margin: 40px auto;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-form {
  display: inline;
}

label {
  font-weight: bold;
  font-size: 14px;
}

input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 15px;
}

input:focus {
  outline: none;
  border-color: #2563eb;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}

.btn-secondary {
  background: #374151;
  color: #fff;
}

.full-width {
  width: 100%;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.user-pill {
  background: #1f2937;
  color: #fff;
  border: 1px solid #4b5563;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
}

.message {
  padding: 12px;
  border-radius: 8px;
  font-weight: bold;
}

.message.error {
  background: #fee2e2;
  color: #991b1b;
}

.message.success {
  background: #dcfce7;
  color: #166534;
}

.small-link {
  font-size: 14px;
  margin-top: 16px;
}

pre {
  background: #111827;
  color: #e5e7eb;
  padding: 16px;
  border-radius: 10px;
  overflow-x: auto;
}

.form-help {
  margin-top: -6px;
  margin-bottom: 18px;
  font-size: 14px;
  color: #6b7280;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.required {
  color: #dc2626;
}

input.input-error {
  border-color: #dc2626;
  background: #fff7f7;
}

input.input-error:focus {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.field-error {
  display: none;
  color: #dc2626;
  font-size: 13px;
  line-height: 1.3;
}

.field-error.visible {
  display: block;
}

.board-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.board-main-card,
.board-side-card {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.board-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.board-header h1 {
  margin: 0 0 8px 0;
}

.board-header p {
  margin: 0;
  color: #6b7280;
}

.board-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chess-board-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
}

.chess-board {
  width: min(76vw, 640px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border: 4px solid #111827;
  border-radius: 12px;
  overflow: hidden;
  background: #111827;
}

.board-square {
  position: relative;
  border: none;
  padding: 0;
  margin: 0;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-square:focus {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: -3px;
  z-index: 3;
}

.light-square {
  background: #f0d9b5;
}

.dark-square {
  background: #b58863;
}

.piece {
  position: relative;
  z-index: 2;
  user-select: none;
  cursor: grab;
}

.piece:active {
  cursor: grabbing;
}

.piece-img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: auto;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.22));
}

.square-coordinate {
  position: absolute;
  inset: 0;
  z-index: 1;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: clamp(18px, 2.5vw, 32px);
  font-weight: 900;
  letter-spacing: 0.04em;

  color: rgba(17, 24, 39, 0.34);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.25);

  pointer-events: none;
  user-select: none;
}

.dark-square .square-coordinate {
  color: rgba(255, 255, 255, 0.38);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.coordinates-hidden .square-coordinate {
  display: none;
}

.selected-square {
  box-shadow: inset 0 0 0 4px rgba(250, 204, 21, 0.95);
}

.last-move-square {
  box-shadow: inset 0 0 0 4px rgba(234, 179, 8, 0.55);
}

.selected-square.last-move-square {
  box-shadow:
    inset 0 0 0 4px rgba(250, 204, 21, 0.95),
    inset 0 0 0 8px rgba(234, 179, 8, 0.35);
}

.highlight-move::after,
.highlight-capture::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.highlight-move::after {
  width: 34%;
  height: 34%;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.55);
}

.highlight-capture::after {
  inset: 8%;
  border-radius: 12px;
  background: rgba(220, 38, 38, 0.28);
  box-shadow: inset 0 0 0 4px rgba(220, 38, 38, 0.75);
}

.board-side-card h2 {
  margin-top: 0;
}

.info-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.info-label {
  font-size: 13px;
  font-weight: bold;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.info-value {
  font-size: 16px;
  font-weight: bold;
  color: #111827;
}

.fen-output {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  color: #111827;
  background: #f8fafc;
}

.move-history {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  font-family: Consolas, Monaco, monospace;
  font-size: 14px;
}

.history-row {
  display: grid;
  grid-template-columns: 42px 1fr 1fr;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #e5e7eb;
}

.history-row:last-child {
  border-bottom: none;
}

.history-number {
  color: #6b7280;
  font-weight: bold;
}

@media (max-width: 1000px) {
  .board-page {
    grid-template-columns: 1fr;
  }

  .board-header {
    flex-direction: column;
  }

  .board-actions {
    justify-content: flex-start;
  }

  .chess-board {
    width: min(92vw, 640px);
  }
}

@media (max-width: 600px) {
  .board-main-card,
  .board-side-card {
    padding: 16px;
  }

  .board-actions {
    width: 100%;
  }

  .board-actions .btn {
    flex: 1;
  }

  .square-coordinate {
    font-size: 9px;
  }
}

.board-select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
}

.board-create-repertoire {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 18px;
}

.board-message {
  min-height: 20px;
  margin: 8px 0 0 0;
  font-size: 13px;
  font-weight: bold;
}

.board-message.success {
  color: #166534;
}

.board-message.error {
  color: #991b1b;
}

.suggestions-box {
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px;
  min-height: 58px;
  margin-bottom: 18px;
  font-size: 14px;
}

.suggestion-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
}

.suggestion-row:last-child {
  border-bottom: none;
}

.suggestion-row-active {
  background: #ecfdf5;
  border-radius: 6px;
}

.suggestion-from-square {
  box-shadow: inset 0 0 0 5px rgba(34, 197, 94, 0.95);
}

.suggestion-to-square::before {
  content: "";
  position: absolute;
  inset: 8%;
  z-index: 1;
  border-radius: 12px;
  background: rgba(34, 197, 94, 0.28);
  box-shadow: inset 0 0 0 4px rgba(34, 197, 94, 0.85);
  pointer-events: none;
}

.suggestion-from-square.last-move-square {
  box-shadow:
    inset 0 0 0 5px rgba(34, 197, 94, 0.95),
    inset 0 0 0 9px rgba(234, 179, 8, 0.35);
}

@media (max-width: 600px) {
  .board-create-repertoire {
    grid-template-columns: 1fr;
  }
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.suggestion-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.suggestion-delete-btn {
  border: none;
  border-radius: 6px;
  background: #fee2e2;
  color: #991b1b;
  font-weight: bold;
  padding: 6px 8px;
  cursor: pointer;
  align-self: center;
}

.suggestion-delete-btn:hover {
  background: #fecaca;
}

.suggestion-row {
  align-items: center;
}

.suggestion-row {
  cursor: pointer;
}

.suggestion-row:hover {
  background: #f1f5f9;
}

.suggestion-row-active {
  background: #ecfdf5;
  border-left: 4px solid #22c55e;
}

.suggestion-row-active:hover {
  background: #dcfce7;
}

.history-tree {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-tree-row {
  width: 100%;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  border-radius: 8px;
  min-height: 38px;

  display: grid;
  grid-template-columns: 52px 1fr auto auto;
  align-items: center;
  gap: 8px;

  padding: 6px 8px;

  cursor: pointer;
  text-align: left;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
}

.history-tree-row:hover {
  background: #f1f5f9;
}

.history-in-current-line {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.history-current {
  border-color: #22c55e;
  background: #dcfce7;
  box-shadow: inset 4px 0 0 #22c55e;
}

.history-number {
  color: #6b7280;
  font-weight: bold;
}

.history-san {
  color: #111827;
}

.history-uci {
  color: #64748b;
  font-size: 12px;
}

.history-branch-label {
  color: #166534;
  font-size: 11px;
  font-weight: bold;
  background: #bbf7d0;
  border-radius: 999px;
  padding: 3px 7px;
  white-space: nowrap;
}

.history-current .history-branch-label {
  background: #22c55e;
  color: #ffffff;
}

.account-page {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.account-header {
  background: #ffffff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.account-header h1 {
  margin: 0 0 8px 0;
}

.account-header p {
  margin: 0;
  color: #6b7280;
}

.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: start;
}

.account-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.account-card h2 {
  margin-top: 0;
}

.account-meta {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
  font-size: 14px;
  color: #374151;
}

.account-meta p {
  margin: 8px 0;
}

.danger-zone {
  grid-column: 1 / -1;
  border: 1px solid #fecaca;
  background: #fffafa;
}

.danger-zone h2 {
  color: #991b1b;
}

.danger-zone p {
  color: #7f1d1d;
}

@media (max-width: 900px) {
  .account-grid {
    grid-template-columns: 1fr;
  }
}

.training-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.training-main-card,
.training-side-card {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.training-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.training-header h1 {
  margin: 0 0 8px 0;
}

.training-header p {
  margin: 0;
  color: #6b7280;
}

.training-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.training-side-card h2 {
  margin-top: 0;
}

.training-message {
  min-height: 22px;
  margin: 14px 0 20px 0;
  padding: 10px;
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  font-weight: bold;
  font-size: 14px;
}

.training-message.success {
  background: #dcfce7;
  color: #166534;
}

.training-message.error {
  background: #fee2e2;
  color: #991b1b;
}

.training-message.info {
  background: #dbeafe;
  color: #1e40af;
}

.training-score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}

.training-score-box {
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px;
}

.score-label {
  display: block;
  color: #64748b;
  font-size: 12px;
  font-weight: bold;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.training-score-box strong {
  font-size: 22px;
  color: #111827;
}

.expected-moves-box {
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px;
  min-height: 44px;
  font-size: 14px;
}

.expected-move-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #e5e7eb;
}

.expected-move-row:last-child {
  border-bottom: none;
}

.solution-from-square {
  box-shadow: inset 0 0 0 5px rgba(34, 197, 94, 0.95);
}

.solution-to-square::before {
  content: "";
  position: absolute;
  inset: 8%;
  z-index: 1;
  border-radius: 12px;
  background: rgba(34, 197, 94, 0.28);
  box-shadow: inset 0 0 0 4px rgba(34, 197, 94, 0.85);
  pointer-events: none;
}

@media (max-width: 1000px) {
  .training-page {
    grid-template-columns: 1fr;
  }

  .training-header {
    flex-direction: column;
  }

  .training-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 600px) {
  .training-main-card,
  .training-side-card {
    padding: 16px;
  }

  .training-actions {
    width: 100%;
  }

  .training-actions .btn {
    flex: 1;
  }
}

.api-page {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.api-header-card,
.api-card,
.api-doc-card,
.api-token-created {
  background: #ffffff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.api-header-card h1 {
  margin: 0 0 8px 0;
}

.api-header-card p {
  margin: 0;
  color: #6b7280;
}

.api-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 22px;
  align-items: start;
}

.api-card h2,
.api-doc-card h2,
.api-token-created h2 {
  margin-top: 0;
}

.api-token-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.api-token-line input {
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
}

.api-token-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.api-token-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;

  border: 1px solid #e5e7eb;
  background: #f8fafc;
  border-radius: 10px;
  padding: 14px;
}

.api-token-item div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.api-token-item span {
  color: #64748b;
  font-size: 13px;
}

.api-token-revoked {
  opacity: 0.65;
}

.api-doc-card pre {
  overflow-x: auto;
  background: #0f172a;
  color: #e5e7eb;
  padding: 14px;
  border-radius: 10px;
  font-size: 13px;
}

.api-doc-card code {
  font-family: Consolas, Monaco, monospace;
}

@media (max-width: 900px) {
  .api-grid {
    grid-template-columns: 1fr;
  }

  .api-token-item {
    flex-direction: column;
    align-items: stretch;
  }

  .api-token-line {
    grid-template-columns: 1fr;
  }
}