: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;
}
*{
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
.chess-main{
  width: 100%;
  display: flex;
  gap: 16px;
  height: 100%;
}
.chess-right-side{
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.chess-right-side-bottom{
  background: #162b3c;
  border-radius: 6px 6px 0 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 0;
}
.player-active-block {
    background: #294d6d none repeat scroll 0 0;
    color: #ffffff;
    margin-top: 0;
    padding: 18px;
    width: 100%;
    margin-bottom: 15px;
    text-align: left;
    flex-shrink: 0;
}
.player-active-block>p {
    font-size: 14px;
    letter-spacing: 0.5px;
}
.player-active-block span {
    font-size: 18px;
    padding-right: 7px;
    font-weight: bold;
}
.video-sidebar-container-header{
    height: 60px;
    background-color: #016066;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    font-size: 16px;
    flex-shrink: 0;
}
.video-sidebar-container-header h1 {
    position: relative;
    top: 52%;
    transform: translateY(-50%);
    text-transform: uppercase;
    color: #a5d1c2;
    font-weight: bold;
    line-height: 19px;
    text-align: center;
    padding: 0 10px;
}



.video-sidebar-items{
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 5px;
    gap: 10px;
    min-height: 0;
  }

.video-sidebar-item {
    flex: 1;
    min-height: 0;
    background: #1c3548;
    overflow: hidden;
    border-radius: 5px;
    width: 100%;
}
  .video-sidebar-item a{
    display: flex;
    align-items: center;
    height: 100%;
    flex-direction: row;
    justify-content: flex-start;
    gap: 15px;
  }
.video-sidebar-item img {
    border: 2px solid #FFF;
    opacity: 0.7;
    max-width: 100%;
    max-height: 100%;
}

.video-sidebar-item h2 {
    font-size: 14px;
    color: #fff;
    text-align: left;
}
.video-sidebar-item:hover h2{
    color: #5ccffb;
}
.video-sidebar-item:hover img {
    border: 2px solid #5ccffb;
    opacity: 1.0;
}

.all-videos-link {
    text-align: center;
    display: none;
    margin: 5px 0 8px;
}
.all-videos-link a {
    position: relative;
    display: inline-block;
    color: #000 !important;
    padding: 10px 15px;
    border-radius: 5px;
    font-weight: bold;
    z-index: 0;
    overflow: hidden;
}
.all-videos-link a:before,
.all-videos-link a:after{
  content: '';
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
}
.all-videos-link a:before{
  background: #DFCE07;
  z-index: -2;
  border-radius: 5px;
  width: 100%;
}
.all-videos-link a:after{
  z-index: -1;
  border-radius: 0 10px 10px 0;
  transition-property: all;
  transition-timing-function: cubic-bezier(.4, 0, .2, 1);
  transition-duration: .3s;
  animation-duration: .3s;
  width: 0;
}
.all-videos-link a:hover:after{
    background: #FFE420;
    width: calc(100% + 20px);
}
.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-placeholder{
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: hidden;
}
.lobby-placeholder::after {
  width: 100%;
  height: 100%;
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.7);
}
.lobby-start {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url('images/start-bg-board.jpg') center/100% 100% no-repeat;
  position: relative;
}

.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: 24px;
  font-weight: bold;
  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;
  cursor: pointer;
  text-indent: -9999px;
  height: 40px;
  width: 242px;
  border: 0;
  outline: none;
  background-size: 566px !important;
}
button.random-opponent{
    background: url(./images/chessgame_image.png) no-repeat;
    background-position: -316px -10px;
}
button.random-opponent:hover{
  background-position: -306px -68px;
}
button.vs-computer{
    background: url(./images/chessgame_image.png) no-repeat;
    background-position: -6px -94px;
}
button.vs-computer:hover{
  background-position: -6px -152px;
}
a.play-with-friend{
    background: url(./images/chessgame_image.png) no-repeat;
    background-position: -6px -209px;
}
a.play-with-friend:hover{
     background-position: -6px -267px;
}
.lobby-start-btn.stats-btn {
  text-indent: 0;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 16px; 
  font-weight: 700;
  letter-spacing: 1px;
  text-decoration: none;
  background: #2ea9d4;
  border-radius: 24px;
  border: 3px solid rgba(255, 255, 255, 0.6);
}
.lobby-start-btn.stats-btn:hover {
  background: #3bbbe9;
}


