/*!
 * Tic Tac Toe Game — Styles
 * Vollständig unter .ttt-wrapper gekapselt. Keine Selektoren ohne dieses
 * Präfix, keine Änderungen an :root oder globalen Tags, damit das
 * umgebende Theme/Plugins unangetastet bleiben und umgekehrt.
 */

.ttt-wrapper {
	/* Eigener CSS-Variablen-Scope — beeinflusst nichts außerhalb. */
	--ttt-bg: #ffffff;
	--ttt-surface: #f6f7fb;
	--ttt-surface-strong: #eef0f7;
	--ttt-border: #e6e8f0;
	--ttt-grid-line: #d7dae6;
	--ttt-text: #1a1d29;
	--ttt-text-muted: #767c8f;
	--ttt-primary: #4f5eff;
	--ttt-primary-dark: #3c48d6;
	--ttt-primary-soft: #eef0ff;
	--ttt-accent: #ef4d84;
	--ttt-accent-soft: #fdeef4;
	--ttt-success: #17b26a;
	--ttt-danger: #f04438;
	--ttt-warning: #f0a63b;
	--ttt-radius-xl: 24px;
	--ttt-radius-lg: 18px;
	--ttt-radius-md: 14px;
	--ttt-radius-sm: 10px;
	--ttt-shadow: 0 20px 45px -18px rgba(24, 27, 51, 0.22), 0 4px 14px -4px rgba(24, 27, 51, 0.08);
	--ttt-shadow-sm: 0 2px 6px -2px rgba(24, 27, 51, 0.12);
	--ttt-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

	all: revert;
	box-sizing: border-box;
	display: block;
	position: relative;
	width: 100%;
	max-width: 460px;
	margin: 2rem auto;
	font-family: var(--ttt-font);
	color: var(--ttt-text);
	line-height: 1.4;
	text-align: left;
	isolation: isolate;
	contain: layout style;
}

.ttt-wrapper *,
.ttt-wrapper *::before,
.ttt-wrapper *::after {
	box-sizing: border-box;
	font-family: inherit;
}

.ttt-wrapper :where(button) {
	all: unset;
	box-sizing: border-box;
	cursor: pointer;
	font-family: inherit;
}

.ttt-wrapper ul,
.ttt-wrapper p,
.ttt-wrapper h1,
.ttt-wrapper h2,
.ttt-wrapper h3,
.ttt-wrapper h4 {
	margin: 0;
	padding: 0;
}

.ttt-wrapper img,
.ttt-wrapper svg {
	max-width: none;
	display: inline-block;
	vertical-align: middle;
}

.ttt-wrapper svg {
	display: block;
}

/* ---------- Karte ---------- */

.ttt-card {
	background: linear-gradient(180deg, #ffffff 0%, #fcfcfe 100%);
	border: 1px solid var(--ttt-border);
	border-radius: var(--ttt-radius-xl);
	box-shadow: var(--ttt-shadow);
	padding: 1.75rem;
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
}

/* ---------- Header ---------- */

.ttt-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding-bottom: 1.1rem;
	border-bottom: 1px solid var(--ttt-border);
}

.ttt-title-group {
	display: flex;
	align-items: center;
	gap: 0.65rem;
}

.ttt-logo {
	width: 40px;
	height: 40px;
	border-radius: var(--ttt-radius-sm);
	background: linear-gradient(135deg, var(--ttt-primary-soft), var(--ttt-accent-soft));
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 1px;
	font-weight: 800;
	font-size: 1.05rem;
	line-height: 1;
	flex: none;
}

.ttt-logo-x {
	color: var(--ttt-primary);
}

.ttt-logo-o {
	color: var(--ttt-accent);
}

.ttt-title {
	font-size: 1.3rem;
	font-weight: 800;
	letter-spacing: -0.015em;
	color: var(--ttt-text);
}

.ttt-icon-btn {
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	background: var(--ttt-surface);
	color: var(--ttt-text-muted);
	border: 1px solid transparent;
	transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease, border-color 0.2s ease;
	flex: none;
}

