:root {
	--player1: #db8686;
	--player2: #7660FF;
	--pieceShadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
	--squareSize: min(7vh, calc(70vw / var(--gridColumns)));  /* Adjust square size based on grid width */
	--phonePiecesSize: 50px;
	--pieceCount: 10;  /* Default number of pieces */
	--gridRows: 8;     /* Default number of rows */
	--gridColumns: 8;  /* Default number of columns */
	--headerHeight: 50px;

	/* Stacking order (low → high) */
	--z-board: 1;
	--z-player-area: 2;
	--z-drag-piece: 3;
	--z-header: 5;
	--z-side-menu: 6;
	--z-waiting: 6;
	--z-game-over: 7;
	--z-menu-button: 10;
	--z-overlay: 8;       /* share dialog, auth, toasts */
	--z-error-modal: 9;   /* illegal-move blocker */

	--error-bubble-gap: 12px;
	--error-square: #ec8484;
	--error-square-piece: #d45f5f;
	--error-bubble-fill: rgba(255, 255, 255, 0.10);
	--error-bubble-pointer: rgba(255, 255, 255, 0.18);
	--zujin: rgba(252, 227, 180, 0.9);
	--zujin-shadow: rgba(168, 132, 78, 0.95);
}

@property --zujin-draw-angle {
	syntax: '<angle>';
	initial-value: 0deg;
	inherits: false;
}

* {
	box-sizing: border-box;
}

body.game-page {
	user-select: none;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
}

body.game-page.is-dragging-piece {
	cursor: grabbing;
}

body.game-page input,
body.game-page select,
body.game-page textarea {
	user-select: text;
	-webkit-user-select: text;
}

header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: var(--z-header);
	margin-bottom: 20px;
	padding: 10px;
	height: 50px;
	background: #3F3F3F;
	box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
	display: flex;
	align-items: center;
}

#logo {
    margin-top: 8px;
	margin-left: 15px;
	transform: scale(1.2);
}

#logo.logo-link {
	cursor: pointer;
}

#menu {
	position: fixed;
	top: 0;
	right: calc(20px - var(--headerHeight));
	height: var(--headerHeight);
	padding: 0 var(--headerHeight);
	border: none;
	background: transparent;
	z-index: var(--z-menu-button);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	pointer-events: auto;
}

#menu img {
	display: block;
	transform: scale(1.3);
	transition: transform 0.3s ease;
}

#menu.open img {
	transform: scale(1.3) rotate(90deg);
}

body {
	margin: 0;
	padding-top: var(--headerHeight); /* Add padding to account for fixed header */
	padding-bottom: calc(var(--squareSize) * 1.5 + 40px); /* Add padding for pieces bank */
	background: #4a4a4a;
}


#grid-parent{
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	overflow-x: auto;  /* Allow horizontal scrolling if needed */
	padding: 10px;     /* Add padding to prevent squares from touching the edge */
	z-index: var(--z-board);
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	/* border: 1px solid red; */
}

#grid{
	/* height: 600px; */
	/* width: 70vh; */
	aspect-ratio: var(--gridColumns) / var(--gridRows);
	padding: 5px;
	display: grid; 
	grid-template-columns: repeat(var(--gridColumns), var(--squareSize)); 
	grid-template-rows: repeat(var(--gridRows), var(--squareSize)); 
	grid-column-gap: 5px;
	grid-row-gap: 5px;
	margin: 0 auto;    /* Center the grid */
	position: relative;
}	

.square {
	background-color:#656565; 
	border-radius: 5px;
	display: flex;
	justify-content: center;
	align-items: center;
	width: var(--squareSize);
	height: var(--squareSize);
}

.square > div {
	width: 100%;
	height: 100%;
	position: relative;
	border-radius: 5px;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 2rem;
	font-weight: 550;
	color: white;
	font-family: 'Roboto', sans-serif;
	transition: background-color 1s ease-out;
	user-select: none; /* Prevent text selection */
	-webkit-user-select: none; /* For Safari */
	-moz-user-select: none; /* For Firefox */
	-ms-user-select: none; /* For IE/Edge */
	pointer-events: none; /* Make text non-interactive */
}

.piece-value {
	display: inline-block;
	line-height: 1;
	transition: transform 0.3s ease;
}

body.local-rotate-numbers:not(.local-player2-turn) .square .piece-value {
	transform: rotate(180deg);
}

body.local-rotate-numbers .unplayed-piece.player1 .piece-value {
	transform: rotate(180deg);
}

.player1 > div {
	background-color: var(--player1);
	box-shadow: var(--pieceShadow);
}

.player2 > div {
	background-color: var(--player2);
	box-shadow: var(--pieceShadow);
}

.square.hover-target {
	box-shadow: var(--pieceShadow), inset 0px 0px 5px 4px rgb(252, 227, 180);
}

.blue {
	background-color: var(--player2);
	color: white;
	box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
	filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));

}

.red {
	background-color:var(--player1);
	color: white;
	box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
	filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
}

.player1 {
    background-color: var(--player1);
    border-radius: 5px;
    color: white;
    box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
    filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
}

.player2 {
    background-color: var(--player2);
    border-radius: 5px;
    color: white;
    box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
    filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
}

.square.last-played > div {
	box-shadow: var(--pieceShadow), 0 0 0 2px var(--zujin);
}

.square.error-highlight {
	background-color: var(--error-square);
}

.square.error-highlight > div {
	background-color: var(--error-square-piece) !important;
	box-shadow: var(--pieceShadow);
	color: white;
}

#illegal-move-text{
	/* display: none; */
	color: white;
}

.player-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin: 0 auto 20px;
    width: 100%;
    position: fixed;
    left: 0;
    right: 0;
    padding: 0 20px;
    z-index: var(--z-player-area);
}

/* Player 1's area */
#player1-area {
    top: var(--headerHeight); /* Position below header */
	
}

