/* ==========================================================================
   Story Page — Character Life Journey
   Requires: reset.css, theme.css
   ========================================================================== */

/* --- Scenario color codes (shared with scenario.css) --- */
#s-1 {
	--scenario-color: green;
	--scenario-bg: rgb(238, 255, 238);
}

#s-2 {
	--scenario-color: rgb(177, 128, 22);
	--scenario-bg: rgb(255, 245, 223);
}

#s-3 {
	--scenario-color: rgb(192, 26, 26);
	--scenario-bg: rgb(255, 227, 227);
}

/* --- Page Header: selection preview --- */
header {
	width: 100%;
	padding: var(--spacing-md) 5%;
	background: var(--color-primary-light);
	display: grid;
	grid-template-areas: "a b";
	align-items: center;
	gap: var(--spacing-md);
	border-bottom: 0.0625rem solid var(--color-border);

	@media screen and (width < 768px) {
		padding-top: 1.8rem;
		grid-template-areas: "a b" "c c";
	}

	& > a {
		grid-area: a;
		font-size: 1rem;
		color: var(--color-primary);
		font-weight: 600;

		&:hover {
			color: var(--color-primary-dark);
		}
	}

	& > div {
		grid-area: b;
		display: flex;
		align-items: center;
		justify-content: space-between;

		@media screen and (width < 768px) {
			grid-area: c;
			justify-content: space-evenly;
		}

		& a {
			font-size: 0.7rem;
			color: var(--color-primary);

			&:hover {
				color: var(--color-primary-dark);
			}
		}

		& > .scenario {
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: var(--spacing-xs);

			& h2 {
				font-size: 1.1rem;
				color: var(--scenario-color);
			}

			& h5 {
				background: var(--scenario-color);
				color: #ffffff;
				font-size: 0.75rem;
				font-weight: 700;
				padding: 0.25rem 0.75rem;
				border-radius: var(--radius-lg);
			}
		}

		& > .character {
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: var(--spacing-xs);

			& > div {
				display: flex;
				align-items: center;
				gap: var(--spacing-xs);

				& img {
					width: 3rem;
					height: 3rem;
				}

				& h2 {
					font-size: 1.5rem;
					color: var(--color-text);
				}
			}
		}
	}
}

