/**
 * Темизация ti4calc под оформление сайта (тёмная «неbula», золото, пергамент).
 * Загружается после index_style.css на странице battle_calc.html.
 */
:root {
	--ti4-void: #070a12;
	--ti4-card: rgba(18, 24, 42, 0.92);
	--ti4-card-border: rgba(212, 175, 55, 0.28);
	--ti4-parchment: #ede6d8;
	--ti4-muted: #b8ae9a;
	--ti4-gold: #d4af37;
	--ti4-gold-dim: #9a7b2e;
	--ti4-brand: #2a3f5c;
	--ti4-brand-hover: #354a6a;
	/* Высота ряда счётчиков ≈ колонка названия юнита */
	--ti4-counter-row-h: 3.9375rem;
}

/* battle_calc: #root оборачивает сводку + карточку калькулятора */
#root.calc-vue-root {
	max-width: 56rem;
	margin-left: auto;
	margin-right: auto;
	padding-left: 0.75rem;
	padding-right: 0.75rem;
}

#root .o-container {
	max-width: 56rem;
	padding-left: 0.75rem;
	padding-right: 0.75rem;
}

#root.calc-vue-root .o-container {
	padding-left: 0;
	padding-right: 0;
}

/* Панель: Сбросить | Космический бой | Вторжение | Сбросить */
#root.calc-vue-root .calc-toolbar.calc-toolbar--actions {
	justify-content: center;
	margin-top: 0.5rem;
}

#root.calc-vue-root .calc-toolbar__actions-row {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 0.45rem;
	justify-content: center;
	align-items: stretch;
}

#root.calc-vue-root .calc-toolbar__actions-row > .c-button.calc-toolbar__action-btn {
	min-height: var(--ti4-counter-row-h);
	height: var(--ti4-counter-row-h);
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0 0.85rem;
	border: 1px solid var(--ti4-card-border);
	border-left: 1px solid var(--ti4-card-border);
	white-space: nowrap;
	-webkit-appearance: none;
	appearance: none;
}

#root.calc-vue-root .calc-toolbar__actions-row > .c-button.calc-toolbar__btn--battle-second {
	border-left: 1px solid var(--ti4-card-border);
	padding-left: calc(0.85rem + 0.35rem);
}

#root.calc-vue-root .calc-toolbar__actions-row > .c-button.calc-toolbar__action-btn.c-button--brand,
#root.calc-vue-root .calc-toolbar__actions-row > .c-button.calc-toolbar__action-btn.c-button--ghost-brand {
	border-left-color: var(--ti4-card-border);
}

#root.calc-vue-root .calc-toolbar__reset-side {
	display: none;
}

#root #options .options-side-labels {
	display: none;
}

/* Выбор фракции — как select «повреждено» */
#root.calc-vue-root .race-select-row {
	align-items: center;
}

#root.calc-vue-root select.race-select.c-field {
	-webkit-appearance: none;
	appearance: none;
	flex: 1 1 38%;
	min-width: 0;
	min-height: 2.75rem;
	max-width: 100%;
	padding: 0.4rem 1.75rem 0.4rem 0.65rem;
	border: 1px solid var(--ti4-card-border);
	border-radius: 8px;
	background-color: rgba(10, 14, 26, 0.85);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' fill='none' stroke='%23d4af37' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.45rem center;
	background-size: 0.65rem;
	color: var(--ti4-parchment);
	font-size: 0.92rem;
	cursor: pointer;
}

#root.calc-vue-root .race-select-row .unit-name {
	flex: 0 0 auto;
	min-width: 2.5rem;
}

#root.calc-vue-root select.race-select.c-field:focus {
	border-color: var(--ti4-gold);
	outline: none;
	box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25);
}

/* Строка юнита: воздух между блоками, приглушение неактивных */
#root #counters .unit-row {
	margin-top: 0.35rem;
	margin-bottom: 0.35rem;
	padding: 0.2rem 0;
	border-radius: 8px;
	transition: opacity 0.2s ease;
	align-items: stretch;
}

#root #counters .unit-row--muted {
	opacity: 0.42;
}

#root #counters .counter.c-input-group {
	flex: 1 1 38%;
	min-width: 0;
	flex-basis: auto;
	flex-shrink: 1;
}

#root .c-input-group.counter {
	gap: 0.35rem;
	flex-wrap: nowrap;
	justify-content: center;
	align-items: stretch;
	align-self: stretch;
	min-height: var(--ti4-counter-row-h);
}