.ai-modal,
.random-modal,
.friend-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
}

.ai-modal-close,
.random-modal-close,
.friend-modal-close{
  position: absolute;
  top: -15px;
  right: -8px;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  background: url(./images/close_button.png);
  text-indent: -9999px;
  background-size: 100%;
}

.ai-modal-section {
  margin-bottom: 18px;
}

.ai-modal-section h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: #7a7a7a;
  font-weight: 700;
}

.ai-levels {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f2f4f7;
}

.ai-level-btn {
  background: #ffffff;
  border: 1px solid #d1d5db;
  padding: 8px 0;
  font-weight: 700;
  color: #6b7280;
  cursor: pointer;
}
.ai-level-btn:hover{
  border-color: #7cc6e8;
}

.ai-level-btn.active {
  background: #5ec1e6;
  border-color: #5ec1e6;
  color: #ffffff;
}

.ai-colors {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.ai-color-btn {
  width: 76px;
  height: 64px;
  border: 2px solid #d1d5db;
  background: #ffffff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.ai-color-btn:hover{
  border-color: #7cc6e8;
}

.ai-color-btn.active {
  border-color: #7cc6e8;
  box-shadow: inset 0 0 0 2px #7cc6e8;
}

.ai-color-icon {
  display: block;
  width: 40px;
  height: 40px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.ai-color-icon.white {
  background-image: url('images/pieces/merida/wK.svg');
}

.ai-color-icon.black {
  background-image: url('images/pieces/merida/bK.svg');
}

.ai-color-icon.random {
  background-image: url('images/pieces/merida/random.svg');
  position: relative;
}

/* .ai-color-icon.random::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('images/pieces/merida/bK.svg');
  background-size: 70%;
  background-repeat: no-repeat;
  background-position: 70% 60%;
  opacity: 0.9;
} */

.ai-start-btn {
  margin-top: 8px;
  padding: 10px 24px;
  border-radius: 999px;
  border: 2px solid #5ec1e6;
  background: #5ec1e6;
  color: #ffffff;
  font-weight: bold;
  letter-spacing: 1px;
  cursor: pointer;
}
.ai-start-btn:hover{
  background: #429abc;
}

.random-modal-card,
.ai-modal-card,
.friend-modal-card {
  width: 96%;
  background: #ffffff;
  padding: 15px;
  position: relative;
  text-align: center;
  border-radius: 8px;
  max-width: 600px;
}
.random-modal-card h2,
.ai-modal-card h2,
.friend-modal-card h2 {
  margin: 0 0 15px;
  font-size: 19px;
  color: #666666;
  letter-spacing: 1px;
}

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

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

.random-modal-section {
  text-align: left;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.inner-fields{
  border: 1px solid #d1d5db;
  padding: 10px 12px 5px;
}

.random-modal-section h3 {
  margin: 0 0 8px;
  text-align: center;
  font-size: 16px;
  color: #777;
}

.random-table {
  border: 1px solid #d1d5db;
  overflow: hidden;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  /* height: calc(100% - 72px); */
  margin-bottom: 8px;
  flex: 1;
}

.random-table-header {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr 0.8fr;
  gap: 8px;
  padding: 10px 12px;
  background: #f1f5f9;
  font-weight: 700;
  color: #6b7280;
  text-align: center;
}

.random-table-body {
  flex: 1 1 auto;
  min-height: 48px;
  overflow-y: auto;
  max-height: 277px;
}

.random-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr 0.8fr;
  gap: 8px;
  padding: 5px 12px;
  border: 0;
  border-bottom: 1px solid #d1d5db;
  background: #ffffff;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  width: 100%;
}
.random-row:last-of-type{
  border-bottom: 0;
}
.random-row:hover{
  background: rgba(200, 255, 200, 0.7);
}

.random-row.active {
  background: #d1fae5;
}

.random-cell {
  color: #4b5563;
  line-height: 28px;
  text-align: center;
}
.random-cell.random-cell-speed{
  color: #23b0db
}

.random-cell-level{
  text-indent: -9999px;
  margin: auto;
  width: 28px;
  height: 28px;
}

.random-cell-level.beginner{
  background: url('./images/b1t.png') no-repeat center/100%;
}
.random-cell-level.medium{
  background: url('./images/b2t.png') no-repeat center/100%;
}
.mobile .random-color-btn{
  height: 57px;
}
.mobile .ai-color-icon{
  width: 35px;
  height: 35px;
}
.random-cell-level.advanced{
  background: url('./images/b3t.png') no-repeat center/100%;
}
.random-cell.color-cell{
  font-size: 0;
  position: relative;
}
.random-cell.color-cell:before{
    content: '';
    width: 11px;
    height: 11px;
    box-shadow:  0 0 0 2px #4b5563;
    border-radius: 50%;
    display: inline-block;
    position: relative;
    top: 6px;
}
.random-cell.color-cell.R:after{
  content: '';
  position: absolute;
  width: 6px;
  height: 11px;
  border-radius: 0 9px 9px 0;
  margin: 9px 0 0 -6px;
}
.random-cell.R::after{
    background: #4b5563;
}
.random-cell.B::before{
    background: #4b5563;
}

.random-empty {
  padding: 16px;
  text-align: center;
  color: #9ca3af;
}

.random-join-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  margin-top: auto;
}

.random-btn {
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid #5ec1e6;
  background: #5ec1e6;
  color: #ffffff;
  font-weight: bold;
  cursor: pointer;
}
.random-btn:hover{
  border-color:  #297d9d;
  background: #429abc;
}

.random-btn.primary {
  width: 100%;
  margin-top: 8px;
}

.random-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.random-status {
  color: #b91c1c;
  position: absolute;
  bottom: 12px;
  right: 0;
}
.random-field {
  margin-bottom: 10px;
}

.random-field label {
  display: block;
  font-weight: 700;
  color: #6b7280;
  margin-bottom: 6px;
}

.random-field h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #6b7280;
}

