:root {
  --lobby-bg: radial-gradient(circle at top, #e8f0ff 0%, #f7f7fb 40%, #fdfdfd 100%);
  --card-bg: #ffffff;
  --card-shadow: 0 24px 60px rgba(15, 23, 42, 0.15);
  --accent: #1f6feb;
  --accent-dark: #1a4fbf;
  --text-main: #0f172a;
  --text-muted: #5b6478;
}

body {
  margin: 0;
  font-family: 'Noto Sans', 'Roboto', system-ui, -apple-system, sans-serif;
  background: var(--lobby-bg);
  color: var(--text-main);
}

.lobby {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.lobby-card {
  background: var(--card-bg);
  padding: 40px 48px;
  border-radius: 20px;
  box-shadow: var(--card-shadow);
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.lobby-card h1 {
  margin: 0 0 8px;
  font-size: 32px;
}

.lobby-subtitle {
  margin: 0 0 24px;
  color: var(--text-muted);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lobby-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid #cbd5f0;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 600;
  background: #f8fafc;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.lobby-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(30, 64, 175, 0.15);
}

.lobby-button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.lobby-button.primary:hover {
  background: var(--accent-dark);
}

.match {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 20px;
}

.lobby-start {
  min-height: 620px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url('images/start-bg-board.png') center/contain no-repeat;
  position: relative;
}

.lobby-start::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.lobby-start-card {
  position: relative;
  z-index: 1;
  text-align: center;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.lobby-start-card h1 {
  margin: 0 0 18px;
  font-size: 28px;
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.lobby-start-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lobby-start-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: 999px;
  background: #2ea9d4;
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.lobby-start-btn:hover {
  background: #2595bf;
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

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

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.match-meta {
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px 16px;
  font-size: 14px;
  background: #ffffff;
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.meta-label {
  color: var(--text-muted);
  font-weight: 600;
}

.meta-value {
  font-weight: 600;
}

.match-board {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
}

.board-wrap {
  width: 520px;
  height: 520px;
}

.cg-512 .cg-wrap {
  width: 520px;
  height: 520px;
}

.cg-512 {
  flex-shrink: 0;
}

.cg-wrap piece {
  width: 12.5%;
  height: 12.5%;
  top: 0;
  left: 0;
}

.moves-panel {
  width: 240px;
  height: 520px;
  background: #2b4f6d;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #ffffff;
  flex-shrink: 0;
}

.rail-top {
  flex: 0 0 auto;
}

.rail-top-bar {
  background: #2f7fd1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 2px solid rgba(255,255,255,0.2);
}

.rail-clock-time {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 2px;
  background: #2b4f6d;
  color: #ffffff;
  border: 2px solid #ffffff;
  padding: 4px 6px;
}

.rail-status {
  background: linear-gradient(180deg, #f39c12, #e67e22);
  padding: 8px 12px;
  text-align: center;
  font-weight: 800;
  border-top: 1px solid rgba(255,255,255,0.3);
  border-bottom: 1px solid rgba(0,0,0,0.2);
  flex: 0 0 auto;
}

.rail-controls {
  background: #2b4f6d;
  border-bottom: 1px solid #1e3a54;
  flex: 0 0 auto;
}

.moves-controls {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: transparent;
  border-bottom: 1px solid #1e3a54;
}

.move-btn {
  flex: 1;
  border: 1px solid #6c8aa3;
  background: transparent;
  color: #ffffff;
  padding: 6px 0;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

.move-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.rail-header {
  padding: 8px 12px;
  font-weight: 700;
  border-bottom: 1px solid #1e3a54;
  flex: 0 0 auto;
}

.rail-moves {
  padding: 0 10px 8px;
  flex: 1 1 auto;
  min-height: 0;
}

.moves-panel .replay .moves {
  height: 100%;
  overflow-y: auto;
  border-top: none;
  border-bottom: none;
}

.rail-moves .lichess_ground,
.rail-moves .replay,
.rail-moves .moves {
  height: 100%;
}

.rail-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #1e3a54;
  flex: 0 0 auto;
}

.rail-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #9db3c5;
  color: #ffffff;
  background: transparent;
  text-decoration: none;
  font-weight: 700;
}

.rail-bottom {
  margin-top: 0;
  background: #2f7fd1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 2px solid rgba(255,255,255,0.2);
  flex: 0 0 auto;
}

.rail-clock-time.bottom {
  border: 2px solid #ffffff;
  padding: 4px 6px;
  font-size: 20px;
  letter-spacing: 2px;
  background: #2b4f6d;
  color: #ffffff;
}

.rail-clock-time.active {
  background: #f3dd62;
  color: #1b1b1b;
}

.rail-label {
  font-weight: 800;
  font-size: 16px;
}

.rail-moves .moves {
  height: 110px;
  overflow-y: auto;
}

.rail-actions {
  margin-top: 8px;
}

.rail-turn {
  font-weight: 800;
  font-size: 16px;
}

@media (max-width: 900px) {
  .match-board {
    flex-direction: column;
    align-items: center;
  }

  .moves-panel {
    width: min(90vw, 420px);
  }
}

body.blue .is2d .cg-board {
  background-image: url('../images/board/8x8blue.svg');
}

.match-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.friend-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.friend-card {
  background: #ffffff;
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.friend-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.friend-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.friend-modal-card {
  width: min(720px, 92vw);
  background: #ffffff;
  border-radius: 8px;
  padding: 24px 28px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.friend-modal-card h2 {
  margin: 0 0 18px;
  font-size: 22px;
  color: #555;
  letter-spacing: 1px;
}

.friend-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: #ffffff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
}

.friend-modal-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: start;
}

.friend-modal-divider {
  font-weight: 700;
  color: #9aa3ad;
  margin-top: 60px;
}

.friend-modal-section {
  border: 1px solid #d4d8dd;
  padding: 16px;
  border-radius: 6px;
  background: #f8f9fb;
  min-height: 240px;
}

.friend-modal-section h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: #777;
}

.friend-modal-section p {
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 12px;
}

.friend-modal-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid #c7cdd4;
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 2px;
}

.friend-modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid #5ec1e6;
  background: #5ec1e6;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.friend-modal-btn.primary {
  background: #2ea9d4;
  border-color: #2ea9d4;
}

.friend-modal-code {
  margin-top: 12px;
}

.friend-modal-code.hidden {
  display: none;
}

.friend-modal-code-box {
  display: flex;
  justify-content: center;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.friend-modal-code-box span {
  background: #eeeeee;
  border: 1px solid #c7cdd4;
  padding: 10px 18px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
}

.friend-modal-copy {
  padding: 10px 14px;
  border: 1px solid #c7cdd4;
  background: #f3f4f6;
  cursor: pointer;
  font-weight: 700;
}

.friend-modal-note {
  font-size: 13px;
  color: #6b7280;
}

.friend-modal-status {
  margin-top: 12px;
  font-weight: 700;
  color: #b91c1c;
  min-height: 18px;
}

.friend-modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.friend-modal-cancel {
  border: 1px solid #d1d5db;
  background: #f9fafb;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 700;
  color: #666;
}

.friend-card p {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.friend-join {
  display: flex;
  gap: 10px;
  align-items: center;
}

.friend-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5f0;
  font-size: 14px;
}

.private-code {
  margin-top: 12px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--accent);
}

.game-status {
  color: var(--text-muted);
  font-weight: 600;
}

@media (max-width: 700px) {
  .match {
    padding: 16px;
  }

  .match-header {
    flex-direction: column;
  }

  .board-wrap {
    width: min(90vw, 420px);
    height: min(90vw, 420px);
  }
}
