:root {
	--color-dark: #746f69;
	--color-mid: #999395;
	--color-light: #e3deda;
	--color-bg: #f0efeb;
	--color-white: #ffffff;
	--color-green: #527863;
	--color-red: #bd6b66;
	--color-yellow: #d4a373;
	--color-white-overlay: rgba(255, 255, 255, 0.2);

	--font-xl: 1.75rem;
	--font-lg: 1.25rem;
	--font-md: 1.1rem;
	--font-sm: 0.9rem;
	--font-xs: 0.8rem;

	--weight-normal: 400;
	--weight-bold: 600;
}

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

button,
input,
select,
textarea {
	font-family: inherit;
}

body {
	font-family:
		"IBM Plex Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
		sans-serif;
	background: var(--color-bg);
	color: var(--color-dark);
	height: 100dvh;
	display: flex;
	justify-content: center;
	padding: 16px 0;
}

.container {
	width: 100%;
	max-width: 480px;
	padding: 20px;
	height: calc(100dvh - 32px);
	display: flex;
	flex-direction: column;
	background: var(--color-light);
	border: 1px solid var(--color-light);
	border-radius: 16px;
	overflow: hidden;
}

h1 {
	text-align: center;
	font-size: var(--font-xl);
	margin-bottom: 24px;
	color: var(--color-dark);
}

/* 상단 바 */
.top-bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 12px 16px;
	margin: -20px -20px 16px -20px;
	background: var(--color-dark);
	border-radius: 16px 16px 0 0;
}

.top-bar-title {
	font-size: var(--font-xl);
	font-weight: var(--weight-bold);
	color: var(--color-white);
	margin-bottom: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	min-width: 0;
}

.top-bar-logo {
	height: 1.2em;
	width: auto;
	vertical-align: -0.2em;
	margin-right: 8px;
}

.top-bar-badge {
	font-size: var(--font-xs);
	color: var(--color-white);
	background: var(--color-white-overlay);
	padding: 4px 10px;
	border-radius: 12px;
	white-space: nowrap;
	flex-shrink: 0;
}

h2 {
	font-size: var(--font-lg);
	margin-bottom: 16px;
	color: var(--color-dark);
}

.btn {
	width: 100%;
	padding: 14px;
	border: none;
	border-radius: 12px;
	font-size: var(--font-md);
	font-weight: var(--weight-bold);
	cursor: pointer;
	transition: opacity 0.2s;
}

.btn:hover {
	opacity: 0.85;
}

.btn-primary,
.btn-success {
	background: var(--color-dark);
	color: var(--color-light);
}

.btn-secondary {
	background: var(--color-white);
	color: var(--color-dark);
}

input,
select {
	width: 100%;
	padding: 14px;
	border: 1px solid var(--color-light);
	border-radius: 6px;
	font-size: var(--font-md);
	background: var(--color-white);
	color: var(--color-dark);
	outline: none;
}

select {
	height: 48px;
	line-height: 48px;
	text-indent: 4px;
	padding: 0;
}

input:focus {
	border-color: var(--color-dark);
}

input::placeholder {
	color: var(--color-mid);
	opacity: 0.55;
}

.input-group {
	margin-bottom: 12px;
}

.input-group label {
	display: block;
	margin-bottom: 6px;
	font-size: var(--font-sm);
	color: var(--color-dark);
}

/* 로비 */
.room-list {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	margin-bottom: 12px;
}

.room-card {
	background: var(--color-white);
	border: 1px solid var(--color-light);
	border-radius: 12px;
	padding: 16px;
	margin-bottom: 10px;
	cursor: pointer;
	transition:
		border-color 0.2s,
		box-shadow 0.2s;
	box-shadow: 0 2px 8px rgba(116, 111, 105, 0.1);
}

.room-card:hover {
	border-color: var(--color-dark);
}

.room-card.disabled {
	cursor: not-allowed;
	opacity: 0.5;
}

.room-card.disabled:hover {
	border-color: var(--color-light);
}

.room-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.room-row + .room-row {
	margin-top: 4px;
}

.room-card .room-title {
	font-size: var(--font-md);
	font-weight: var(--weight-bold);
}

.room-card .room-players {
	font-size: var(--font-sm);
	color: var(--color-dark);
}

.room-card .room-quiz-type {
	font-size: var(--font-sm);
	color: var(--color-dark);
}

.room-card .room-status {
	font-size: var(--font-sm);
	padding: 2px 8px;
	border-radius: 8px;
	background: var(--color-dark);
	color: var(--color-light);
}

.room-card .room-status.playing {
	background: var(--color-mid);
}

/* 모달 */
.modal-overlay {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.4);
	z-index: 100;
	justify-content: center;
	align-items: center;
}