.random-field input[type="range"] {
  width: 100%;
  accent-color: #1d92c0;
}

.random-levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.random-level-btn {
  border: 2px solid #d1d5db;
  background: #ffffff;
  padding: 5px 8px 7px;
  font-weight: 700;
  color: #6b7280;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.random-level-btn:hover{
  border-color: #7cc6e8;
  color: #1f2937;
}

.random-level-btn.active {
  border-color: #7cc6e8;
  box-shadow: inset 0 0 0 2px #7cc6e8;
  color: #1f2937;
}

.random-colors {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
}

.random-color-btn {
  height: 64px;
  border: 2px solid #d1d5db;
  background: #ffffff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.random-color-btn:hover{
  border-color: #7cc6e8;
}

.random-color-btn.active {
  border-color: #7cc6e8;
  box-shadow: inset 0 0 0 2px #7cc6e8;
}

.random-waiting {
  text-align: center;
  margin-top: 5px;
  font-weight: 700;
  color: #111827;
  font-size: 14px;
}



.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: space-between;
  gap: 16px;
  height: 100%;
}

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

.cg-512 {
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  padding-right: 16px;
  padding-bottom: 16px;
  background: #fff;
  position: relative;
  height: 100%;
  z-index: 0;
}

.board-result-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
}
.board-result-overlay:before{
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background: rgba(0, 0, 0, 0.5);
}

.board-result-overlay.hidden {
  display: none;
}

.resign-confirm-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

.resign-confirm-overlay.hidden {
  display: none;
}

.promotion-overlay {
  position: absolute;
  inset: 0;
  z-index: 31;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

.promotion-overlay.hidden {
  display: none;
}

.promotion-card {
  width: min(540px, calc(100% - 24px));
  background: transparent;
  border: 0;
  padding: 0;
}

.promotion-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 14px 22px;
  justify-items: center;
}

.promotion-btn {
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 0;
  width: clamp(110px, 18vw, 210px);
  height: clamp(110px, 18vw, 210px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.promotion-btn:hover {
  transform: scale(1.03);
}

.promotion-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.45));
}

.resign-confirm-card {
  width: min(360px, calc(100% - 32px));
  background: #ffffff;
  border: 1px solid #d6dde6;
  border-radius: 8px;
  padding: 16px;
  color: #1c2430;
  text-align: center;
}