/* Player 2's area */
#player2-area {
    bottom: 20px;
}

/* Online host (player1): swap areas so you are always at the bottom */
body.view-self-at-bottom #player1-area {
    top: auto;
    bottom: 20px;
}

body.view-self-at-bottom #player2-area {
    bottom: auto;
    top: var(--headerHeight);
}

body:not(.view-self-at-bottom) #player1-area,
body.view-self-at-bottom #player2-area {
    margin-top: 5px;
}

.player-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    position: absolute;
    left: 100px;
    min-width: 100px;
}

/* Desktop: top player shows timer above name; bottom player keeps name above timer */
body:not(.view-self-at-bottom) #player1-area .player-info,
body.view-self-at-bottom #player2-area .player-info {
    flex-direction: column-reverse;
}

.player-name-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
}

.cpu-difficulty-select {
    font-family: 'Roboto', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.2rem 0.35rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.35);
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    max-width: 7rem;
}

.cpu-difficulty-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
}

.cpu-name-row.active-turn .cpu-difficulty-select {
    border-color: var(--player2);
    color: white;
}

.player-name {
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.35);
    text-shadow: none;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.8s ease, text-shadow 0.8s ease;
}

.cpu-name-row .player-name {
    max-width: none;
    flex: 0 0 auto;
}

#player1-name.active-turn {
    color: var(--player1);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

#player2-name.active-turn {
    color: var(--player2);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.player-timer {
    font-family: 'Roboto', sans-serif;
    font-size: 2.5rem;
    font-weight: bold;
    /* padding: 0.5rem 0; */
    color: white;
    min-width: 90px;
    text-align: left;
    transition: all 0.8s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    left: 0;
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.player-timer.inactive {
    color: rgba(255, 255, 255, 0.271);
    text-shadow: none;
    /* transform: translateZ(0) scale(0.8); */
}

/* Add pulse animation for active timer */
@keyframes timerPulse {
    0% { transform: translateZ(0) scale(1); }
    40% { transform: translateZ(0) scale(1.4); }
    100% { transform: translateZ(0) scale(1); }
}

.player-timer:not(.inactive) {
    animation: timerPulse 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    animation-fill-mode: forwards;
}

.pieces-bank {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border-radius: 9px;
    width: 50vw;
    height: auto;
    padding: 0.4% 20px;
    background-color: rgb(97, 97, 101);
    border: 1px solid rgba(0, 0, 0, 0.333);
    box-shadow: inset 0px 7px 9px -4px rgb(36, 36, 36);
    transition: all 0.3s ease;
    overflow-x: auto;
    overflow-y: visible;
    position: relative;
    transform: none;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    touch-action: pan-x;  /* Allow horizontal scrolling */
    will-change: transform;  /* Optimize for animations */
    transform: translateZ(0);  /* Force GPU acceleration */
}

/* Hide scrollbar in Chrome/Safari */
.pieces-bank::-webkit-scrollbar {
    display: none;
}

.unplayed-piece {
    margin: 0.8%;
    width: var(--squareSize);
    aspect-ratio: 1 / 1;
    flex: 0 0 var(--squareSize);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 550;
    font-family: 'Roboto', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: pan-y;  /* Allow vertical dragging */
    position: relative;
    transform: scale(1);
    transition: box-shadow 0.3s ease, transform 0.3s ease, filter 0.3s ease;
}

.unplayed-piece:hover:not(.disabled-piece):not(.selected-piece) {
	box-shadow: var(--pieceShadow), 0px 0px 6px 3px rgb(252, 227, 180);
	transform: scale(1.08);
	z-index: 1;
}

.pieces-bank.waiting-turn .unplayed-piece:not(.disabled-piece) {
    filter: brightness(0.92) drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
    cursor: default;
    touch-action: pan-x;
}

.unplayed-piece.view-only-piece {
    cursor: grab;
    touch-action: pan-x;
}

.unplayed-piece.view-only-piece:active {
    cursor: grabbing;
}

.pieces-bank.waiting-turn .unplayed-piece:hover,
.pieces-bank.waiting-turn .unplayed-piece:active {
    box-shadow: var(--pieceShadow);
    transform: scale(1);
    z-index: auto;
}

.disabled-piece {
	background-color: #808080 !important;
	color: #4c4c4c !important;
	box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
	filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
	cursor: default;
}

.unplayed-piece.disabled-piece:hover,
.unplayed-piece.disabled-piece:active {
	box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
	transform: scale(1);
	z-index: auto;
	cursor: default;
}

.unplayed-piece.selected-piece,
.unplayed-piece.selected-piece:hover {
	box-shadow: var(--pieceShadow), inset 0px 0px 5px 4px rgb(252, 227, 180);
	transform: scale(1.06);
	z-index: 1;
}

#score-area {
	/* background-color: purple; */
	border: none;
	border-radius: 0 40px 40px 0;
	height: 100px;
	width: 150px;
	position: absolute;
	top: 51%;
	transform: translateY(-50%);
	margin-left: -10px;
	display: flex;
	flex: 0 0 auto;
	justify-content: center;
	align-items: center;
	background: transparent;
	user-select: none;
	-webkit-user-select: none;
	z-index: var(--z-drag-piece);
	pointer-events: auto;
	overflow: visible;
	transition: width 0.4s ease;
}

@keyframes score-tab-bg-spring {
	0% { transform: scale(1); }
	55% { transform: scale(1.05); }
	100% { transform: scale(1.04); }
}

#score-area::before {
	content: '';
	position: absolute;
	inset: 0;
	border: 2px solid rgb(236, 236, 236, 0.25);
	border-radius: 0 40px 40px 0;
	background-color: #65636373;
	z-index: 0;
	transform: scale(1);
	transform-origin: center center;
	transition: transform 0.22s ease;
}

#score-area.score-hub:hover::before {
	animation: score-tab-bg-spring 0.38s cubic-bezier(0.34, 1.25, 0.64, 1) forwards;
}