#root #counters .unit-row .unit-name {
	min-height: var(--ti4-counter-row-h);
	align-self: stretch;
	display: flex;
	align-items: center;
	justify-content: center;
}

#root #counters .o-field {
	display: flex;
	align-items: stretch;
	align-self: stretch;
	flex: 0 1 auto;
	min-width: 2.65rem;
}

#root #counters .o-field input.c-field {
	min-width: 2.5rem;
	max-width: 3.25rem;
	width: 100%;
	min-height: var(--ti4-counter-row-h);
	height: 100%;
	box-sizing: border-box;
	text-align: center;
	font-size: 1rem;
	border-left: 1px solid var(--ti4-card-border);
}

#root #counters .unit-name {
	min-width: 5.5rem;
	font-size: 0.92rem;
}

/* «+», улучшение II — разделитель слева */
#root #counters .c-input-group.counter > .o-field + .count-stepper {
	border-left: 1px solid var(--ti4-card-border);
	padding-left: 0.35rem;
}

#root #counters .c-input-group.counter > .o-field + .count-stepper + .upgrade {
	border-left: 1px solid var(--ti4-card-border);
	padding-left: 0.35rem;
}

/* Повреждено до боя: в одну линию с кнопками, единая высота */
#root #counters select.damaged {
	-webkit-appearance: none;
	appearance: none;
	min-width: 2.75rem;
	min-height: var(--ti4-counter-row-h);
	height: var(--ti4-counter-row-h);
	align-self: stretch;
	box-sizing: border-box;
	padding: 0 1.35rem 0 0.4rem;
	border: 1px solid var(--ti4-card-border);
	border-radius: 8px;
	background-color: rgba(10, 14, 26, 0.85);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' fill='none' stroke='%23d4af37' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.35rem center;
	background-size: 0.65rem;
	color: var(--ti4-parchment);
	font-size: 0.95rem;
	text-align: center;
	cursor: pointer;
	flex-shrink: 0;
}

#root #counters select.damaged:focus {
	border-color: var(--ti4-gold);
	outline: none;
	box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25);
}

#root {
	color: var(--ti4-parchment);
	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
		sans-serif;
	font-size: 0.95rem;
}

#root strong {
	color: var(--ti4-parchment);
	font-weight: 600;
}

#root .o-grid__cell.block {
	color: var(--ti4-muted);
}

#root .unit-name {
	color: var(--ti4-muted);
	font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

#root .unit-name span {
	color: var(--ti4-parchment);
}

#counters .o-grid.attacker-participates.defender-participates .unit-name {
	background: rgba(40, 55, 90, 0.55);
}

#counters .o-grid.attacker-participates .unit-name {
	background: linear-gradient(0.25turn, rgba(45, 62, 98, 0.65), rgba(45, 62, 98, 0.65) 70%, rgba(18, 24, 42, 0.2) 95%, transparent);
}

#counters .o-grid.defender-participates .unit-name {
	background: linear-gradient(-0.25turn, rgba(45, 62, 98, 0.65), rgba(45, 62, 98, 0.65) 70%, rgba(18, 24, 42, 0.2) 95%, transparent);
}

#root .c-field,
#root select.c-field {
	background: rgba(10, 14, 26, 0.85);
	border-color: var(--ti4-card-border);
	color: var(--ti4-parchment);
}

#root .c-field:focus,
#root select.c-field:focus {
	border-color: var(--ti4-gold);
	outline: none;
	box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25);
}

#root .c-button--brand {
	background: var(--ti4-brand);
	border-color: rgba(212, 175, 55, 0.35);
	color: var(--ti4-parchment);
}

#root .c-button--brand:not(:disabled):hover {
	background: var(--ti4-brand-hover);
}

#root .c-button--ghost-brand {
	border-color: rgba(212, 175, 55, 0.45);
	color: var(--ti4-gold);
	background: rgba(10, 14, 26, 0.4);
}

#root .c-button--ghost-brand:not(:disabled):hover {
	background: rgba(212, 175, 55, 0.15);
	color: var(--ti4-parchment);
}

#root .c-button.count-stepper,
#root .c-button.upgrade {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 2.25rem;
	min-height: 2.25rem;
	padding: 0.25rem;
	-webkit-appearance: none;
	appearance: none;
}

#root #counters .c-button.count-stepper,
#root #counters .c-button.upgrade {
	min-width: var(--ti4-counter-row-h);
	min-height: var(--ti4-counter-row-h);
	width: var(--ti4-counter-row-h);
	height: var(--ti4-counter-row-h);
	box-sizing: border-box;
	flex-shrink: 0;
	align-self: stretch;
}