.resign-confirm-card p {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.resign-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.resign-confirm-btn {
  min-width: 120px;
  border: 1px solid #8ca2b5;
  background: #f8fafc;
  color: #1c2430;
  border-radius: 6px;
  padding: 8px 10px;
  font-weight: 700;
  cursor: pointer;
}

.resign-confirm-btn.danger {
  border-color: #b64b4b;
  background: #d45a5a;
  color: #ffffff;
}

.resign-confirm-btn:hover {
  filter: brightness(0.97);
}

.board-result-text {
  color: #fff;
  /* font-size: clamp(34px, 7vw, 64px); */
  text-transform: uppercase;
  white-space: pre-line;
  text-align: center;
  font-family: verdana;
  -webkit-text-stroke: 1px #fff;
  position: relative;
  aspect-ratio: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: center;
  font-size: clamp(16px, 3.7cqw, 30px);
}

.board-result-main {
  display: block;
}

.board-result-subtext {
  display: block;
  margin-top: 2px;
  font-size: 0.8em;
  text-transform: none;
}
body[data-mode="ai-rail"] #play-vs-ai section {
  display: block;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 0;
  vertical-align: top;
  height: calc(100% - 20px)
}

body[data-mode="ai-rail"] #play-vs-ai section p {
  display: none;
  margin: 0;
}

body[data-mode="ai-rail"] #play-vs-ai .cg-wrap {
  width: 520px;
  height: 520px;
}

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

.moves-panel {
  flex: 1;
  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;
  position: relative;
}

.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: bold;
  font-size: 16px;
  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: bold;
  border-top: 1px solid rgba(255,255,255,0.3);
  border-bottom: 1px solid rgba(0,0,0,0.2);
  flex: 0 0 auto;
  font-size: 14px;
}

.rail-status-text {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.15;
}

.rail-status-text .status-main {
  display: block;
}

.rail-status-text .status-sub {
  display: block;
  font-size: 0.82em;
  font-weight: 600;
}

.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;
  font-size: 0;
}
.move-btn:before{
  content: "";
  display: inline-block;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 0 0;
}
.move-btn#move-live::before{
  content: "\21BB";
  font-size: 25px;
  position: absolute;
  margin: -18px 0 0 -7px;
}
.move-btn#move-first::before{
  width: 16px;
  height: 16px;
  background-image: url(./images/icon-exit.svg);
}
.move-btn#move-prev::before,
.move-btn#move-next::before{
  width: 12px;
  height: 12px;
  background-image: url(./images/icon-prev.svg);
}
.move-btn#move-next::before{
  transform: rotateY(-180deg);
}
.move-btn#move-last::before{
  width: 20px;
  height: 20px;
  background-image: url(./images/icon-last.svg);
  transform: rotateY(-180deg);
}
.move-btn:hover{
  background: #224059;
}

.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;
  font-size: 13px;
}

.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;
  font-size: 14px;
}

.analysis-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: rgba(18, 42, 64, 0.97);
}

.analysis-panel.hidden {
  display: none;
}

.analysis-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid #1e3a54;
  background: rgba(12, 29, 45, 0.88);
}

.analysis-header {
  font-size: 13px;
  font-weight: 700;
}

.analysis-close-btn {
  border: 1px solid #9db3c5;
  background: transparent;
  color: #ffffff;
  font-weight: 700;
  padding: 6px 10px;
  cursor: pointer;
}

.analysis-close-btn:hover {
  background: #224059;
}

.analysis-panel-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  padding: 12px;
  overflow-y: auto;
}

.analysis-status {
  font-size: 12px;
  color: #c1d3e3;
}

.analysis-summary {
  font-size: 12px;
  color: #d7e7f6;
  margin-top: 4px;
}

.analysis-list {
  margin-top: 6px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  font-size: 12px;
}

.analysis-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(157, 179, 197, 0.15);
}

.analysis-item:last-child {
  border-bottom: none;
}

.analysis-item-meta {
  color: #ffffff;
}

.analysis-move-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.analysis-move-btn:hover .analysis-item-meta,
.analysis-move-btn:focus-visible .analysis-item-meta {
  color: #7dc3f5;
  text-decoration: underline;
}

.analysis-item-detail {
  color: #9dc0dc;
  text-align: right;
}

.analysis-attribution {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(157, 179, 197, 0.15);
  color: #9dc0dc;
  font-size: 11px;
  line-height: 1.4;
}

.analysis-attribution a {
  color: #7dc3f5;
  text-decoration: underline;
}

.analysis-item.quality-inaccuracy .analysis-item-detail {
  color: #f2c66d;
}