#score-area > * {
	position: relative;
	z-index: 1;
}

#score-area.score-wide {
	width: 188px;
}

#score-area.score-expanded {
	width: 118px;
}

#score-area.score-expanded.score-wide {
	width: 152px;
}

#score-word {
	width: auto;
	height: auto;
	
	transform: rotate(-90deg);
	font-size: 30px;
	margin: 0;
	align-items: center ;
	color: #dfdfdf3d;
	
}

.score-hub {
	pointer-events: auto;
	cursor: pointer;
}

.score-hub-center {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 3rem;
	min-height: 3rem;
	transition: min-width 0.4s ease;
	pointer-events: auto;
}

.score-hub.score-expanded .score-hub-center {
	min-width: 1.5rem;
}

.score-hub-main {
	position: relative;
	z-index: 2;
	margin: 0;
	line-height: 1;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
	transform: scale(1);
	transform-origin: center center;
	transition: color 0.25s ease, text-shadow 0.25s ease, transform 0.4s ease;
	pointer-events: auto;
}

.score-hub.score-expanded .score-hub-main {
	transform: scale(0.5);
}

.score-hub:not(.score-neutral):hover .score-hub-main {
	text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5), 0 0 20px currentColor;
}

.score-hub.score-neutral:hover .score-hub-main {
	text-shadow: 0 2px 10px rgba(255, 255, 255, 0.14);
}

.score-expand {
	position: absolute;
	left: 50%;
	margin: 0;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	font-family: "Roboto", "Lucida Console", "Courier New", monospace;
	font-weight: 900;
	line-height: 1;
	transition: transform 0.4s ease, opacity 0.35s ease, visibility 0.4s ease;
}

.score-expand-opponent {
	bottom: 50%;
	transform: translate(-50%, 0);
}

.score-expand-self {
	top: 50%;
	transform: translate(-50%, 0);
}

.score-hub.score-expanded .score-expand-opponent {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, calc(-100% - 24px));
}

.score-hub.score-expanded .score-expand-self {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, calc(100% + 24px));
}

#score-area .score-hub-center {
	flex: 1 1 auto;
	min-width: 0;
}

#score {
	height: auto;
	width: auto;
	margin: 10px;
	font-size: 50pt;
	font-family: "Roboto", "Lucida Console", "Courier New", monospace;
	font-weight: 900;
	color: #373737;
}

#score-area .score-expand {
	font-size: 40pt;
}


.mobile-only {
	display: none !important;
}

button, select {
    margin-top: 10px;
    padding: 5px 10px;
    border-radius: 4px;
    background-color: #656565;
    color: white;
    border: 1px solid #808080;
    cursor: pointer;
    transition: all 0.2s ease;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button:hover, select:hover {
    background-color: #707070;
    transform: scale(1.05);
}

button:focus, select:focus {
    outline: none;
    border-color: var(--player1);
}

#menu {
	margin: 0;
	padding: 0 var(--headerHeight);
	border: none;
	border-radius: 0;
	background: transparent;
	color: inherit;
	transition: none;
	transform-style: flat;
}

#menu:hover,
#menu:focus {
	background: transparent;
	transform: none;
}

#by-me {
    position:absolute;
    transform: scale(3);
    bottom: 20px;
    right: 130px;
    opacity: .07;
    pointer-events: none;
}

body.error-bubble-active #grid-parent,
body.error-bubble-active .player-area,
body.error-bubble-active .square,
body.error-bubble-active .unplayed-piece {
    pointer-events: none !important;
}

.error-bubble-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-error-modal);
    background: rgba(0, 0, 0, 0.12);
    pointer-events: auto;
}

.error-bubble-modal .speech-bubble {
    position: fixed;
    background: var(--error-bubble-fill);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    color: #1f1f1f;
    padding: 10px 15px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    font-size: 16px;
    pointer-events: auto;
    white-space: normal;
    animation: errorBubbleIn 0.2s ease-in;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.08),
        0 8px 20px rgba(0, 0, 0, 0.18),
        0 20px 40px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: min(280px, 80vw);
}

.speech-bubble-message {
    line-height: 1.35;
}

.error-bubble-modal .speech-bubble-okay {
    margin: 0;
    padding: 7px 20px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.30);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    border: none;
    cursor: pointer;
  /* top-left highlight, bottom-right shadow (inset bevel) */
    box-shadow:
	inset 1px 1px 3px rgba(255, 255, 255, 0.2), 
	inset -1px -1px 3px rgb(0 0 0 / 18%);
}

.error-bubble-modal .speech-bubble-okay:hover {
    background: rgb(58, 58, 58);
    transform: scale(1.05);
    transition: transform 0.2s ease;

}

.error-bubble-modal .speech-bubble-okay:focus {
    outline: none;
    border: none;
}

.error-bubble-modal .speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 23px solid transparent;
    border-right: 23px solid transparent;
    border-top: 30px solid var(--error-bubble-pointer);
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.12));
    pointer-events: none;
}

@keyframes errorBubbleIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== Tutorial ===== */

body.tutorial-page {
    --tutorial-bubble-fill: rgba(255, 252, 252, 0.735);
    --tutorial-bubble-border: rgba(219, 134, 134, 0.28);
}

body.tutorial-page #menu {
    display: none;
}

body.tutorial-page .player-timer {
    display: none;
}

body.tutorial-intro-active #grid-parent,
body.tutorial-intro-active .player-area .unplayed-piece,
body.tutorial-intro-active .square {
    pointer-events: none;
}

.tutorial-banner {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    height: 50px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: var(--z-header);
    color: white;
    font-family: 'Roboto', sans-serif;
    white-space: nowrap;
}

.tutorial-progress {
    font-size: 12px;
    opacity: 0.7;
}

.tutorial-title {
    font-size: 15px;
    font-weight: 600;
}