.ttt-icon-btn .ttt-icon {
	width: 20px;
	height: 20px;
	flex: none;
}

.ttt-icon-btn:hover {
	background: var(--ttt-surface-strong);
	color: var(--ttt-text);
	border-color: var(--ttt-border);
}

.ttt-icon-btn:active {
	transform: scale(0.92);
}

.ttt-icon-btn[data-muted="true"] [data-ttt-sound-on] {
	display: none;
}

.ttt-icon-btn:not([data-muted="true"]) [data-ttt-sound-off] {
	display: none;
}

/* ---------- Toolbar ---------- */

.ttt-toolbar {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}

.ttt-field {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
}

.ttt-field-timer {
	align-items: flex-end;
}

.ttt-field-label {
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--ttt-text-muted);
}

/* Segment-Schalter für die Schwierigkeitsauswahl */

.ttt-segmented {
	display: inline-flex;
	background: var(--ttt-surface);
	border: 1px solid var(--ttt-border);
	border-radius: 999px;
	padding: 4px;
	gap: 4px;
}

.ttt-segment {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.5rem 1rem;
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 700;
	color: var(--ttt-text-muted);
	transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
	white-space: nowrap;
}

.ttt-segment:hover {
	color: var(--ttt-text);
}

.ttt-segment[aria-selected="true"] {
	background: var(--ttt-bg);
	color: var(--ttt-primary);
	box-shadow: var(--ttt-shadow-sm);
}

.ttt-segment:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px rgba(79, 94, 255, 0.25);
}

.ttt-timer {
	font-variant-numeric: tabular-nums;
	font-weight: 800;
	font-size: 1.05rem;
	background: var(--ttt-surface);
	border: 1px solid var(--ttt-border);
	border-radius: var(--ttt-radius-sm);
	padding: 0.5rem 0.9rem;
	color: var(--ttt-text);
	letter-spacing: 0.02em;
}

/* ---------- Scoreboard ---------- */

.ttt-scoreboard {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 0.5rem;
}

.ttt-score-item {
	background: var(--ttt-surface);
	border: 1px solid var(--ttt-border);
	border-radius: var(--ttt-radius-sm);
	padding: 0.55rem 0.4rem;
	text-align: center;
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
}