#root .c-button.count-stepper svg,
#root .c-button.upgrade svg {
	display: block;
	flex-shrink: 0;
}

#root #options,
#root #help {
	background: var(--ti4-card);
	border: 1px solid var(--ti4-card-border);
	border-radius: 12px;
	padding: 0.75rem 1rem 1rem;
	margin-top: 0.75rem;
}

/* Ячейка с кнопкой «?» между колонками опций — не схлопывать (иначе ломаются подсказки/клик) */
#root #options .o-grid.center-grid > .o-grid__cell:not(.left-option):not(.right-option) {
	flex: 0 0 auto;
	min-width: 2rem;
	display: flex;
	align-items: center;
	justify-content: center;
	align-self: center;
}

#root #options .help {
	position: relative;
	z-index: 3;
}

#root #options .heading {
	color: var(--ti4-gold-dim);
	font-family: ui-sans-serif, system-ui, sans-serif;
	font-size: 0.72rem;
	letter-spacing: 0.14em;
	text-transform: uppercase;
}

#root .left-option label,
#root .right-option label {
	color: var(--ti4-muted);
}

.loading-spinner {
	border-color: rgba(212, 175, 55, 0.45);
	border-right-color: transparent;
}

/* Кнопка «?» справки по опции — без текстового символа в псевдоэлементе (Safari) */
#root .help {
	width: 1.35rem;
	height: 1.35rem;
	min-width: 1.35rem;
	min-height: 1.35rem;
	padding: 0;
	border-radius: 50%;
	border: 1px solid rgba(212, 175, 55, 0.5);
	background: rgba(40, 55, 90, 0.6);
	position: relative;
	-webkit-appearance: none;
	appearance: none;
	cursor: help;
	vertical-align: middle;
}

#root .help::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 0.65rem;
	height: 0.65rem;
	background: no-repeat center / contain
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Ccircle cx='6' cy='3.5' r='1.3' fill='%23d4af37'/%3E%3Crect x='5' y='6' width='2' height='4.5' rx='0.6' fill='%23d4af37'/%3E%3C/svg%3E");
}

#root #totals .block {
	color: var(--ti4-muted);
}

/* Сводка вероятностей (на battle_calc — над карточкой, под шапкой страницы) */
.calc-vue-root > .chart-summary-row {
	margin-top: 0.35rem;
	margin-bottom: 0.5rem;
}

.chart-summary-row {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.65rem;
	margin: 0;
	max-width: none;
}

@media (max-width: 36rem) {
	.chart-summary-row {
		grid-template-columns: 1fr;
	}
}

.chart-summary-row__card {
	background: rgba(18, 24, 42, 0.88);
	border: 1px solid var(--ti4-card-border);
	border-radius: 12px;
	padding: 0.65rem 0.85rem;
	text-align: center;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.chart-summary-row__label {
	display: block;
	font-family: ui-sans-serif, system-ui, sans-serif;
	font-size: 0.68rem;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--ti4-muted);
	margin-bottom: 0.25rem;
}

.chart-summary-row__value {
	font-family: ui-sans-serif, system-ui, sans-serif;
	font-size: clamp(1.35rem, 3.5vw, 1.75rem);
	font-weight: 700;
	letter-spacing: 0.02em;
}

.chart-summary-row__card--att .chart-summary-row__value {
	color: #e8a0a0;
}

.chart-summary-row__card--draw .chart-summary-row__value {
	color: #c4bba8;
}

.chart-summary-row__card--def .chart-summary-row__value {
	color: #9ec5f0;
}

/* Индикатор пересчёта — между сводкой и карточкой */
#root .calc-computing-bar {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.65rem;
	margin-top: 0;
	margin-bottom: 0.65rem;
	padding: 0.5rem 0.75rem;
	background: var(--ti4-card);
	border: 1px solid var(--ti4-card-border);
	border-radius: 12px;
	font-family: ui-sans-serif, system-ui, sans-serif;
	font-size: 0.88rem;
	color: var(--ti4-muted);
}

#root .calc-computing-bar .loading-spinner {
	width: 1.35rem;
	height: 1.35rem;
	border-width: 2px;
	flex-shrink: 0;
}

