:root {
	--brand-blue: #0065b3;
	--brand-orange: #ff9e1b;
	--bg-gradient: linear-gradient(135deg, #005699 0%, #0072c6 100%);
	--glass-bg: rgba(255, 255, 255, 0.12);
	--glass-border: rgba(255, 255, 255, 0.25);
	--glass-hover: rgba(255, 255, 255, 0.2);
	--text-white: #ffffff;
	--text-white-dim: rgba(255, 255, 255, 0.7);
	--text-dark: #0f172a;
	--text-muted: #64748b;
	--radius-lg: 20px;
	--radius-sm: 12px;
	--header-height: 60px;
	--font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; }
input { user-select: text; }

body {
	font-family: var(--font-family);
	background: var(--bg-gradient);
	color: var(--text-white);
	height: 100dvh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.app-wrapper {
	flex: 1;
	display: flex;
	flex-direction: column;
	padding: 10px 20px 20px 20px;
	max-width: 600px;
	margin: 0 auto;
	width: 100%;
	justify-content: flex-start;
	gap: 15px;
	padding-bottom: max(20px, env(safe-area-inset-bottom));
	position: relative;
	z-index: 1;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: var(--header-height);
	margin-bottom: 0;
	flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.logo-img {
	height: 38px;
	width: auto;
	object-fit: contain;
	filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.back-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	background: rgba(255, 255, 255, 0.15);
	border: 1px solid rgba(255, 255, 255, 0.3);
	border-radius: 12px;
	color: white;
	text-decoration: none;
	transition: all 0.2s ease;
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}
.back-btn:active { background: rgba(255, 255, 255, 0.3); transform: scale(0.95); }
.back-btn svg { width: 20px; height: 20px; stroke-width: 2.5; }

.header-controls { display: flex; gap: 8px; align-items: center; }

.lang-select {
	appearance: none;
	background: rgba(0, 0, 0, 0.2);
	border: 1px solid rgba(255,255,255,0.15);
	color: white;
	padding: 6px 10px;
	border-radius: 12px;
	font-size: 1.1rem;
	font-family: var(--font-family);
	cursor: pointer;
	text-align: center;
	height: 36px;
	width: calc(1.5rem + 10px + 10px);
}
.lang-select option { background: #005699; color: white; font-size: 0.9rem; }

.unit-toggle {
	background: rgba(0, 0, 0, 0.2);
	border-radius: 12px;
	padding: 3px;
	display: flex;
	cursor: pointer;
	height: 36px;
	align-items: center;
	border: 1px solid rgba(255,255,255,0.1);
}

.unit-option {
	padding: 0 10px;
	height: 28px;
	line-height: 28px;
	border-radius: 9px;
	font-size: 0.7rem;
	font-weight: 700;
	color: var(--text-white-dim);
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.unit-option.active {
	background-color: var(--text-white);
	color: var(--brand-blue);
	box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.tool-title {
	font-size: 1.4rem;
	font-weight: 800;
	color: var(--text-white);
	text-align: center;
	margin: 5px 0;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	text-shadow: 0 2px 4px rgba(0,0,0,0.15);
	flex-shrink: 0;
}

.input-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
	margin-bottom: 0;
}

.input-card {
	background: var(--glass-bg);
	border: 1px solid var(--glass-border);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border-radius: var(--radius-lg);
	padding: 12px 16px;
	display: flex;
	flex-direction: column;
	transition: all 0.2s;
}
.input-card:focus-within {
	background: rgba(255, 255, 255, 0.25);
	border-color: rgba(255, 255, 255, 0.5);
	transform: translateY(-1px);
}

.input-card label {
	font-size: 0.65rem; text-transform: uppercase; letter-spacing: 1px;
	color: var(--text-white-dim); font-weight: 700; margin-bottom: 2px;
}

.input-row { display: flex; align-items: baseline; }

.input-row input {
	width: 100%; background: transparent; border: none;
	color: var(--text-white); font-size: 1.7rem; font-weight: 700;
	padding: 0; outline: none; font-family: var(--font-family);
	-moz-appearance: textfield; text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.input-row input::-webkit-outer-spin-button,
.input-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-row input::placeholder { color: rgba(255, 255, 255, 0.2); }

.unit-label { font-size: 0.85rem; color: var(--text-white-dim); margin-left: 4px; font-weight: 500; }
.full-width { grid-column: span 2; }

.type-selector {
	display: flex; background: rgba(0, 0, 0, 0.15);
	border-radius: 14px; padding: 4px; margin-top: 4px;
}
.type-btn {
	flex: 1; background: transparent; border: none;
	color: var(--text-white-dim); padding: 10px 4px;
	font-size: 0.85rem; font-weight: 600; border-radius: 10px;
	cursor: pointer; transition: all 0.2s;
}
.type-btn.active {
	background: var(--brand-orange); color: white;
	box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.type-description {
	text-align: center; font-size: 0.75rem;
	color: var(--text-white-dim); margin-top: 8px;
	min-height: 1.2em; font-weight: 500;
}

.result-area {
	margin-top: 10px; text-align: center; position: relative; flex-shrink: 0;
}
.result-label {
	font-size: 0.85rem; color: var(--text-white-dim);
	letter-spacing: 1.5px; text-transform: uppercase;
	margin-bottom: 0px; font-weight: 700;
}
.din-display {
	font-size: 4.5rem;
	font-weight: 800; line-height: 1;
	color: var(--text-white); text-shadow: 0 4px 20px rgba(0,0,0,0.2);
	font-variant-numeric: tabular-nums; margin: 5px 0;
}
.details-trigger {
	font-size: 0.85rem; color: var(--text-white);
	background: rgba(255,255,255,0.15); padding: 8px 18px;
	border-radius: 20px; cursor: pointer; margin-top: 5px;
	display: inline-block; backdrop-filter: blur(4px);
	font-weight: 600; border: 1px solid rgba(255,255,255,0.1);
	transition: background 0.2s;
}
.details-trigger:active { background: rgba(255,255,255,0.25); }

.error-toast {
	position: absolute; bottom: 80px; left: 50%;
	transform: translateX(-50%); background: #ef4444; color: white;
	font-size: 0.85rem; padding: 8px 16px; border-radius: 12px;
	white-space: nowrap; opacity: 0; transition: opacity 0.3s;
	box-shadow: 0 4px 15px rgba(0,0,0,0.3); pointer-events: none;
	z-index: 10; font-weight: 600;
}
.error-toast.visible { opacity: 1; }

.modal-overlay {
	position: fixed; top: 0; left: 0; right: 0; bottom: 0;
	background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px); z-index: 100;
	display: flex; align-items: center; justify-content: center;
	opacity: 0; pointer-events: none; transition: opacity 0.2s ease-in-out;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-card {
	background: #f8fafc; color: var(--text-dark);
	width: 90%; max-width: 400px; border-radius: 24px;
	padding: 24px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
	transform: scale(0.92); transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.open .modal-card { transform: scale(1); }

.modal-header {
	font-size: 1.1rem; font-weight: 800; margin-bottom: 20px;
	color: var(--brand-blue); text-align: center;
	text-transform: uppercase; letter-spacing: 0.5px;
}

.calc-row {
	display: flex; justify-content: space-between;
	align-items: flex-start; padding: 14px 0; border-bottom: 1px solid #e2e8f0;
}
.calc-desc {
	font-size: 0.95rem; color: var(--text-dark); font-weight: 700;
	display:flex; flex-direction:column; max-width: 65%;
}
.calc-desc small {
	font-size: 0.75rem; color: var(--text-muted); font-weight: 400;
	margin-top: 4px; line-height: 1.35;
}
.calc-val {
	font-size: 1rem; font-weight: 800; color: var(--text-dark);
	text-align: right; white-space: nowrap; background: #e2e8f0;
	padding: 4px 10px; border-radius: 8px; min-width: 70px;
	display: flex; justify-content: center;
}
.val-tight { background: #fff7ed; color: #c2410c; }
.val-loose { background: #f0fdf4; color: #15803d; }
.val-base { background: #dbeafe; color: #1e40af; font-size: 1.1rem; }

.final-box {
	background: #eff6ff; border-radius: 12px; padding: 16px;
	margin-top: 20px; text-align: center; border: 1px solid #bfdbfe;
	display: flex; justify-content: space-between; align-items: center;
}
.final-label { font-size: 1rem; font-weight: 800; color: #1e40af; }
.final-number { font-size: 2.2rem; font-weight: 900; color: var(--brand-blue); line-height: 1; }
.iso-ref { text-align: center; margin-top: 15px; font-size: 0.7rem; color: #94a3b8; font-weight: 500; }

.close-btn {
	margin-top: 15px; width: 100%; padding: 14px;
	background: var(--brand-blue); color: white;
	border: none; border-radius: 14px; font-weight: 700; font-size: 1rem;
	cursor: pointer; transition: background 0.2s;
}
.close-btn:active { background: #00509e; }

@media (min-width: 600px) {
	.input-grid .full-width { grid-column: span 2; }
	.app-wrapper { max-width: 750px; }
}

@media (max-height: 680px) {
	.app-wrapper { padding: 10px 15px; }
	.logo-img { height: 32px; }
	.din-display { font-size: 4.5rem; margin: 0; }
	.input-card { padding: 8px 12px; }
	.result-area { margin-top: 5px; }
}