/* --- Main Layout: top nav + content --- */
main {
	width: 90%;
	margin: auto;
	display: grid;
	grid-template-columns: 1fr 2fr;
	grid-template-rows: 1fr;
	gap: var(--spacing-lg);
	padding-block: var(--spacing-md);
	min-height: 80vh;

	@media screen and (width < 768px) {
		display: flex;
		flex-direction: column-reverse;
	}

	/* --- Navigation Section --- */
	& > .nav {
		display: flex;
		flex-direction: column;
		gap: var(--spacing-lg);
		height: fit-content;

		/* --- Timeline Nav --- */
		& > nav#life-step {
			display: flex;
			flex-direction: column;
			gap: var(--spacing-sm);
			padding-bottom: var(--spacing-lg);
			border-bottom: 0.0625rem solid var(--color-border);

			& > h3 {
				font-size: 0.85rem;
				text-transform: uppercase;
				letter-spacing: 0.05em;
				color: var(--color-text-muted);
				font-weight: 600;
				margin-right: var(--spacing-sm);
			}

			& > form {
				flex: 1 1 auto;
				min-width: 10rem;

				& .step-card {
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					width: 100%;
					text-align: left;
					background: var(--color-surface);
					border: 0.0625rem solid var(--color-border);
					border-radius: var(--radius-sm);
					padding: var(--spacing-xs) var(--spacing-sm);
					transition:
						border-color 0.2s ease,
						box-shadow 0.2s ease,
						background-color 0.2s ease;

					&:hover {
						border-color: var(--color-primary);
						box-shadow: var(--shadow-card-hover);
					}

					&.active {
						border-color: var(--color-primary);
						box-shadow: var(--shadow-card);

						& h4 {
							color: var(--color-primary-dark);
						}

						& p {
							color: var(--color-text-muted);
						}
					}

					& h4 {
						font-size: 0.9rem;
						font-weight: 600;
						color: var(--color-text);
						margin-bottom: 0.125rem;
					}

					& p {
						font-size: 0.8rem;
						color: var(--color-text-muted);
					}
				}
			}
		}

		/* --- Scenario Switcher Nav --- */
		& > nav#change-scenario {
			& > .scenario-switcher {
				& > h3 {
					font-size: 0.85rem;
					text-transform: uppercase;
					letter-spacing: 0.05em;
					color: var(--color-text-muted);
					font-weight: 600;
					margin-bottom: var(--spacing-sm);
				}

				& > .scenario-switcher-grid {
					display: grid;
					grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
					gap: var(--spacing-sm);

					& > form {
						& .scenario-option {
							display: flex;
							flex-direction: column;
							align-items: flex-start;
							gap: 0.25rem;
							width: 100%;
							text-align: left;
							background: var(--scenario-bg);
							border: 0.0625rem solid var(--color-border);
							border-left: 0.25rem solid var(--scenario-color);
							border-radius: var(--radius-sm);
							padding: var(--spacing-sm);
							transition:
								box-shadow 0.2s ease,
								border-color 0.2s ease;

							&:hover {
								border-color: var(--scenario-color);
								box-shadow: var(--shadow-card-hover);
							}

							& h4 {
								font-size: 0.95rem;
								font-weight: 600;
								color: var(--color-text);
							}

							& h5 {
								font-size: 0.8rem;
								color: var(--scenario-color);
								font-weight: 700;
							}
						}
					}
				}
			}
		}
	}

	/* --- Story Content Wrapper --- */
	& > .story-content {
		display: flex;
		flex-direction: column;
		gap: var(--spacing-md);

		/* --- Content area: story header --- */
		& > .header {
			display: flex;
			height: fit-content;
			justify-content: space-between;
			align-items: center;
			background: var(--color-surface);
			border: 0.0625rem solid var(--color-border);
			border-radius: var(--radius-md);
			padding: var(--spacing-md) var(--spacing-lg);
			box-shadow: var(--shadow-card);

			& > div:first-child {
				& h1 {
					font-size: clamp(1.2rem, 2.5vw, 1.6rem);
					margin-bottom: 0.25rem;
				}

				& p {
					font-size: 0.9rem;
				}
			}

			& > div:last-child {
				& h5 {
					background: var(--scenario-bg);
					color: var(--scenario-color);
					border: 1px solid var(--scenario-color);
					font-size: 0.8rem;
					font-weight: 700;
					padding: 0.3rem 0.85rem;
					border-radius: var(--radius-lg);
					white-space: nowrap;
				}
			}
		}

		/* --- Story content: image + text block --- */
		& > section.story {
			& > p {
				font-size: 1.05rem;
				line-height: 1.75;
				color: var(--color-text);
				max-width: none;
				margin-bottom: var(--spacing-md);
			}

			& > img {
				border-radius: var(--radius-md);
				box-shadow: var(--shadow-card);
				margin-bottom: var(--spacing-md);
			}
		}
	}
}