.modal-overlay.active {
	display: flex;
}

.modal {
	background: var(--color-light);
	border: 1px solid var(--color-light);
	border-radius: 16px;
	padding: 24px;
	width: 90%;
	max-width: 400px;
	max-height: calc(100dvh - 32px);
	overflow-y: auto;
	box-shadow: 0 4px 16px rgba(116, 111, 105, 0.2);
}

.modal h2 {
	margin-bottom: 20px;
}

.modal .btn {
	margin-top: 8px;
}

.button-row {
	display: flex;
	gap: 8px;
}

.button-row .btn {
	margin-top: 0;
	flex: 1;
}

.modal .button-row {
	margin-top: 16px;
}

/* 게임 화면 */
.game-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 16px;
	margin: -20px -20px 6px -20px;
	background: var(--color-dark);
	border-radius: 16px 16px 0 0;
}

.game-header .round-info {
	font-size: var(--font-md);
	color: var(--color-white);
	flex-shrink: 0;
	min-width: 48px;
}

.game-header .timer-text {
	font-size: var(--font-sm);
	color: var(--color-white);
	flex-shrink: 0;
	min-width: 32px;
	text-align: right;
}

.question-area {
	background: var(--color-white);
	border: 1px solid var(--color-light);
	border-radius: 12px;
	padding: 20px;
	margin-bottom: 12px;
	min-height: 120px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	box-shadow: 0 2px 8px rgba(116, 111, 105, 0.1);
}

.question-area .quiz-meta {
	display: flex;
	justify-content: space-between;
	font-size: var(--font-sm);
	color: var(--color-dark);
	margin-bottom: 8px;
	font-weight: var(--weight-bold);
}

.question-area .question-text {
	font-size: var(--font-lg);
	line-height: 1.6;
	text-align: center;
}

.timer-bar {
	flex: 1;
	height: 16px;
	background: var(--color-white-overlay);
	border-radius: 5px;
	overflow: hidden;
}

.timer-bar .timer-fill {
	height: 100%;
	background: var(--color-white);
	border-radius: 5px;
	transition: width 0.1s linear;
	width: 100%;
}

.music-timer-bar {
	width: 100%;
	height: 4px;
	background: var(--color-light);
	border-radius: 5px;
	overflow: hidden;
}

.music-timer-bar .music-timer-fill {
	height: 100%;
	width: 0%;
	background: var(--color-green);
	border-radius: 5px;
	transition: width 0.05s linear;
}

/* 게임 뷰 레이아웃 */
#game-view:not(.hidden) {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

/* 채팅 */
.chat-area {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 8px 0;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.chat-msg {
	font-size: var(--font-md);
	padding: 6px 12px;
	border-radius: 8px;
	background: var(--color-white);
	word-break: break-word;
}

.chat-msg.system {
	background: transparent;
	color: var(--color-dark);
	font-size: var(--font-sm);
}

.chat-msg.correct,
.chat-msg.no-answer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	color: var(--color-white);
}

.chat-msg.correct {
	background: var(--color-green);
}

.chat-msg.no-answer {
	background: var(--color-red);
}

.report-btn {
	background: rgba(255, 255, 255, 0.25);
	color: var(--color-white);
	border: none;
	padding: 4px 10px;
	border-radius: 6px;
	font-size: var(--font-sm);
	font-weight: var(--weight-bold);
	cursor: pointer;
	flex-shrink: 0;
}

.report-btn:disabled {
	opacity: 0.5;
	cursor: default;
}

.chat-msg.hint {
	background: var(--color-yellow);
	color: var(--color-white);
}

.chat-input {
	display: flex;
	gap: 8px;
	padding-top: 8px;
	flex-shrink: 0;
}

.chat-input-actions + .chat-input {
	padding-top: 0;
}

.chat-input input {
	flex: 1;
	border-radius: 20px;
	padding: 12px 16px;
}

.chat-input .btn {
	width: auto;
	padding: 12px 20px;
	border-radius: 20px;
}

.chat-input-actions {
	display: flex;
	gap: 8px;
	padding-top: 8px;
	padding-bottom: 6px;
	flex-shrink: 0;
}

.chat-input-actions #scoreboard-toggle {
	margin-right: auto;
}

.chat-input-actions .btn {
	width: auto;
	padding: 8px 16px;
	border-radius: 16px;
	font-size: var(--font-sm);
	flex-shrink: 0;
}

.btn-toggle {
	background: var(--color-white);
	color: var(--color-dark);
	border: 1px solid var(--color-light);
}

.btn-skip {
	background: var(--color-mid);
	color: var(--color-white);
}

.btn-hint {
	background: var(--color-yellow);
	color: var(--color-white);
}

