/*
 * Takumi PWA front-end styles.
 *
 * Colors come from custom properties set inline by TKPwa_Frontend:
 * --tkpwa-theme, --tkpwa-bg, --tkpwa-accent, --tkpwa-on-accent.
 * App-only pieces key off html.tkpwa-standalone.
 */

/* ---------- Show / hide by mode ---------- */

html.tkpwa-standalone .tkpwa-hide-in-app,
html:not(.tkpwa-standalone) .tkpwa-only-in-app {
	display: none !important;
}

/* ---------- Install banner ---------- */

.tkpwa-install {
	position: fixed;
	left: 12px;
	right: 12px;
	bottom: calc(12px + env(safe-area-inset-bottom, 0px));
	z-index: 999998;
	max-width: 480px;
	margin: 0 auto;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: #fff;
	color: #1d2327;
	border-radius: 14px;
	box-shadow: 0 2px 6px rgba(0, 0, 0, .1), 0 12px 32px rgba(0, 0, 0, .14);
	font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
	transform: translateY(calc(100% + 24px));
	opacity: 0;
	transition: transform .35s ease, opacity .35s ease;
}

.tkpwa-install.is-visible {
	transform: none;
	opacity: 1;
}

.tkpwa-install__icon {
	flex: none;
	width: 48px;
	height: 48px;
	border-radius: 11px;
}

.tkpwa-install__body {
	flex: 1;
	min-width: 0;
}

.tkpwa-install__title {
	display: block;
	font-weight: 700;
}

.tkpwa-install__text {
	margin: 2px 0 0;
	font-size: 13px;
	color: #50575e;
}

.tkpwa-install__steps {
	margin: 6px 0 0;
	padding: 0;
	list-style: none;
	counter-reset: tkpwa-step;
	font-size: 14px;
}

.tkpwa-install__steps li {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 4px;
	counter-increment: tkpwa-step;
}

.tkpwa-install__steps li::before {
	content: counter(tkpwa-step);
	flex: none;
	width: 20px;
	height: 20px;
	display: grid;
	place-items: center;
	border-radius: 50%;
	background: #f0f0f1;
	font-size: 12px;
	font-weight: 700;
}

.tkpwa-install__glyph {
	flex: none;
	display: inline-flex;
	color: #007aff;
}

.tkpwa-install__action {
	flex: none;
	border: 0;
	border-radius: 999px;
	padding: 8px 18px;
	font: inherit;
	font-weight: 700;
	background: var(--tkpwa-accent, #1d2327);
	color: var(--tkpwa-on-accent, #fff);
	cursor: pointer;
}

.tkpwa-install__close {
	flex: none;
	align-self: flex-start;
	width: 32px;
	height: 32px;
	margin: -6px -8px 0 0;
	border: 0;
	background: transparent;
	color: #50575e;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
}

/* On iPhone the Share button sits in the bottom toolbar; point at it. */
.tkpwa-install--ios::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: -8px;
	width: 16px;
	height: 16px;
	background: #fff;
	transform: translateX(-50%) rotate(45deg);
}

/* ---------- Bottom navigation (app mode only) ---------- */

.tkpwa-bottom-nav {
	display: none;
}

html.tkpwa-standalone .tkpwa-bottom-nav {
	display: block;
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 999990;
	padding-bottom: env(safe-area-inset-bottom, 0px);
	background: var(--tkpwa-bg, #fff);
	border-top: 1px solid rgba(0, 0, 0, .1);
	font: 11px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

html.tkpwa-standalone body:has(.tkpwa-bottom-nav) {
	padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

.tkpwa-bottom-nav ul {
	display: flex;
	margin: 0;
	padding: 0;
	list-style: none;
}

.tkpwa-bottom-nav li {
	flex: 1;
	min-width: 0;
	margin: 0;
}

.tkpwa-bottom-nav a {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 3px;
	height: 60px;
	padding: 0 4px;
	color: inherit;
	opacity: .65;
	text-decoration: none;
}

.tkpwa-bottom-nav a[aria-current="page"] {
	opacity: 1;
	color: var(--tkpwa-accent, inherit);
	font-weight: 700;
}

.tkpwa-bottom-nav__label {
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Toasts must clear the bar. */
html.tkpwa-standalone body:has(.tkpwa-bottom-nav) .tkpwa-toast {
	bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}

/* ---------- Loading screen ---------- */

.tkpwa-loading {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 24px;
	background: var(--tkpwa-bg, #fff);
	opacity: 0;
	visibility: hidden;
	transition: opacity .2s ease, visibility 0s linear .2s;
}

.tkpwa-loading.is-visible {
	opacity: 1;
	visibility: visible;
	transition: opacity .2s ease;
}

.tkpwa-loading img {
	width: 96px;
	height: 96px;
	border-radius: 22px;
}

.tkpwa-loading__spinner {
	width: 28px;
	height: 28px;
	border: 3px solid rgba(127, 127, 127, .25);
	border-top-color: var(--tkpwa-accent, #1d2327);
	border-radius: 50%;
	animation: tkpwa-spin .8s linear infinite;
}

@keyframes tkpwa-spin {
	to {
		transform: rotate(360deg);
	}
}

/* ---------- Pull to refresh ---------- */

.tkpwa-ptr {
	position: fixed;
	top: env(safe-area-inset-top, 0px);
	left: 50%;
	z-index: 999997;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 14px;
	border-radius: 999px;
	background: #fff;
	color: #1d2327;
	box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
	font: 13px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
	transform: translate(-50%, -48px);
	pointer-events: none;
}

.tkpwa-ptr__arrow {
	transition: transform .2s ease;
}

.tkpwa-ptr.is-ready .tkpwa-ptr__arrow {
	transform: rotate(180deg);
}

.tkpwa-ptr.is-loading .tkpwa-ptr__arrow {
	animation: tkpwa-spin .8s linear infinite;
}

/* ---------- Scroll progress ---------- */

.tkpwa-progress {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 999996;
	height: 3px;
	background: var(--tkpwa-accent, #1d2327);
	transform: scaleX(0);
	transform-origin: 0 50%;
	pointer-events: none;
}

.admin-bar .tkpwa-progress {
	top: 32px;
}

@media screen and (max-width: 782px) {
	.admin-bar .tkpwa-progress {
		top: 46px;
	}
}

/* ---------- Toast ---------- */

.tkpwa-toast {
	position: fixed;
	left: 12px;
	right: 12px;
	bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	z-index: 999999;
	max-width: 480px;
	margin: 0 auto;
	padding: 12px 16px;
	border-radius: 10px;
	background: #1d2327;
	color: #fff;
	font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
	opacity: 0;
	transform: translateY(12px);
	transition: opacity .3s ease, transform .3s ease;
}

.tkpwa-toast.is-visible {
	opacity: 1;
	transform: none;
}

/* ---------- Install button shortcode ---------- */

.tkpwa-install-button[hidden] {
	display: none !important;
}

@media (prefers-reduced-motion: reduce) {
	.tkpwa-install,
	.tkpwa-toast,
	.tkpwa-loading {
		transition: none;
	}
}