.ttt-score-label {
	font-size: 0.6rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--ttt-text-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ttt-score-value {
	font-size: 1.1rem;
	font-weight: 800;
	color: var(--ttt-text);
	font-variant-numeric: tabular-nums;
}

.ttt-highscore {
	background: linear-gradient(135deg, rgba(240, 166, 59, 0.14), rgba(239, 77, 132, 0.1));
	border-color: rgba(240, 166, 59, 0.35);
}

.ttt-highscore .ttt-score-value {
	color: #a86a0a;
}

/* ---------- Status ---------- */

.ttt-status {
	text-align: center;
	font-weight: 700;
	font-size: 0.95rem;
	color: var(--ttt-text-muted);
	min-height: 1.3em;
	transition: color 0.2s ease;
}

.ttt-status[data-state="win"] {
	color: var(--ttt-success);
}

.ttt-status[data-state="lose"] {
	color: var(--ttt-danger);
}

.ttt-status[data-state="draw"] {
	color: var(--ttt-warning);
}

/* ---------- Spielfeld ---------- */

.ttt-board-wrap {
	position: relative;
}

.ttt-board {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	grid-template-rows: repeat(3, 1fr);
	aspect-ratio: 1 / 1;
	width: 100%;
	background: var(--ttt-bg);
	border: 2px solid var(--ttt-grid-line);
	border-radius: var(--ttt-radius-lg);
	overflow: hidden;
	box-shadow: inset 0 1px 2px rgba(20, 22, 40, 0.03);
}

.ttt-cell {
	background: var(--ttt-bg);
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	transition: background-color 0.18s ease;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
}

/* Echte Rasterlinien im klassischen #-Muster */
.ttt-cell:nth-child(1),
.ttt-cell:nth-child(2),
.ttt-cell:nth-child(4),
.ttt-cell:nth-child(5),
.ttt-cell:nth-child(7),
.ttt-cell:nth-child(8) {
	border-right: 2px solid var(--ttt-grid-line);
}

.ttt-cell:nth-child(-n+6) {
	border-bottom: 2px solid var(--ttt-grid-line);
}

.ttt-cell:hover:not([data-filled="true"]):not([disabled]) {
	background: var(--ttt-surface);
}

.ttt-cell:active:not([data-filled="true"]):not([disabled]) {
	background: var(--ttt-surface-strong);
}

.ttt-cell:focus-visible {
	outline: none;
	box-shadow: inset 0 0 0 3px rgba(79, 94, 255, 0.35);
}

.ttt-cell[data-mark="x"] {
	color: var(--ttt-primary);
}

.ttt-cell[data-mark="o"] {
	color: var(--ttt-accent);
}

.ttt-cell[disabled] {
	cursor: default;
}

.ttt-cell.ttt-win-cell {
	background: rgba(23, 178, 106, 0.1);
	animation: ttt-win-pulse 1.1s ease-in-out infinite;
}

/* ---------- Gezeichnete X/O-Symbole (SVG) ---------- */

.ttt-mark-wrap {
	width: 62%;
	height: 62%;
	display: flex;
	align-items: center;
	justify-content: center;
	filter: drop-shadow(0 2px 3px rgba(20, 22, 40, 0.08));
}

.ttt-mark-wrap svg {
	width: 100%;
	height: 100%;
	overflow: visible;
}

.ttt-mark-stroke {
	fill: none;
	stroke: currentColor;
	stroke-width: 9;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ttt-mark-x .ttt-mark-stroke {
	stroke-dasharray: 90;
	stroke-dashoffset: 90;
	animation: ttt-draw-line 0.28s ease forwards;
}

.ttt-mark-x .ttt-mark-stroke:nth-child(2) {
	animation-delay: 0.14s;
}

.ttt-mark-o .ttt-mark-stroke {
	stroke-dasharray: 220;
	stroke-dashoffset: 220;
	transform-origin: center;
	transform: rotate(-90deg);
	animation: ttt-draw-line 0.4s ease forwards;
}

@keyframes ttt-draw-line {
	to {
		stroke-dashoffset: 0;
	}
}

@keyframes ttt-win-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(23, 178, 106, 0.35); }
	50% { box-shadow: 0 0 0 6px rgba(23, 178, 106, 0); }
}

/* ---------- Pause-Overlay ---------- */

.ttt-pause-overlay[hidden] {
	display: none;
}

.ttt-pause-overlay {
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.9);
	backdrop-filter: blur(4px);
	border-radius: var(--ttt-radius-lg);
	display: flex;
	align-items: center;
	justify-content: center;
	animation: ttt-fade-in 0.18s ease both;
	z-index: 2;
}

.ttt-pause-content {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.6rem;
	color: var(--ttt-text);
}

.ttt-pause-content .ttt-pause-icon {
	width: 52px;
	height: 52px;
	border-radius: 999px;
	background: var(--ttt-surface);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--ttt-primary);
}

.ttt-pause-content p {
	font-weight: 700;
	font-size: 0.95rem;
	color: var(--ttt-text-muted);
}

/* ---------- Steuerung ---------- */

.ttt-controls {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.75rem;
}

.ttt-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	width: 100%;
	padding: 0.85rem 1rem;
	border-radius: var(--ttt-radius-sm);
	font-weight: 700;
	font-size: 0.9rem;
	text-align: center;
	line-height: 1;
	transition: transform 0.12s ease, background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.ttt-btn svg {
	width: 17px;
	height: 17px;
	flex: none;
}

.ttt-btn:active {
	transform: scale(0.97);
}

.ttt-btn-secondary {
	background: var(--ttt-surface);
	border: 1px solid var(--ttt-border);
	color: var(--ttt-text);
}