.btn-skip:disabled,
.btn-hint:disabled {
	opacity: 0.5;
	cursor: default;
}

/* 게임 섹션 */
.game-section {
	background: var(--color-white);
	border-radius: 12px;
	padding: 16px;
	margin-bottom: 12px;
	box-shadow: 0 2px 8px rgba(116, 111, 105, 0.1);
}

/* 점수판 */
.scoreboard {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.score-row {
	display: flex;
	align-items: center;
	gap: 8px;
}

.score-rank {
	font-size: var(--font-sm);
	font-weight: var(--weight-bold);
	color: var(--color-dark);
	min-width: 28px;
	flex-shrink: 0;
}

.score-players {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
}

.score-chip {
	background: var(--color-white);
	border: 1px solid var(--color-light);
	border-radius: 20px;
	padding: 4px 12px;
	font-size: var(--font-sm);
	white-space: nowrap;
	box-shadow: 0 2px 8px rgba(116, 111, 105, 0.1);
}

.score-chip .score-val {
	color: var(--color-dark);
	font-weight: var(--weight-bold);
	margin-left: 6px;
}

/* 대기실 */
.waiting-room {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.waiting-section,
.waiting-section-inner {
	padding: 16px;
}

.waiting-section {
	background: var(--color-white);
	border-radius: 12px;
	margin-bottom: 12px;
	box-shadow: 0 2px 8px rgba(116, 111, 105, 0.1);
}

.waiting-top-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
	align-items: stretch;
	margin-bottom: 12px;
}

.waiting-top-row > .waiting-section {
	min-width: 0;
	min-height: 0;
	margin-bottom: 0;
	display: flex;
	flex-direction: column;
}

.waiting-section.waiting-section-players {
	position: relative;
	padding: 0;
}

.waiting-section-inner {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
}

.waiting-section-chat {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.section-label {
	font-size: var(--font-md);
	color: var(--color-dark);
	margin-bottom: 12px;
	text-align: left;
}

.game-section .section-label {
	margin-bottom: 8px;
}

.player-count {
	background: var(--color-dark);
	color: var(--color-light);
	font-size: var(--font-sm);
	padding: 1px 8px;
	border-radius: 10px;
	margin-left: 4px;
}

.setting-grid {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.setting-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: var(--font-sm);
}

.setting-key {
	color: var(--color-dark);
}

.setting-value {
	font-weight: var(--weight-bold);
	color: var(--color-dark);
}

.player-list {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.player-item {
	padding: 5px 10px;
	background: var(--color-bg);
	border-radius: 8px;
	display: flex;
	justify-content: space-between;
	font-size: var(--font-sm);
}

.player-item.is-host {
	background: var(--color-dark);
	color: var(--color-white);
}

.player-item .ready-badge {
	font-size: var(--font-sm);
	color: var(--color-green);
	font-weight: var(--weight-bold);
}

.player-item .not-ready-badge {
	font-size: var(--font-sm);
	color: var(--color-red);
}

#start-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

#ready-btn:disabled {
	opacity: 0.6;
	cursor: default;
}

/* 결과 화면 */
.result-screen {
	text-align: center;
	flex: 1;
	min-height: 0;
}

.result-screen h1 {
	margin-bottom: 24px;
}

.ranking-list {
	margin-bottom: 24px;
}

.ranking-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 14px 16px;
	background: var(--color-white);
	border-radius: 12px;
	margin-bottom: 8px;
	box-shadow: 0 2px 8px rgba(116, 111, 105, 0.1);
}

.ranking-item.first {
	background: var(--color-white);
	border: 2px solid var(--color-dark);
}

.ranking-item .rank {
	font-size: var(--font-lg);
	font-weight: var(--weight-bold);
	width: 36px;
}

.ranking-item .rank-name {
	flex: 1;
	text-align: left;
	margin-left: 12px;
	font-size: var(--font-md);
}

.ranking-item .rank-score {
	font-size: var(--font-lg);
	font-weight: var(--weight-bold);
	color: var(--color-dark);
}

/* 카테고리 전용 모드 */
.question-text.category-only {
	font-size: 2.5rem;
	font-weight: var(--weight-bold);
	color: var(--color-dark);
}

.quiz-image {
	max-width: 100%;
	max-height: 280px;
	border-radius: 8px;
	object-fit: contain;
}

/* 토글 스위치 */
.toggle-group {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.toggle-group > label:first-child {
	margin-bottom: 0;
}

.toggle {
	position: relative;
	display: inline-block;
	width: 48px;
	height: 28px;
	flex-shrink: 0;
}

.toggle input {
	opacity: 0;
	width: 0;
	height: 0;
	position: absolute;
}

.toggle-slider {
	position: absolute;
	cursor: pointer;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: var(--color-mid);
	border-radius: 28px;
	transition: background 0.2s;
}

.toggle-slider::before {
	content: "";
	position: absolute;
	width: 22px;
	height: 22px;
	left: 3px;
	bottom: 3px;
	background: var(--color-white);
	border-radius: 50%;
	transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
	background: var(--color-dark);
}

.toggle input:checked + .toggle-slider::before {
	transform: translateX(20px);
}

/* 모바일 최적화 */
@media (max-width: 520px) {
	:root {
		--font-xl: 1.4rem;
		--font-lg: 1.05rem;
		--font-md: 0.95rem;
		--font-sm: 0.8rem;
	}

	body {
		padding: 0;
		background: var(--color-light);
	}

	.container {
		max-width: 100%;
		height: 100dvh;
		border-radius: 0;
		border: none;
		padding: 0 12px;
	}

	.top-bar {
		margin: 0 -12px 12px -12px;
		border-radius: 0;
	}

	.room-card {
		padding: 12px;
		margin-bottom: 8px;
		border-radius: 10px;
	}

	.modal {
		width: 94%;
		padding: 20px;
		border-radius: 14px;
	}

	.input-group {
		margin-bottom: 10px;
	}

	input,
	select {
		padding: 12px;
		border-radius: 10px;
	}

	.btn {
		padding: 12px;
		border-radius: 10px;
	}

	.waiting-section,
	.waiting-section-inner {
		padding: 12px;
	}

	.waiting-section {
		margin-bottom: 8px;
		border-radius: 10px;
	}

	.setting-grid {
		gap: 4px;
	}

	.setting-item {
		font-size: var(--font-sm);
	}

	.question-area {
		padding: 14px;
		margin-bottom: 8px;
		min-height: 90px;
		border-radius: 10px;
	}

	.game-section {
		padding: 12px;
		margin-bottom: 8px;
		border-radius: 10px;
	}

	.game-header {
		padding: 8px 12px;
		margin: 0 -12px 6px -12px;
	}

	.chat-input input {
		padding: 10px 14px;
	}

	.chat-input .btn {
		padding: 10px 16px;
	}

	.ranking-item {
		padding: 12px 14px;
		border-radius: 10px;
	}
}

/* 세로가 작은 모바일 */
@media (max-width: 520px) and (max-height: 700px) {
	:root {
		--font-xl: 1.2rem;
		--font-lg: 0.95rem;
		--font-md: 0.85rem;
		--font-sm: 0.75rem;
	}

	.top-bar {
		margin-bottom: 8px;
	}

	.waiting-section,
	.waiting-section-inner {
		padding: 8px 10px;
	}

	.waiting-section {
		margin-bottom: 6px;
	}

	.section-label {
		margin-bottom: 6px;
	}

	.setting-grid {
		gap: 2px;
	}

	.player-item {
		padding: 6px 8px;
	}

	.btn {
		padding: 10px;
	}

	.question-area {
		padding: 10px;
		min-height: 70px;
		margin-bottom: 6px;
	}

	.game-header {
		padding: 4px 12px;
		margin: 0 -12px 6px -12px;
	}

	.timer-bar {
		height: 8px;
	}

	.game-section {
		padding: 8px 10px;
		margin-bottom: 6px;
	}

	.chat-msg {
		padding: 4px 10px;
		font-size: var(--font-sm);
	}

	.chat-input {
		padding-top: 4px;
		gap: 6px;
	}

	.chat-input input {
		padding: 8px 12px;
	}

	.chat-input .btn {
		padding: 8px 14px;
	}

	.modal {
		padding: 16px;
	}

	.input-group {
		margin-bottom: 8px;
	}

	input,
	select {
		padding: 10px;
	}

	.ranking-item {
		padding: 10px 12px;
		margin-bottom: 6px;
	}
}

/* 재접속 배너 */
.reconnect-banner {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	padding: 8px;
	background: #f59e0b;
	color: #000;
	text-align: center;
	font-weight: var(--weight-bold);
	z-index: 9999;
}

/* 에러 페이지 */
.error-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	gap: 12px;
}

.error-code {
	font-size: 4rem;
	line-height: 1;
}

/* 중앙 정렬 메시지 (로딩, 빈 상태 등) */
.centered-message {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 80px 0;
	gap: 16px;
	color: var(--color-dark);
}
.spinner {
	width: 36px;
	height: 36px;
	border: 3px solid var(--color-light);
	border-top-color: var(--color-dark);
	border-radius: 50%;
	animation: spin 0.7s linear infinite;
}
@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* 숨기기 */
.hidden {
	display: none;
}