.analysis-item.quality-mistake .analysis-item-detail {
  color: #f29b6d;
}

.analysis-item.quality-blunder .analysis-item-detail {
  color: #ef6a6a;
}

.analysis-run-btn {
  width: 100%;
  margin-top: 8px;
  border: 1px solid #9db3c5;
  background: transparent;
  color: #ffffff;
  font-weight: 700;
  padding: 6px 8px;
  cursor: pointer;
}

.analysis-run-btn.hidden {
  display: none;
}

.analysis-run-btn:hover {
  background: #224059;
}

.takeback-panel {
  position: relative;
  z-index: 21;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #1e3a54;
  flex-wrap: wrap;
  background: #122a40;
}

.takeback-panel.hidden {
  display: none;
}

.takeback-text {
  font-weight: 700;
  color: #d9e6f2;
}

.takeback-btn {
  border: 1px solid #9db3c5;
  background: transparent;
  color: #ffffff;
  border-radius: 6px;
  padding: 4px 10px;
  font-weight: 700;
  cursor: pointer;
}

.takeback-btn.hidden {
  display: none;
}

.takeback-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.rail-actions .rail-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1px solid #9db3c5;
  color: #ffffff;
  background: transparent;
  text-decoration: none;
  font-weight: bold;
  height: 35px;
  line-height: 1;
}
.rail-actions .rail-action-btn:hover{
  background: #224059;
}

.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: 16px;
  letter-spacing: 2px;
  background: #2b4f6d;
  color: #ffffff;
}

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

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

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

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

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



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 {
  background: rgba(0, 0, 0, 0.7);
}

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

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

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

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

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

.friend-create-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.friend-create-field label {
  display: block;
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 4px;
  font-weight: 700;
}

.friend-create-field h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #6b7280;
}

.friend-create-field input[type="range"] {
  width: 100%;
}

.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: 8px 18px;
  border-radius: 999px;
  border: 2px solid #5ec1e6;
  background: #5ec1e6;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}
.friend-modal-btn:hover{
  background: #429abc;
  border-color: #297d9d;
}

.friend-modal-btn.primary {
  background: #2ea9d4;
  border-color: #2ea9d4;
}
.friend-modal-btn.primary:hover{
  background: #429abc;
  border-color: #297d9d;
}

.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: 7px 18px;
  font-size: 18px;
  font-weight: bold;
  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;
  margin-bottom: 0 !important;
}

.friend-modal-status {
  margin-top: 12px;
  font-weight: 700;
  color: #b91c1c;
  left: 30px;
  position: absolute;
}

.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;
  display: none;
}
.friend-modal-cancel:hover{
  background: #d9dbdc;
}

.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: 799px){
 .cg-512 {
    padding: 16px;
  }
}
/* portrait css */
@media (max-aspect-ratio: 5/3.8) {
  .chess-main,
  .match-board{
    flex-direction: column;
  }
  .lobby-placeholder{
    width: 100%;
  }
  .cg-512{
    height: 100vw;
  }
  .cg-wrap {
    outline: 16px solid #fff;
  }
  .cg-512:after{
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: url('images/board/8x8maple.jpg') repeat 0 0/25%;
    filter: blur(8px);
    z-index: -2;
    transform: scale(1.1);
  }
  .cg-512:before{
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: -1;
  }

  .rail-actions{
    flex-direction: row;
    justify-content: space-between;
  }
  .rail-actions .rail-action-btn{
    flex: 1;
  }
  .iphone .rail-actions .rail-action-btn{
       height: 45px;
  }
  .random-modal-grid,
  .friend-modal-grid{
    grid-template-columns: 1fr;
  }
   .random-modal-divider,
   .friend-modal-divider{
    margin-top: 0;
  }
  .random-modal,  .ai-modal,  .friend-modal {
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
  }
  .chess-right-side-bottom{
      height: calc(100vh - 100vw - 74px)
  }
  @media (min-aspect-ratio: 1/2) {
    .cg-512 {
        max-height: 60vh;
        width: 100%;
      }
    .iphone .cg-512{
      max-height: 55vh;
    }
      @media (min-width: 800px) {
        .cg-512 {
          padding-right: 0;
        }
      }
    .lobby-start{
      margin: auto;
      background-size: contain;
      aspect-ratio: 1;
      border-left: 1.15vh solid #fff;
      border-top: 1.15vh solid #fff;
      max-width: 45vh;
    }
    .lobby-placeholder{
      max-height: 45vh;
    }
     .lobby-placeholder:before{
       content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        background: url(images/board/8x8maple.jpg?v=1774249426872) repeat 0 0 / 25%;
        filter: blur(8px);
        z-index: -2;
        transform: scale(1.1);
     }
    .lobby-start-card{
      transform: scale(0.7);
    }
    .chess-right-side-bottom{
      height: calc(55vh - 106px);
    }
    @media (max-width: 799px){
      .chess-right-side-bottom{
        height: calc(55vh - 74px);
       }
    }
  }
  @media (max-height: 700px){
    /* .random-modal-card, .ai-modal-card, .friend-modal-card{
        zoom: 0.68;
    } */
  }
  @media (max-height: 900px) {
    .make-hide{
      display: none;
    }
    .make-show{
      display: block;
    }
  }
  @media (max-width: 500px) {
    .rail-actions .rail-action-btn{
      font-size: 12px;
    }
  }
}
/* landscape css */
@media (min-aspect-ratio: 5/3.8) {
  /* css with height condition */
  @media (max-height: 500px) {
    .make-hide{
      display: none;
    }
    .make-show{
      display: block;
    }
    /* .random-modal-card,  .ai-modal-card, .friend-modal-card{
     zoom: calc(97vh / 100vw)
    } */
  }
}