.tutorial-nav-btn,
.tutorial-exit-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.tutorial-nav-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    line-height: 1;
    font-size: 16px;
    font-weight: 600;
}

.tutorial-nav-btn:hover:not(:disabled),
.tutorial-exit-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.tutorial-nav-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.tutorial-exit-btn {
    padding: 4px 12px;
}

.square.tutorial-target {
    animation: tutorialTargetPulse 1.6s ease-in-out infinite;
}

@keyframes tutorialTargetPulse {
    0%, 100% { box-shadow: inset 0 0 0 3px var(--player1); }
    50% { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--player1) 35%, transparent); }
}

/* Tutorial speech bubble: same look as the error bubble, but it doesn't
   block the board - the player acts while the instructions stay up. */
.tutorial-bubble-layer {
    position: fixed;
    inset: 0;
    z-index: var(--z-error-modal);
    pointer-events: none;
}

.tutorial-bubble-layer .speech-bubble {
    position: fixed;
    background: var(--tutorial-bubble-fill);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #1f1f1f;
    padding: 12px 16px 16px;
    border-radius: 8px;
    /* border: 1px solid var(--tutorial-bubble-border); */
    font-size: 15px;
    pointer-events: auto;
    white-space: normal;
    animation: errorBubbleIn 0.2s ease-in;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.08),
        0 8px 20px rgba(0, 0, 0, 0.18),
        0 20px 40px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: min(360px, 88vw);
}

.tutorial-bubble-layer .speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 23px solid transparent;
    border-right: 23px solid transparent;
    border-top: 30px solid var(--tutorial-bubble-fill);
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.12));
    pointer-events: none;
}

.tutorial-bubble-layer .speech-bubble.centered {
    left: 50%;
    top: calc(var(--headerHeight) + 128px);
    transform: translateX(-50%);
}

.tutorial-bubble-layer .speech-bubble.centered::after {
    display: none;
}

.tutorial-bubble-layer .speech-bubble-okay {
    margin: 0;
    padding: 7px 20px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.30);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow:
        inset 1px 1px 3px rgba(255, 255, 255, 0.2),
        inset -1px -1px 3px rgb(0 0 0 / 18%);
}

.tutorial-bubble-layer .speech-bubble-okay:hover {
    background: rgb(58, 58, 58);
    transform: scale(1.05);
    transition: transform 0.2s ease;
}

.flying-piece {
    position: fixed;
    z-index: var(--z-drag-piece);
    transition: all 1s cubic-bezier(0.5, 0, 0, 0.9);
    /* width: var(--squareSize);
    height: var(--squareSize); */
}

.game-over-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(calc(-50% + var(--go-x, 0px)), calc(-50% + var(--go-y, 0px)));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    z-index: var(--z-game-over);
}

.game-over-container.hidden {
    pointer-events: none;
    visibility: hidden;
}

.game-over-message {
    position: relative;
    background-color: rgba(0, 0, 0, 0.368);
    color: white;
    padding: 2.5rem;
	padding-bottom: 2rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 7px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(15px);
	-webkit-backdrop-filter: blur(15px);
    min-width: 300px;
    opacity: 0;
    transform: scale(1);
    transition: opacity 1s ease, transform 0.22s ease, box-shadow 0.22s ease;
    cursor: grab;
    touch-action: none;
}

