@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600;700&family=Crimson+Pro:ital,wght@0,300;1,300&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
	background-color: #f0ead8;
	background-image:
		repeating-linear-gradient(
			0deg,
			transparent,
			transparent 27px,
			rgba(180,160,120,0.08) 27px,
			rgba(180,160,120,0.08) 28px
		),
		repeating-linear-gradient(
			90deg,
			transparent,
			transparent 27px,
			rgba(180,160,120,0.04) 27px,
			rgba(180,160,120,0.04) 28px
		);
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	font-family: 'Caveat', cursive;
	color: #2c2416;
	padding: 12px;
	overscroll-behavior: none;
	touch-action: none;
}

h1 {
	font-family: 'Caveat', cursive;
	font-size: clamp(1.4rem, 5vw, 2.2rem);
	font-weight: 700;
	color: #1a1208;
	letter-spacing: 0.04em;
	padding: 2rem;
	transform: rotate(-0.6deg);
	text-shadow: 1px 1px 0 rgba(100,80,40,0.15);
}

#board-wrap {
	position: relative;
	display: inline-block;
}

#base-canvas,
#mark-canvas {
	display: block;
	max-width: 100%;
	height: auto;
	filter: drop-shadow(2px 3px 6px rgba(80,60,20,0.18));
	border-radius: 2px;
	touch-action: none;
}

#mark-canvas {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

#settings-btn,
#reset-btn {
	padding: 8px 24px;
	background: transparent;
	border: none;
	border-bottom: 1.5px solid #6b5230;
	color: #4a3820;
	font-family: 'Caveat', cursive;
	font-size: clamp(1rem, 3.5vw, 1.1rem);
	letter-spacing: 0.08em;
	cursor: pointer;
	transform: rotate(-0.4deg);
	transition: color 0.2s, border-color 0.2s, transform 0.15s;
	min-height: 44px;
}

#button-container {
	display: flex;
	align-items: center;
	gap: 8px;
	position: relative;
}

#settings-btn:hover,
#reset-btn:hover {
	color: #1a1208;
	border-color: #1a1208;
	transform: rotate(-0.4deg) scale(1.04);
}

#settings-panel {
	position: absolute;
    top: 50%;
    left: 50%;
    transform: translateY(0) translateX(-50%) scale(0.9) rotate(3deg);;
	margin-left: 8px;
	min-width: 11rem;
	max-width: 16rem;
	padding: 0.75rem 1rem;
	border-radius: 4px;
	border: 1px solid rgba(90,70,40,0.35);
	background-color: rgba(255,252,244,0.92);
	box-shadow: 1px 2px 4px rgba(80,60,20,0.15);
	font-family: 'Caveat', cursive;
	font-size: 1rem;
	opacity: 0;
	pointer-events: none;
	transition: opacity 160ms ease-out, transform 160ms ease-out;
	z-index: 10;
}

#settings-panel.is-open {
	opacity: 1;
	pointer-events: auto;
    transform: translateY(-50%) translateX(-50%) scale(1) rotate(0deg);;
}

@media (max-width: 640px) {
	#button-container {
		flex-direction: column;
		align-items: stretch;
	}
}

.settings-item {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 4px;
    cursor: pointer;
}

.settings-item:last-child {
	margin-bottom: 0;
}

.settings-item input[type="checkbox"] {
	accent-color: #6b5230;
    cursor: pointer;
}

#turn-indicator {
	display: flex;
	align-items: center;
	gap: 5px;
    padding-top: 2rem;
}

.turn-dot {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	font-family: 'Caveat', cursive;
	font-size: 0.85rem;
	font-weight: 700;
	border: 1.5px solid currentColor;
}

.turn-dot[data-player="X"] { color: #2a4db5; }
.turn-dot[data-player="O"] { color: #b52a2a; }

.turn-dot--current {
	opacity: 1;
	width: 32px;
	height: 32px;
	font-size: 1.1rem;
	border-width: 2px;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(255, 252, 244, 0.72);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease-out;
    z-index: 9;
}

body.settings-open::after {
    opacity: 1;
    pointer-events: auto;
}

.custom-select {
	position: relative;
	font-family: 'Caveat', cursive;
	font-size: 1rem;
	color: #4a3820;
}

.custom-select__trigger {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 2px 0;
	background: transparent;
	border: none;
	border-bottom: 1.5px solid #6b5230;
	color: #4a3820;
	font-family: 'Caveat', cursive;
	font-size: 1rem;
	letter-spacing: 0.04em;
	cursor: pointer;
	transition: color 0.15s, border-color 0.15s;
	white-space: nowrap;
}

.custom-select__trigger:hover {
	color: #1a1208;
	border-color: #1a1208;
}

.custom-select__arrow {
	font-size: 0.85rem;
	transition: transform 0.15s;
	line-height: 1;
}

.custom-select.is-open .custom-select__arrow {
	transform: rotate(180deg);
}

.custom-select__options {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	min-width: 100%;
	list-style: none;
	margin: 0;
	padding: 4px 0;
	background: rgba(255, 252, 244, 0.97);
	border: 1px solid rgba(90, 70, 40, 0.3);
	border-radius: 3px;
	box-shadow: 1px 3px 8px rgba(80, 60, 20, 0.15);
	z-index: 20;
	opacity: 0;
	pointer-events: none;
	transform: translateY(-4px) rotate(-0.5deg);
	transition: opacity 140ms ease-out, transform 140ms ease-out;
}

.custom-select.is-open .custom-select__options {
	opacity: 1;
	pointer-events: auto;
	transform: translateY(0) rotate(0deg);
}

.custom-select__option {
	padding: 4px 12px;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.1s;
	border-radius: 2px;
}

.custom-select__option:hover {
	background: rgba(160, 120, 50, 0.12);
}

.custom-select__option[aria-selected="true"] {
	color: #6b5230;
	font-weight: 600;
}