/* normal desktop css for videos section */
@media (min-aspect-ratio: 5/4) and (max-aspect-ratio: 3/2) {
    .make-hide{
      display: none;
    }
    .make-show{
      display: block;
    }
  .video-sidebar-item a{
    flex-direction: column;
    padding: 15px 8px;
    justify-content: center;
    gap: 0;
  }
  .video-sidebar-item h2{
    text-align: center;
    margin-top: 8px;
  }
  .video-sidebar-item img{
    max-height: 60%;
    max-width: 100%;
    width: auto;
    height: auto;
  }
}
 /* css for fullscreen */
@media (min-width: 1100px) {
  @media (min-height: 700px) {
    .lobby-start-card{
      zoom: calc(100vh / 750px);
    }
  }
  /* .chess-right-side{
    zoom: calc(100vh / 750px);
  }
  .moves-panel{
    zoom: calc(100vh / 750px);
  } */
  .video-sidebar-items{
    padding: 10px;
  }
  .video-sidebar-item a{
    padding: 0;
    gap: 15px;
  }
  .video-sidebar-item h2{
    text-align: left;
    font-weight: bold;
  }
}
/* css for fullscreen with min height */
@media (min-aspect-ratio: 3/2) and (min-width: 1024px) and (min-height: 630px) {
  /* .random-modal-card,  .ai-modal-card, .friend-modal-card{
    zoom: 1.2
  } */
}
/* css for mobile device */
  @media (max-width: 799px){
   .moves-panel{
      zoom: 0.7;
    }
    .player-active-block{
      padding: 5px 10px;
      margin-bottom: 8px;
    }
    .video-sidebar-container-header{
      height: 45px;
      font-size: 13px;
    }
    .video-sidebar-container-header h1{
      line-height: 1.3;
    }
    .lichess_ground .replay turn > move{
      font-size: 15px;
    }
    .random-level-btn{
      font-size: 11px;
    }
    .random-modal-grid{
      gap: 2px;
    }
    /* .ai-modal, .random-modal, .friend-modal{
      aspect-ratio: auto;
      background: rgba(0, 0, 0, 0.7);
    } */
    .video-sidebar-item h2{
      font-size: 13px;
    }
    /* .random-modal-card, .ai-modal-card, .friend-modal-card{
      max-width: none;
    } */
     .ai-modal-close,
     .random-modal-close,
     .friend-modal-close{
      right: -4px;
    }
}


@media (min-aspect-ratio: 1.5/1) {
  @media (max-height: 550px){
    .ai-modal, .random-modal, .friend-modal{
      aspect-ratio: auto;
      background: rgba(0, 0, 0, 0.7);
    }
    .random-modal-card, .ai-modal-card, .friend-modal-card{
      max-width: none;
    }
  }
}
.apple .friend-modal-input{
  font-size: 16px;
}