.game-over-message.dragging {
    cursor: grabbing;
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.game-over-container.show-message .game-over-message {
    opacity: 1;
}

.game-over-message p, h2 {
	font-family: 'Roboto';
    font-style: italic;
}

.game-over-message h2 {
    margin-top: 0;
    /* color: #ffd700; */
    font-size: 2.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.game-over-message p {

    /* font-weight: 100; */
    font-size: 24px;
    line-height: 28px;

    color: #FFFFFF5e;
    /* margin: 0.8rem 0; */
    font-size: 1.4rem;
}

.game-over-message .winner-text {
	margin:0;
    width: auto;
	font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 2rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.game-over-message .scores-label {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    /* color: #ffd700; */
}

.game-over-message hr {
	opacity: 0.2;
    margin-top: -6px;
	margin-bottom: 11px;
}

.game-over-message .scores {
    display: flex;
    justify-content: center;
    align-items: center;
	
}

/* .game-over-message .score-item {
    text-align: center;
    min-width: 120px;
} */

.game-over-message .score-divider {
    font-size: 44pt;
    font-weight: 800;
    color: rgb(252, 252, 252);
    margin-top: -9px;
	min-width: 100px;
}

.game-over-message .score-player-name {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0.25rem 0;
    opacity: 0.9;
}

.game-over-message .player1-score .score-player-name {
    color: var(--player1);
    text-align: right;
}

.game-over-message .player2-score .score-player-name {
    color: var(--player2);
    text-align: left;
}

.game-over-message .score-item .score {
    font-size: 44pt;
    font-weight: bold;
	width: 100px;
	margin: 20px auto;
}

.game-over-message .player1-score .score {
    color: var(--player1);
	text-align: right;
}

.game-over-message .player2-score .score {
    color: var(--player2);
	text-align: left;
}

.debug-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 10px 0;
}

.debug-controls button,
.debug-controls select {
    width: 100%;
    padding: 8px;
    margin: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.debug-controls button:hover,
.debug-controls select:hover {
    background: rgba(255, 255, 255, 0.2);
}

.debug-controls select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 20px;
    padding-right: 30px;
}

.game-over-btn-parent {
    display: flex;
    justify-content: center;
    gap: 1rem;
    pointer-events: none;
}

.game-over-btn-parent > .btn-glass {
    opacity: 0;
    transform: translateY(-3rem);
    pointer-events: none;
}

@keyframes game-over-btn-fall {
    from {
        opacity: 0;
        transform: translateY(-3rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-over-container.show-buttons .game-over-btn-parent > :nth-child(1) {
    animation: game-over-btn-fall 0.6s ease-out forwards;
}

.game-over-container.show-buttons .game-over-btn-parent > :nth-child(2) {
    animation: game-over-btn-fall 0.6s ease-out forwards;
    animation-delay: 0.5s;
}

.game-over-container.show-buttons .game-over-btn-parent > :nth-child(3) {
    animation: game-over-btn-fall 0.6s ease-out forwards;
    animation-delay: 1s;
}

.game-over-container.show-buttons-ready .game-over-btn-parent {
    pointer-events: auto;
}

.game-over-container.show-buttons-ready .game-over-btn-parent > .btn-glass {
    pointer-events: auto;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.1rem;
    border: none;
    border-radius: 8px;
    background-color: #8E8E8E;
    color: rgba(0, 0, 0, 0.32);
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
    filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: transform;
}

.btn:hover {
    transform: scale(1.05);
    background-color: #9E9E9E;
}

.btn:active {
    transform: translateY(0);
}

.btn .icon {
    width: 1.2rem;
    height: 1.2rem;
    margin-right: 5px;
    filter: brightness(0) invert(1); /* Makes the SVG white */
    transition: transform 0.2s ease;
    color: rgba(0, 0, 0, 0.32);
    filter: brightness(0) invert(1) drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.5));
    transform-style: preserve-3d;
    backface-visibility: hidden;
    will-change: transform;
}

.btn:hover .icon {
    transform: none; /* Remove the default scale effect */
}

.btn .text {
	font-weight: 900;
    font-size: 14pt;
    color: #e7e7e7;
    text-shadow: 1px 1px 2px #0000006e;
}

/* Specific button styles */
.lobby-btn {
    background-color: #8E8E8E;
}

.lobby-btn:hover .icon {
    animation: slideLeft 1s cubic-bezier(0.36, 0, 0.66, -0.56);
}

.rematch-btn {
    background-color: #8E8E8E;
}

.rematch-btn:hover .icon {
    animation: rotateRematch 1s ease-in-out;
}

.new-game-btn {
    background-color: #8E8E8E;
}

.new-game-btn:hover .icon {
    animation: rotatePlus 1s ease-in-out;
}

/* Glass button style */
.btn-glass {
	display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.1rem;
    border: none;
    border-radius: 8px;
    background-color: #8E8E8E;
    color: rgba(0, 0, 0, 0.32);
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: inset 4px 4px 18px rgba(255, 255, 255, 0.29), inset -4px -4px 9px rgba(0, 0, 0, 0.26);
    filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.25));
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: transform;

	background-color: rgb(26 26 26 / 40%);
    border: none;
	backdrop-filter: blur(15px);
	-webkit-backdrop-filter: blur(15px);
    border-radius: 9px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition-property: border 3s ease-in-out;
}

.btn-glass:hover {
	background-color: rgb(26 26 26 / 40%);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4); 
}

.btn-glass:active {
    transform: scale(0.96);
	
}

.btn-glass .text {
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.btn-glass .icon {
    filter: brightness(0) invert(1) opacity(0.9);
}

@keyframes slideLeft {
    0%, 100% { transform: translateX(0); -webkit-animation-timing-function: ease-in-out; }
    25% { transform: translateX(-8px); -webkit-animation-timing-function: ease-out; }
    50% { transform: translateX( 2px); -webkit-animation-timing-function: ease-in; }
    75% { transform: translateX(-4px); -webkit-animation-timing-function: ease-out; }
}

@keyframes rotateRematch {
    0% { transform: rotate(0deg);  -webkit-animation-timing-function: ease-in-out; }
    100% { transform: rotate(360deg); -webkit-animation-timing-function: ease-in-out; }
}

@keyframes rotatePlus {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

@font-face {
    font-family: 'The Wild Breath of Zelda';
    src: url('the-wild-breath-of-zelda.ttf') format('truetype');
}

/* Lobby styles */
.lobby-bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.lobby-bg-rotate {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(calc(-1 * var(--lobby-bg-drift-angle, 25deg)));
    transform-origin: 50vw 50vh;
    filter: blur(var(--lobby-bg-blur, 8px));
}

.lobby-bg-scroll {
    position: absolute;
    top: 0;
    left: 0;
    width: max-content;
    height: max-content;
    will-change: transform;
    animation: lobby-bg-drift var(--lobby-bg-duration, 110s) linear infinite;
}

.lobby-bg-tile {
    position: absolute;
    top: 0;
    left: 0;
}

.lobby-bg-square {
    position: absolute;
    width: var(--lobby-bg-square-size, 96px);
    height: var(--lobby-bg-square-size, 96px);
    border-radius: 8px;
    background-color: #bdbdbd;
}

@keyframes lobby-bg-drift {
    from {
        transform: translate(
            var(--lobby-bg-start-x, -3840px),
            var(--lobby-bg-start-y, -1792px)
        );
    }
    to {
        transform: translate(
            var(--lobby-bg-end-x, -7680px),
            var(--lobby-bg-end-y, -1792px)
        );
    }
}

body.lobby-page .lobby-container {
    position: relative;
    z-index: 1;
}

.lobby-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - var(--headerHeight)); /* Adjust for fixed header */
    padding: 20px;
}

.lobby-content {
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 2rem;
    width: 100%;
    max-width: 800px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.lobby-content h1 {
    color: white;
    text-align: center;
    margin-bottom: 2rem;
    font-family: 'Roboto', sans-serif;
    font-size: 2.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.username-setup {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.username-setup label {
    color: rgba(255, 255, 255, 0.85);
    font-family: 'Roboto', sans-serif;
    font-size: 0.95rem;
}

.username-setup input {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.25);
    color: white;
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
}

.username-setup input::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

.lobby-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-overlay) - 1);
    animation: fadeIn 0.2s ease-out;
}

.cpu-difficulty-dialog .difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.cpu-difficulty-dialog .difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.25);
    color: white;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.cpu-difficulty-dialog .difficulty-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.4);
}