.ttt-btn-secondary:hover {
	background: var(--ttt-surface-strong);
}

.ttt-btn-primary {
	background: linear-gradient(135deg, var(--ttt-primary), var(--ttt-primary-dark));
	color: #ffffff;
	box-shadow: 0 10px 20px -8px rgba(79, 94, 255, 0.55);
}

.ttt-btn-primary:hover {
	box-shadow: 0 12px 24px -8px rgba(79, 94, 255, 0.65);
}

.ttt-btn:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px rgba(79, 94, 255, 0.3);
}

/* ---------- Ergebnis-Modal ---------- */

.ttt-modal-overlay[hidden] {
	display: none;
}

.ttt-modal-overlay {
	position: absolute;
	inset: 0;
	background: rgba(15, 17, 32, 0.6);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	border-radius: var(--ttt-radius-xl);
	z-index: 5;
	animation: ttt-fade-in 0.2s ease both;
}

.ttt-modal {
	background: var(--ttt-bg);
	border-radius: var(--ttt-radius-xl);
	padding: 1.9rem 1.6rem;
	max-width: 320px;
	width: 100%;
	text-align: center;
	box-shadow: 0 30px 70px -14px rgba(0, 0, 0, 0.4);
	animation: ttt-modal-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes ttt-modal-in {
	0% { transform: translateY(14px) scale(0.94); opacity: 0; }
	100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes ttt-fade-in {
	from { opacity: 0; }
	to { opacity: 1; }
}

.ttt-modal-icon {
	width: 68px;
	height: 68px;
	margin: 0 auto 0.85rem;
	border-radius: 999px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.9rem;
	background: var(--ttt-surface);
}

.ttt-modal-icon[data-result="win"] {
	background: rgba(23, 178, 106, 0.14);
}

.ttt-modal-icon[data-result="lose"] {
	background: rgba(240, 68, 56, 0.12);
}

.ttt-modal-icon[data-result="draw"] {
	background: rgba(240, 166, 59, 0.16);
}

.ttt-modal h3 {
	font-size: 1.3rem;
	font-weight: 800;
	margin-bottom: 0.4rem;
	letter-spacing: -0.01em;
}

.ttt-modal p[data-ttt-modal-text] {
	color: var(--ttt-text-muted);
	font-size: 0.9rem;
	margin-bottom: 1.1rem;
}

.ttt-modal-scores {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.6rem;
	margin-bottom: 0.75rem;
}

.ttt-modal-score-box {
	background: var(--ttt-surface);
	border: 1px solid var(--ttt-border);
	border-radius: var(--ttt-radius-sm);
	padding: 0.65rem 0.4rem;
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
}

.ttt-modal-score-box span {
	font-size: 0.65rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	font-weight: 700;
	color: var(--ttt-text-muted);
}

.ttt-modal-score-box strong {
	font-size: 1.2rem;
	font-weight: 800;
	color: var(--ttt-text);
}

.ttt-modal-newrecord {
	font-weight: 700;
	color: #a86a0a;
	font-size: 0.85rem;
	margin-bottom: 0.9rem;
	animation: ttt-pop-in 0.3s ease both;
}

@keyframes ttt-pop-in {
	0% { transform: scale(0.7); opacity: 0; }
	100% { transform: scale(1); opacity: 1; }
}

.ttt-modal-actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.75rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 420px) {
	.ttt-wrapper {
		margin: 1rem auto;
	}

	.ttt-card {
		padding: 1.25rem;
		border-radius: var(--ttt-radius-lg);
	}

	.ttt-scoreboard {
		grid-template-columns: repeat(2, 1fr);
	}

	.ttt-title {
		font-size: 1.15rem;
	}

	.ttt-segment {
		padding: 0.4rem 0.65rem;
		font-size: 0.75rem;
	}
}

@media (min-width: 700px) {
	.ttt-wrapper {
		max-width: 500px;
	}
}

/* Reduzierte Bewegung respektieren */
@media (prefers-reduced-motion: reduce) {
	.ttt-wrapper * {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}
