/* =====================================================================
   flags.css – the flags page (flagg.html)
   ---------------------------------------------------------------------
   Sections:
     1. Top (home link + title)
     2. Sticky filter menu
     3. Filter buttons ("chips")
     4. The half-moon button that hides / shows the menu
     5. Flag grid
     6. Flip cards (flag on the front, name + capital on the back)
     7. Phones
   Colours and fonts come from common.css.
   ===================================================================== */

/* This page may be a little wider than the front page */
:root { --max: 1240px; --card-back: #383f48; }


/* ---------- 1. Top ---------- */
.top { display: flex; align-items: center; gap: 16px; padding: 22px 24px 16px; }

/* "← Piña" link back to the front page */
.home {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	color: var(--dark);
	font-weight: 600;
	text-decoration: none;
	font-size: .9rem;
}
.home img { width: 28px; height: 28px; }
.home:hover { color: var(--primary); }

h1 {
	margin: 0 0 0 auto;   /* "auto" pushes the title to the right */
	color: var(--dark);
	font-size: clamp(1rem, 3vw, 1.4rem);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .02em;
	line-height: 1.3;
}


/* ---------- 2. Sticky filter menu ----------
   .bar sticks to the top of the screen while you scroll.
   .panel is the white part with the filters. When .bar has the class
   "closed" (set by flags.js), the panel shrinks to zero height.      */
.bar { position: sticky; top: 0; z-index: 20; }

.panel {
	background: rgba(255, 255, 255, .97);
	border-top: 1px solid var(--line);
	border-bottom: 1px solid var(--line);
	box-shadow: 0 6px 18px rgba(0, 0, 0, .06);
	overflow: hidden;
	transition: max-height .35s ease, opacity .25s ease;   /* max-height is set by flags.js */
}
.bar.closed .panel { max-height: 0 !important; opacity: 0; border-width: 0; }

.panel-inner { padding: 10px 24px 12px; }

/* One filter row: a small grey label + the buttons */
.row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.row-label {
	flex: 0 0 64px;
	font-size: .68rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .06em;
	color: #aaa;
}
.chips { display: flex; flex-wrap: wrap; gap: 2px 4px; }

/* "Viser 54 av 195 flagg   Nullstill" */
.status { display: flex; align-items: center; gap: 14px; margin-top: 6px; font-size: .78rem; }
.status strong { color: var(--dark); }
.reset {
	border: 0;
	background: none;
	color: var(--primary);
	cursor: pointer;
	padding: 2px 0;
	font-size: .78rem;
	text-decoration: underline;
}
.reset:disabled { color: #ccc; text-decoration: none; cursor: default; }


/* ---------- 3. Filter buttons ("chips") ----------
   Three looks, all set by flags.js:
     normal              – can be clicked
     aria-pressed="true" – the chosen option (blue)
     disabled            – would show no flags with the other choices (light grey)  */
.chip {
	border: 0;
	background: none;
	padding: 6px 10px;
	border-radius: 99px;
	font-size: .72rem;
	text-transform: uppercase;
	letter-spacing: .02em;
	color: #555;
	cursor: pointer;
	white-space: nowrap;
	flex-shrink: 0;        /* never squeeze a chip; on phones the row scrolls instead */
	transition: background .15s, color .15s;
}
.chip:hover:not(:disabled) { background: #f1f1f1; color: var(--dark); }
.chip[aria-pressed="true"] { background: var(--primary); color: #fff; }
.chip:disabled { color: #d0d0d0; cursor: default; }
.chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Letter buttons are narrower, except "Alle" */
.row.letters .chip { min-width: 30px; padding: 6px 7px; }
.row.letters .chip:first-child { padding: 6px 10px; }


/* ---------- 4. Half-moon button ----------
   Hangs just below the menu (top: 100%). When the menu is closed,
   the menu has no height, so the half-moon hangs from the top of the
   screen instead. The arrow turns around, and a red badge shows how
   many filters are active.                                           */
.moon {
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	width: 64px;
	height: 30px;
	border: 0;
	border-radius: 0 0 32px 32px;   /* rounded only at the bottom = half circle */
	background: var(--primary);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 4px 10px rgba(0, 0, 0, .15);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 0 4px;
}
.moon:hover { background: var(--primary-hover); }
.moon:focus-visible { outline: 3px solid #9fd6f2; }

.moon svg { width: 18px; height: 18px; transition: transform .3s; }
.bar.closed .moon svg { transform: rotate(180deg); }

/* Red number badge – only visible when the menu is closed and a filter is on */
.moon .count {
	position: absolute;
	top: 2px;
	right: 6px;
	min-width: 16px;
	height: 16px;
	border-radius: 8px;
	background: var(--accent);
	font-size: .6rem;
	font-weight: 700;
	line-height: 16px;
	display: none;
}
.bar.closed .moon .count:not(:empty) { display: block; }


/* ---------- 5. Flag grid ----------
   As many 200px-wide flags per row as fit on the screen.             */
.flags {
	list-style: none;
	margin: 0;
	padding: 44px 0 60px;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
	gap: 20px;
}
.flags li[hidden] { display: none; }   /* flags.js hides flags that don't match the filters */


/* ---------- 6. Flip cards ----------
   Each card has a front (.front, the flag) and a back (.back, name and
   capital) on top of each other. Turning .card-inner 180° shows the back.
   On computers it flips on hover; on phones flags.js flips it on tap
   by adding the class "flipped".                                      */
.card {
	display: block;
	width: 100%;
	aspect-ratio: 1170 / 800;   /* same shape as the flag images, so they are never cropped or squeezed */
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	perspective: 900px;         /* gives the flip a 3D look */
}
.card-inner {
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	transition: transform .6s;
	transform-style: preserve-3d;
}
@media (hover: hover) {                       /* only on devices with a mouse */
	.card:hover .card-inner { transform: rotateY(180deg); }
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }

.front,
.back {
	position: absolute;
	inset: 0;
	backface-visibility: hidden;              /* hide each side when it faces away */
	-webkit-backface-visibility: hidden;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.front { background: #f3f3f3; }               /* grey placeholder while the image loads */
.front img { display: block; width: 100%; height: 100%; }

.back {
	transform: rotateY(180deg);               /* starts turned away */
	background: var(--card-back);
	color: #fff;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 8px;
	line-height: 1.3;
}
.back .name { font-weight: 600; font-size: 1rem; }
.back .cap { font-size: .8rem; color: #c9d0d8; margin-top: 4px; }
.back .cap small {                            /* the word "HOVEDSTAD" */
	display: block;
	font-size: .62rem;
	text-transform: uppercase;
	letter-spacing: .08em;
	color: #8f99a5;
}


/* ---------- 7. Phones (screens up to 640px wide) ---------- */
@media (max-width: 640px) {
	.top, .panel-inner { padding-left: 14px; padding-right: 14px; }

	/* Each filter row becomes one line that you can swipe sideways */
	.row-label { flex-basis: 50px; font-size: .6rem; }
	.chips {
		flex-wrap: nowrap;
		overflow-x: auto;
		scrollbar-width: none;                /* hide the scrollbar (Firefox) */
		-webkit-overflow-scrolling: touch;
	}
	.chips::-webkit-scrollbar { display: none; }   /* hide the scrollbar (Chrome, Safari) */

	/* Smaller flags: three per row */
	.flags { grid-template-columns: repeat(3, 1fr); gap: 10px; padding-top: 40px; }
	.back { padding: 4px; }
	.back .name { font-size: .7rem; }
	.back .cap { font-size: .62rem; margin-top: 2px; }
	.back .cap small { display: none; }
}

/* Very narrow phones: two per row */
@media (max-width: 360px) {
	.flags { grid-template-columns: repeat(2, 1fr); }
}