.cpu-difficulty-dialog .difficulty-btn.selected {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.5);
}

.cpu-difficulty-dialog .difficulty-label {
    font-size: 1rem;
    font-weight: 500;
}

.cpu-difficulty-dialog .difficulty-hint {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
}

.game-modes {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mode-btn {
    width: 100%;
    padding: 1.5rem !important;
    opacity: 1;
    transition: all 0.3s ease !important;
}

.mode-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mode-btn:not(:disabled):hover {
    transform: translateY(-2px) scale(1.02);
}

.mode-content {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.mode-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}

.mode-text .text {
    font-size: 1.5rem;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: transform;
}

.mode-text .subtext {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: transform;
}

.mode-btn .icon {
    width: 2rem;
    height: 2rem;
}

/* Animated Zujin outline — draws around button edge on hover/focus */
body.lobby-page .btn-glass,
body.lobby-page .difficulty-btn {
    position: relative;
    overflow: visible;
    isolation: isolate;
    --spotlight-x: -999px;
    --spotlight-y: -999px;
}

body.lobby-page .btn-glass {
    /* filter: drop-shadow breaks mix-blend-mode on .mouse-spotlight */
    filter: none;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        1px 1px 4px rgba(0, 0, 0, 0.25);
}

/* Base multi-color border from gold through warmer hues to brown */
body.lobby-page .btn-glass::after,
body.lobby-page .difficulty-btn::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    padding: 2px;
    z-index: 1;
    background: conic-gradient(
        from 278deg in oklch longer hue,
        var(--zujin) 0deg,
        var(--zujin-shadow) 180deg,
        var(--zujin) 360deg
    );
    -webkit-mask:
        conic-gradient(from 278deg, #fff 0deg, #fff var(--zujin-draw-angle), transparent var(--zujin-draw-angle)),
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: source-in, xor;
    mask:
        conic-gradient(from 278deg, #000 0deg, #000 var(--zujin-draw-angle), transparent var(--zujin-draw-angle)) intersect,
        linear-gradient(#000 0 0) content-box exclude,
        linear-gradient(#000 0 0);
    mask-composite: intersect, exclude;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

/* Rainbow accent on the border ring, revealed near the cursor */
body.lobby-page .btn-glass::before,
body.lobby-page .difficulty-btn::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    padding: 2px;
    z-index: 1;
    background: conic-gradient(
        from 278deg in oklch longer hue,
        var(--zujin) 0deg,
        var(--zujin-shadow) 180deg,
        var(--zujin) 360deg
    );
    -webkit-mask:
        radial-gradient(
            circle 30px at var(--spotlight-x) var(--spotlight-y),
            #fff 0%,
            rgba(255, 255, 255, 0.45) 55%,
            transparent 100%
        ),
        conic-gradient(from 278deg, #fff 0deg, #fff var(--zujin-draw-angle), transparent var(--zujin-draw-angle)),
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: source-in, source-in, xor;
    mask:
        radial-gradient(
            circle 30px at var(--spotlight-x) var(--spotlight-y),
            #000 0%,
            rgba(0, 0, 0, 0.45) 55%,
            transparent 100%
        ) intersect,
        conic-gradient(from 278deg, #000 0deg, #000 var(--zujin-draw-angle), transparent var(--zujin-draw-angle)) intersect,
        linear-gradient(#000 0 0) content-box exclude,
        linear-gradient(#000 0 0);
    mask-composite: intersect, intersect, exclude;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease-in-out;
}

/* Interior flashlight — tints white icons/text only (darken blend) */
body.lobby-page .mouse-spotlight {
    display: block;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(
        circle 120px at var(--spotlight-x) var(--spotlight-y),
        rgba(255, 255, 255, 0.95) 0%,
        rgba(255, 255, 255, 0.45) 45%,
        transparent 100%
    );
    mix-blend-mode: darken;
    transition: opacity 0.2s ease;
}

body.lobby-page .mode-content {
    position: relative;
    isolation: isolate;
}

body.lobby-page .mode-content .mouse-spotlight {
    border-radius: 0;
}

body.lobby-page .btn-glass > *:not(.mouse-spotlight),
body.lobby-page .difficulty-btn > *:not(.mouse-spotlight) {
    position: relative;
    z-index: 2;
}

body.lobby-page .btn-glass:not(:disabled):hover::before,
body.lobby-page .btn-glass:not(:disabled):hover::after,
body.lobby-page .btn-glass:not(:disabled):focus-visible::before,
body.lobby-page .btn-glass:not(:disabled):focus-visible::after,
body.lobby-page .difficulty-btn:not(:disabled):hover::before,
body.lobby-page .difficulty-btn:not(:disabled):hover::after,
body.lobby-page .difficulty-btn:not(:disabled):focus-visible::before,
body.lobby-page .difficulty-btn:not(:disabled):focus-visible::after {
    opacity: 1;
    --zujin-draw-angle: 360deg;
}

body.lobby-page .btn-glass:not(:disabled):hover .mouse-spotlight,
body.lobby-page .btn-glass:not(:disabled):focus-visible .mouse-spotlight,
body.lobby-page .difficulty-btn:not(:disabled):hover .mouse-spotlight,
body.lobby-page .difficulty-btn:not(:disabled):focus-visible .mouse-spotlight {
    opacity: 0.25;
}

@media (prefers-reduced-motion: reduce) {
    body.lobby-page .btn-glass::before,
    body.lobby-page .difficulty-btn::before,
    body.lobby-page .mouse-spotlight {
        display: none;
    }
}

@media (hover: none) {
    body.lobby-page .btn-glass::before,
    body.lobby-page .difficulty-btn::before,
    body.lobby-page .mouse-spotlight {
        display: none;
    }
}

@keyframes zujin-outline-draw {
    from { --zujin-draw-angle: 0deg; }
    to { --zujin-draw-angle: 360deg; }
}

/* Active Games Section */
.active-games-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.active-games-section h2 {
    color: white;
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    font-style: normal;
    text-align: left;
}

.active-games-section h3 {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.2rem;
    margin-bottom: 1rem;
    font-style: normal;
    text-align: left;
}

.active-games-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.games-separator {
    margin: 1.5rem 0;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.hosted-games-section {
    animation: fadeIn 0.3s ease-out;
}

.hosted-game {
    background: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.game-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.game-host {
    color: white;
    font-size: 1.1rem;
    font-weight: 500;
}

.game-time {
    color: var(--text-secondary);
    font-size: 0.8em;
}

.join-game-btn {
    padding: 0.5rem 1rem !important;
    font-size: 0.9rem !important;
    min-width: 100px;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.no-games {
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    padding: 2rem;
    font-style: italic;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cancel-game-btn {
    background: rgba(255, 59, 59, 0.2) !important;
    border: 1px solid rgba(255, 59, 59, 0.4) !important;
}

.cancel-game-btn:hover {
    background: rgba(255, 59, 59, 0.3) !important;
    border: 1px solid rgba(255, 59, 59, 0.5) !important;
}

.share-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 2rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: var(--z-overlay);
    animation: fadeIn 0.3s ease-out;
}

.share-dialog h3 {
    color: white;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.share-dialog .link-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.share-dialog .share-link {
    flex: 1;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-family: monospace;
    font-size: 1rem;
}

.share-dialog .copy-btn {
    padding: 0.75rem 1.5rem;
    white-space: nowrap;
}

.share-dialog .note {
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.share-dialog .dialog-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.share-dialog .cancel-btn {
    background: rgba(255, 59, 59, 0.2);
    border: 1px solid rgba(255, 59, 59, 0.4);
}

.share-dialog .cancel-btn:hover {
    background: rgba(255, 59, 59, 0.3);
    border: 1px solid rgba(255, 59, 59, 0.5);
}

.auth-container {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: var(--z-overlay);
}

.auth-container form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.auth-container input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.auth-container button {
    padding: 8px 16px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.auth-container button:hover {
    background: #0056b3;
}

#user-info {
    text-align: center;
}

#user-info button {
    margin-top: 10px;
    background: #dc3545;
}

#user-info button:hover {
    background: #c82333;
}

/* Side menu styles */
.side-menu {
    position: fixed;
    top: 0;
    right: -300px;
    width: 300px;
    height: 100vh;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(10px);
    transition: right 0.3s ease-in-out;
    z-index: var(--z-side-menu);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
}

@media screen and (max-width: 768px) {
    .side-menu {
        background: rgba(0, 0, 0, 0.88);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
    }
}

.side-menu.open {
    right: 0;
}

.side-menu-header {
    display: flex;
    align-items: center;
    flex: 0 0 var(--headerHeight);
    height: var(--headerHeight);
    margin: 0;
    padding: 0 56px 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.side-menu-header h3 {
    color: white;
    margin: 0;
    font-size: 1.2rem;
    line-height: 1;
}

.local-game-controls {
	display: none;
	flex-direction: column;
	gap: 10px;
	padding: 20px 20px 0;
}

body.local-game-mode .local-game-controls {
	display: flex;
}

.local-game-toggle {
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	cursor: pointer;
}

.local-game-toggle-label {
	flex: 1;
	cursor: pointer;
}

.local-game-toggle input[type="checkbox"] {
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	margin: 0;
	accent-color: rgb(252, 227, 180);
	cursor: pointer;
}

/* Side menu controls (debug + lobby settings) */
.side-menu .debug-controls,
.side-menu .side-menu-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    margin: 0;
    padding: 20px;
    overflow-y: auto;
}

.debug-control-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    padding: 8px;
    margin: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: white;
    font-size: 14px;
    box-sizing: border-box;
    cursor: default;
}

.debug-control-label select {
    width: 100%;
    padding: 8px;
    margin: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 20px;
    padding-right: 30px;
    box-sizing: border-box;
}

.debug-control-label input[type="range"] {
    width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    accent-color: rgb(252, 227, 180);
    cursor: pointer;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-section-title {
    margin: 0 0 4px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.settings-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    box-sizing: border-box;
}

.settings-control-label {
    display: block;
    color: white;
    font-size: 14px;
    white-space: nowrap;
    cursor: default;
}

.settings-value {
    font-weight: 500;
    color: rgb(252, 227, 180);
}

.settings-range-wrap {
    position: relative;
    width: 100%;
}

.settings-range-default {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 12px;
    margin-top: -6px;
    margin-left: -1px;
    background: rgba(252, 227, 180, 0.9);
    border-radius: 1px;
    pointer-events: none;
    z-index: 1;
}

.settings-range-wrap input[type="range"] {
    position: relative;
    z-index: 2;
    width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    accent-color: rgb(252, 227, 180);
    cursor: pointer;
}

.debug-controls button,
.debug-controls select {
    width: 100%;
    padding: 8px;
    margin: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.debug-controls button:hover,
.debug-controls select:hover {
    background: rgba(255, 255, 255, 0.2);
}

.debug-controls select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 20px;
    padding-right: 30px;
}

@media screen and (max-width: 768px) and (hover: none) and (pointer: coarse) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only.mobile-player-bar {
        display: flex !important;
    }

    .mobile-player-bar {
        position: relative;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        gap: 0.35rem;
        padding: 0 2px;
        min-height: 40px;
    }

    .mobile-player-timer {
        flex: 0 0 auto;
        min-width: 64px;
        font-size: 2rem;
        text-align: left;
        padding: 0;
        margin: 0;
        position: static;
        left: auto;
        transform: none;
    }

    .mobile-player-name {
        flex: 1 1 auto;
        text-align: center;
        max-width: none;
        font-size: 0.95rem;
        padding: 0 0.25rem;
    }

    /* Opponent bar: center name on full screen width, not just space after timer */
    #player1-area .mobile-player-name,
    body.view-self-at-bottom #player2-area .mobile-player-name {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        flex: none;
        max-width: calc(100% - 80px);
        padding: 0 0.25rem;
        pointer-events: none;
    }

    .mobile-cpu-name-row {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        flex: none;
        max-width: calc(100% - 80px);
        pointer-events: auto;
        z-index: 1;
    }

    .mobile-cpu-name-row .mobile-player-name {
        position: static;
        transform: none;
        pointer-events: none;
        flex: 0 0 auto;
    }

    .mobile-cpu-name-row .cpu-difficulty-select {
        flex: 0 1 auto;
        min-width: 0;
    }

    #mobile-player1-name.active-turn {
        color: var(--player1);
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    }

    #mobile-player2-name.active-turn {
        color: var(--player2);
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    }

    .mobile-score-area {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 40px;
        min-width: 68px;
        border: none;
        border-radius: 40px 0 0 40px;
        background: transparent;
        padding: 0 8px 0 12px;
        user-select: none;
        -webkit-user-select: none;
        position: relative;
        z-index: 2;
        pointer-events: auto;
        transition: min-width 0.4s ease, padding 0.4s ease;
    }

    .mobile-score-area::before {
        content: '';
        position: absolute;
        inset: 0;
        border: 2px solid rgb(236, 236, 236, 0.25);
        border-radius: 40px 0 0 40px;
        background-color: #65636373;
        z-index: 0;
        transform: scale(1);
        transform-origin: center center;
        transition: transform 0.22s ease;
    }

    .mobile-score-area.score-hub:hover::before {
        animation: score-tab-bg-spring 0.38s cubic-bezier(0.34, 1.25, 0.64, 1) forwards;
    }

    .mobile-score-area > * {
        position: relative;
        z-index: 1;
    }

    .mobile-score-area.score-wide {
        min-width: 92px;
        padding: 0 10px 0 14px;
    }

    .mobile-score-area.score-expanded {
        min-width: 54px;
        padding: 0 6px 0 10px;
    }

    .mobile-score-area.score-expanded.score-wide {
        min-width: 72px;
        padding: 0 8px 0 12px;
    }

    /* Player bar: bleed score capsule off the right edge */
    #player2-area,
    body.view-self-at-bottom #player1-area {
        padding-right: 0;
    }

    #player2-area .mobile-player-bar,
    body.view-self-at-bottom #player1-area .mobile-player-bar {
        padding-right: 0;
    }

    #player2-area .mobile-score-area,
    body.view-self-at-bottom #player1-area .mobile-score-area {
        margin-right: -4px;
    }

    .mobile-score-word {
        transform: rotate(90deg);
        font-size: 11px;
        margin: 0;
        color: #dfdfdf3d;
        line-height: 1;
    }

    .mobile-score-area .score-hub-center {
        flex: 1 1 auto;
        min-width: 0;
        min-height: 2rem;
    }

    .mobile-score-value {
        font-size: 2rem;
        font-family: "Roboto", "Lucida Console", "Courier New", monospace;
        font-weight: 900;
        margin: 0;
        line-height: 1;
        color: #373737;
    }

    .mobile-score-area .score-expand {
        font-size: 1.75rem;
    }

    .mobile-score-area.score-expanded .score-expand-opponent {
        transform: translate(-50%, calc(-100% - 18px));
    }

    .mobile-score-area.score-expanded .score-expand-self {
        transform: translate(-50%, calc(100% + 18px));
    }

    .mobile-player-timer:not(.inactive) {
        animation: timerPulse 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        animation-fill-mode: forwards;
    }

    .pieces-bank {
        width: 100%;
        padding: 0.6% 20px;
        margin: 0;
        height: calc(var(--phonePiecesSize) * 1.5);
    }

    .unplayed-piece {
        margin: 1%;
        width: var(--phonePiecesSize);
        flex: 0 0 var(--phonePiecesSize);
        aspect-ratio: 1 / 1;
        font-size: 2.5rem;
    }

    .player-area {
        padding: 0 10px;
        gap: 0.35rem;
        flex-direction: column;
        align-items: center;
    }

    /* Opponent (top): piece bank, then timer + name below */
    #player1-area .pieces-bank {
        order: 0;
        margin-top: 0;
    }

    #player1-area .mobile-player-bar {
        order: 1;
    }

    #player1-area .mobile-score-area {
        display: none;
    }

    /* Player (bottom): timer + name + score above piece bank */
    #player2-area .mobile-player-bar {
        order: 0;
    }

    #player2-area .pieces-bank {
        order: 1;
        margin-left: 0;
    }

    #player1-area {
        top: var(--headerHeight);
        margin-bottom: 10px;
    }

    #player2-area {
        bottom: 20px;
        margin-top: 10px;
    }

    body.view-self-at-bottom #player1-area {
        top: auto;
        bottom: 20px;
        margin-top: 10px;
        margin-bottom: 0;
    }

    body.view-self-at-bottom #player2-area {
        bottom: auto;
        top: var(--headerHeight);
        margin-top: 0;
        margin-bottom: 10px;
    }

    body.view-self-at-bottom #player1-area .mobile-player-bar {
        order: 0;
    }

    body.view-self-at-bottom #player1-area .pieces-bank {
        order: 1;
    }

    body.view-self-at-bottom #player1-area .mobile-score-area {
        display: flex;
    }

    body.view-self-at-bottom #player2-area .pieces-bank {
        order: 0;
    }

    body.view-self-at-bottom #player2-area .mobile-player-bar {
        order: 1;
    }

    body.view-self-at-bottom #player2-area .mobile-score-area {
        display: none;
    }
}

/* Add at the end of the file */
.notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: var(--z-overlay);
    animation: fadeIn 0.3s, fadeOut 0.3s 2.7s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.waiting-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: var(--z-waiting);
    text-align: center;
    font-size: 18px;
}