@media (max-width: 767px) {
	body.page-battle-calc {
		overflow-x: hidden;
	}

	body.page-battle-calc .wrap {
		max-width: none;
		padding-top: 0.85rem;
	}

	body.page-battle-calc .back {
		display: none;
	}

	body.page-battle-calc .page-head {
		margin-bottom: 0.85rem;
	}

	body.page-battle-calc .page-head h1 {
		font-size: clamp(1.35rem, 8vw, 1.75rem);
		line-height: 1.15;
	}

	body.page-battle-calc .page-head .subtitle {
		font-size: 0.72rem;
		letter-spacing: 0.12em;
		line-height: 1.35;
	}

	#root.calc-vue-root {
		--ti4-counter-row-h: 3rem;
		width: 100%;
		max-width: none;
		padding-left: 0;
		padding-right: 0;
	}

	#root.calc-vue-root .calc-card {
		padding: 0.7rem;
		overflow: hidden;
	}

	#root.calc-vue-root .chart-summary-row {
		grid-template-columns: 1fr;
		gap: 0.45rem;
		margin-bottom: 0.55rem;
	}

	#root.calc-vue-root .chart-summary-row__card {
		padding: 0.55rem 0.65rem;
	}

	#root.calc-vue-root .chart-summary-row__label {
		font-size: 0.62rem;
		margin-bottom: 0.1rem;
	}

	#root.calc-vue-root .chart-summary-row__value {
		font-size: 1.25rem;
	}

	#root.calc-vue-root .calc-computing-bar {
		margin-bottom: 0.55rem;
		padding: 0.45rem 0.6rem;
	}

	#root.calc-vue-root .o-container {
		width: 100%;
		max-width: none;
	}

	/* Заголовки и выбор фракций: две понятные колонки без центрального пустого места */
	#root.calc-vue-root .o-container > .o-grid.center-grid:first-child,
	#root.calc-vue-root .race-select-row {
		display: grid !important;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
		gap: 0.5rem;
		align-items: stretch;
	}

	#root.calc-vue-root .o-container > .o-grid.center-grid:first-child .unit-name,
	#root.calc-vue-root .race-select-row .unit-name {
		display: none;
	}

	#root.calc-vue-root .o-container > .o-grid.center-grid:first-child .block {
		width: auto;
		flex-basis: auto;
		text-align: center;
	}

	#root.calc-vue-root select.race-select.c-field {
		width: 100%;
		min-height: 3rem;
		font-size: 16px;
	}

	/* Каждая строка юнита становится карточкой: название -> атакующий -> защитник */
	#root #counters {
		margin-top: 0.65rem;
	}

	#root #counters .unit-row {
		display: grid !important;
		grid-template-columns: 1fr;
		gap: 0.5rem;
		margin: 0 0 0.65rem;
		padding: 0.65rem;
		background: rgba(10, 14, 26, 0.38);
		border: 1px solid rgba(212, 175, 55, 0.16);
		border-radius: 12px;
	}

	#root #counters .unit-row .unit-name {
		order: 1;
		min-width: 0;
		width: 100%;
		flex-basis: auto;
		min-height: auto;
		padding: 0.35rem 0.5rem;
		border-radius: 8px;
		font-size: 1rem;
		text-align: center;
	}

	#root #counters .counter--attacker {
		order: 2;
	}

	#root #counters .counter--defender {
		order: 3;
	}

	#root #counters .counter.c-input-group {
		display: grid !important;
		grid-template-columns: var(--ti4-counter-row-h) minmax(2.5rem, 1fr) var(--ti4-counter-row-h) var(--ti4-counter-row-h) minmax(2.75rem, auto);
		gap: 0.35rem;
		width: 100%;
		min-height: auto;
		align-items: stretch;
		justify-content: stretch;
		flex: none;
		flex-basis: auto;
		max-width: 100%;
		overflow: hidden;
	}

	#root #counters .counter.c-input-group::before {
		grid-column: 1 / -1;
		display: block;
		font-family: ui-sans-serif, system-ui, sans-serif;
		font-size: 0.65rem;
		font-weight: 700;
		letter-spacing: 0.12em;
		text-transform: uppercase;
		color: var(--ti4-muted);
	}

	#root #counters .counter--attacker::before {
		content: "Атакующий";
	}

	#root #counters .counter--defender::before {
		content: "Защитник";
	}

	#root #counters .counter.c-input-group > .hidden {
		display: none !important;
	}

	#root #counters .c-button.count-stepper,
	#root #counters .c-button.upgrade,
	#root #counters select.damaged,
	#root #counters .o-field input.c-field {
		min-height: var(--ti4-counter-row-h);
		height: var(--ti4-counter-row-h);
	}

	#root #counters .c-button.count-stepper,
	#root #counters .c-button.upgrade {
		width: var(--ti4-counter-row-h);
		min-width: var(--ti4-counter-row-h);
		padding: 0.25rem;
	}

	#root #counters .o-field {
		min-width: 0;
		width: 100%;
	}

	#root #counters .o-field input.c-field {
		min-width: 0;
		max-width: none;
		font-size: 16px;
	}

	#root #counters select.damaged {
		min-width: 2.75rem;
		padding-left: 0.45rem;
		padding-right: 1.25rem;
		font-size: 16px;
	}

	/* На мобильном разделители должны быть видны у полей, «+» и улучшения */
	#root #counters .c-input-group.counter > .o-field + .count-stepper,
	#root #counters .c-input-group.counter > .o-field + .count-stepper + .upgrade {
		padding-left: 0.25rem;
		border-left: 1px solid var(--ti4-card-border);
	}

	/* Служебные кнопки крупные, в 2 колонки */
	#root.calc-vue-root .calc-toolbar.calc-toolbar--actions {
		margin-top: 0.7rem;
	}

	#root.calc-vue-root .calc-toolbar__actions-row {
		display: grid !important;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		grid-template-areas:
			"reset-attacker reset-defender"
			"space ground";
		width: 100%;
		gap: 0.5rem;
	}

	#root.calc-vue-root .calc-toolbar__action-btn--reset-attacker {
		grid-area: reset-attacker;
	}

	#root.calc-vue-root .calc-toolbar__action-btn--reset-defender {
		grid-area: reset-defender;
	}

	#root.calc-vue-root .calc-toolbar__action-btn--space {
		grid-area: space;
	}

	#root.calc-vue-root .calc-toolbar__action-btn--ground {
		grid-area: ground;
	}

	#root.calc-vue-root .calc-toolbar__actions-row > .c-button.calc-toolbar__action-btn {
		width: 100%;
		min-height: 3rem;
		height: 3rem;
		padding-left: 0.35rem;
		padding-right: 0.35rem;
		font-size: 0.92rem;
		border-left: 1px solid var(--ti4-card-border);
	}

	#root.calc-vue-root .calc-toolbar__action-btn--reset-attacker,
	#root.calc-vue-root .calc-toolbar__action-btn--reset-defender {
		flex-direction: column;
		gap: 0.1rem;
		line-height: 1.05;
	}

	#root.calc-vue-root .calc-toolbar__reset-main,
	#root.calc-vue-root .calc-toolbar__reset-side {
		display: block;
	}

	#root.calc-vue-root .calc-toolbar__reset-side {
		font-size: 0.72rem;
		letter-spacing: 0.08em;
		text-transform: uppercase;
		color: var(--ti4-text-muted);
	}

	#root.calc-vue-root .calc-toolbar__actions-row > .c-button.calc-toolbar__btn--battle-second {
		padding-left: 0.35rem;
	}

	/* Опции: компактная двухсторонняя таблица с кликабельной кнопкой справки */
	#root #options {
		padding: 0.75rem 0.6rem 0.85rem;
	}

	#root #options .options-side-labels {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.5rem;
		align-items: center;
		margin: 0 0 0.7rem;
		color: var(--ti4-gold);
		font-size: 0.68rem;
		font-weight: 700;
		letter-spacing: 0.14em;
		text-transform: uppercase;
	}

	#root #options .options-side-labels span:first-child {
		grid-column: 1;
		text-align: center;
	}

	#root #options .options-side-labels span:last-child {
		grid-column: 2;
		text-align: center;
	}

	#root #options .heading {
		margin-top: 0.8rem;
		font-size: 0.68rem;
	}

	#root #options .o-grid.center-grid {
		display: grid !important;
		grid-template-columns: minmax(0, 1fr) auto auto minmax(0, 1fr);
		gap: 0.25rem;
		align-items: center;
		margin: 0.35rem 0;
	}

	#root #options .left-option,
	#root #options .right-option {
		min-width: 0;
		padding: 0;
		font-size: 0.78rem;
		line-height: 1.25;
	}

	#root #options .left-option {
		grid-column: 1;
		justify-content: flex-end;
		text-align: right;
	}

	#root #options .right-option {
		grid-column: 4;
		text-align: left;
	}

	#root #options .left-option label,
	#root #options .right-option label {
		overflow-wrap: anywhere;
	}

	#root #options .help {
		width: 1.6rem;
		height: 1.6rem;
		min-width: 1.6rem;
		min-height: 1.6rem;
	}
}