/* --- Outro Section (Impacts + End-of-journey) --- */
.outro {
	display: grid;
	grid-template-columns: 2fr 3fr;
	gap: 5rem;
	width: 90%;
	margin: var(--spacing-lg) auto;
	margin-bottom: var(--spacing-xl);

	@media screen and (width < 768px) {
		grid-template-columns: 1fr;
	}

	/* --- Impacts section --- */
	& .impacts {

		& > h2 {
			margin-bottom: var(--spacing-md);
		}

		& > .impact-list {
			display: grid;
			grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
			gap: var(--spacing-md);

			& > .impact-card {
				display: flex;
				gap: var(--spacing-sm);
				background: var(--color-surface);
				border: 0.0625rem solid var(--color-border);
				border-radius: var(--radius-md);
				padding: var(--spacing-md);
				box-shadow: var(--shadow-card);
				transition:
					border-color 0.25s ease,
					box-shadow 0.25s ease;

				&:hover {
					border-color: var(--color-primary);
					box-shadow: var(--shadow-card-hover);
				}

				& > img {
					width: 2.5rem;
					height: 2.5rem;
					object-fit: contain;
					flex-shrink: 0;
				}

				& > div {
					& h3 {
						font-size: 1rem;
						margin-bottom: var(--spacing-xs);
					}

					& p {
						font-size: 0.875rem;
						max-width: none;
					}
				}
			}
		}

		& .rating-block {
			margin-top: var(--spacing-lg);
			padding-top: var(--spacing-md);
			border-top: 1px solid var(--color-border);

			& h3 {
				font-size: 1.1rem;
				margin-bottom: var(--spacing-sm);
				color: var(--color-primary-dark);
			}

			& .rating-buttons {
				display: flex;
				gap: var(--spacing-md);
				justify-content: center;

				& .btn-vote {
					display: flex;
					align-items: center;
					gap: 0.5rem;
					padding: 0.6rem 1.2rem;
					border-radius: var(--radius-sm);
					border: 1px solid var(--color-border);
					background: var(--color-surface);
					cursor: pointer;
					font-weight: 600;
					transition: all 0.2s ease;

					&:hover {
						transform: translateY(-2px);
						box-shadow: var(--shadow-card);
					}

					&.like:hover {
						border-color: #28a745;
						color: #28a745;
						background: #e8f5e9;
					}

					&.dislike:hover {
						border-color: #dc3545;
						color: #dc3545;
						background: #fdecea;
					}

					& .count {
						font-size: 0.9rem;
						color: var(--color-text-muted);
					}
				}
			}
		}
	}

	/* --- End-of-journey section --- */
	& .end {
		background: var(--color-primary-light);
		border-radius: var(--radius-md);
		padding: var(--spacing-lg);

		@media (max-width: 48rem) {
			padding: var(--spacing-md);
		}

		& h3 {
			margin-bottom: var(--spacing-xs);
		}

		& > p {
			max-width: none;
			margin-bottom: var(--spacing-md);

			& > a {
				font-weight: 600;
			}
		}

		& > .sources-box {
			background: var(--color-surface);
			border: 0.0625rem solid var(--color-border);
			border-left: 0.25rem solid var(--color-primary);
			border-radius: var(--radius-sm);
			padding: var(--spacing-sm) var(--spacing-md);
			margin-bottom: var(--spacing-md);

			& h4 {
				font-size: 0.9rem;
				font-weight: 600;
				margin-bottom: var(--spacing-xs);
			}

			& p {
				font-size: 0.875rem;
				max-width: none;
			}

			& a {
				color: var(--color-primary);
				font-weight: 600;

				&:hover {
					color: var(--color-primary-dark);
				}
			}
		}

		& > .buttons {
			display: flex;
			flex-direction: column;
			gap: var(--spacing-sm);

			& > a {
				display: inline-block;
				color: var(--color-primary);
				font-weight: 600;
				margin-top: var(--spacing-xs);

				&:hover {
					color: var(--color-primary-dark);
				}
			}
		}
	}
}

/* --- Scenario Details Modal --- */
.modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	width: 100vw;
	height: 100vh;
	background: rgba(26, 31, 46, 0.6);
	backdrop-filter: blur(4px);
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 1000;
	opacity: 1;
	visibility: visible;
	transition:
		opacity 0.3s ease,
		visibility 0.3s ease;
}

.modal-overlay.hidden {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.modal-content {
	position: relative;
	max-width: 32rem;
	width: 90%;
	max-height: 90vh;
	overflow-y: auto;
	background: var(--color-surface);
	border-radius: var(--radius-md);
	padding: var(--spacing-lg);
	box-shadow: var(--shadow-card-hover);
	border-left: 0.5rem solid var(--scenario-color);
	transform: translateY(0);
	transition: transform 0.3s ease;

	@media screen and (width < 768px) {
		padding: var(--spacing-md);
		.btn-primary {
			padding: var(--spacing-sm) var(--spacing-md);
		}
	}
}

.modal-overlay.hidden .modal-content {
	transform: translateY(1rem);
}

.modal-close {
	position: absolute;
	top: 1rem;
	right: 1rem;
	background: transparent;
	border: none;
	font-size: 1.5rem;
	line-height: 1;
	color: var(--color-text-muted);
	cursor: pointer;
	transition: color 0.2s ease;
}

.modal-close:hover {
	color: var(--color-text);
}
