/* ==========================================================================
   Advanced Scientific Calculator v2
   Palette (teal + navy only):
     --asc-navy-900  deep navy    frame / headers
     --asc-navy-700  mid navy     panels / toolbar
     --asc-navy-500  soft navy    default key surface
     --asc-navy-300  pale navy    subtle borders / dividers
     --asc-teal-600  core teal    primary actions
     --asc-teal-400  bright teal  hover / highlight / accents
     --asc-teal-100  pale teal    display background
   ========================================================================== */

.asc-wrapper {
	--asc-navy-900: #091B2E;
	--asc-navy-700: #123054;
	--asc-navy-500: #1D4B76;
	--asc-navy-300: #2D6491;
	--asc-teal-600: #0E7C7B;
	--asc-teal-400: #2CC4BB;
	--asc-teal-100: #EAF7F5;

	--asc-radius-lg: 20px;
	--asc-radius-md: 12px;
	--asc-radius-sm: 8px;

	width: 100%;
	max-width: 720px;
	margin: 1.5rem auto;
	overflow-x: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	box-sizing: border-box;
}

.asc-wrapper *,
.asc-wrapper *::before,
.asc-wrapper *::after {
	box-sizing: border-box;
}

.asc-title {
	color: var(--asc-navy-900);
	font-weight: 600;
	font-size: 1.05rem;
	margin: 0 0 0.75rem;
	letter-spacing: 0.01em;
}

/* Layout: calculator + history card side by side when there's room, wrapping
   history below automatically when there isn't — via flex-wrap, not a media-query
   flex-direction switch. Every layout-critical property here is !important to
   guarantee it can't be silently overridden by theme CSS. */

.asc-layout {
	display: flex !important;
	flex-wrap: wrap !important;
	align-items: flex-start !important;
	gap: 16px !important;
	width: 100% !important;
}

.asc-calculator {
	position: relative;
	flex: 1 1 320px !important;
	min-width: 280px !important;
	max-width: 100%;
	background: var(--asc-navy-900);
	border-radius: var(--asc-radius-lg);
	padding: 0;
	overflow: hidden;
	box-shadow: 0 20px 45px -12px rgba(9, 27, 46, 0.45), 0 2px 8px rgba(9, 27, 46, 0.25);
}

/* ---------- History card ---------- */

.asc-history-card {
	flex: 1 1 240px !important;
	min-width: 240px !important;
	max-width: 100%;
	display: flex !important;
	flex-direction: column !important;
	background: var(--asc-navy-900);
	border-radius: var(--asc-radius-lg);
	overflow: hidden;
	box-shadow: 0 20px 45px -12px rgba(9, 27, 46, 0.45), 0 2px 8px rgba(9, 27, 46, 0.25);
}

.asc-history-header {
	flex: 0 0 auto;
	color: var(--asc-teal-100);
	opacity: 0.65;
	font-size: 0.72rem;
	font-weight: 800;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	padding: 14px 16px 8px;
}

button {
	font-family: inherit;
	-webkit-tap-highlight-color: transparent;
}

/* ---------- Display ---------- */

.asc-display {
	position: relative;
	background: var(--asc-teal-100);
	padding: 12px 14px 10px;
}

.asc-display-top {
	display: flex;
	align-items: center;
	gap: 8px;
}

.asc-mem-indicator {
	font-size: 0.68rem;
	font-weight: 800;
	color: var(--asc-teal-600);
	width: 18px;
	height: 18px;
	line-height: 18px;
	text-align: center;
	border-radius: 50%;
	border: 1.5px solid var(--asc-teal-600);
	opacity: 0;
	transform: scale(0.8);
	transition: opacity 0.15s ease, transform 0.15s ease;
}

.asc-mem-indicator[data-visible="true"] {
	opacity: 1;
	transform: scale(1);
}

.asc-mode-toggle {
	margin-left: auto;
	display: flex;
	background: rgba(9, 27, 46, 0.08);
	border-radius: 999px;
	padding: 2px;
}

.asc-mode-btn {
	border: none;
	background: transparent;
	color: var(--asc-navy-700);
	opacity: 0.55;
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.03em;
	padding: 5px 10px;
	border-radius: 999px;
	cursor: pointer;
}

.asc-mode-btn.is-active {
	background: var(--asc-teal-600);
	color: #fff;
	opacity: 1;
}

/* History list — lives inside the navy history card. */

.asc-history {
	display: block !important;
	box-sizing: border-box !important;
	flex: 1 1 auto !important;
	min-height: 90px !important;
	max-height: 220px !important;
	overflow-y: auto !important;
	overflow-x: hidden !important;
	overscroll-behavior: contain !important;
	-webkit-overflow-scrolling: touch;
	padding: 0 10px 12px;
	scrollbar-width: thin;
	scrollbar-color: rgba(234, 247, 245, 0.25) transparent;
}

.asc-history-list {
	display: block !important;
	height: auto !important;
}

.asc-history::-webkit-scrollbar {
	width: 5px;
}
.asc-history::-webkit-scrollbar-thumb {
	background: rgba(234, 247, 245, 0.2);
	border-radius: 3px;
}
.asc-history::-webkit-scrollbar-track {
	background: transparent;
}

.asc-history-empty {
	color: rgba(234, 247, 245, 0.4);
	font-size: 0.78rem;
	font-style: italic;
	padding: 4px 4px 8px;
}

.asc-history-list .asc-history-item {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 1px;
	padding: 8px 6px;
	border-radius: var(--asc-radius-sm);
	cursor: pointer;
}

.asc-history-list .asc-history-item:hover,
.asc-history-list .asc-history-item:focus-visible {
	background: rgba(44, 196, 187, 0.12);
}

.asc-history-list .asc-history-expr {
	color: rgba(234, 247, 245, 0.55);
	font-size: 0.78rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 100%;
}

.asc-history-list .asc-history-result {
	font-weight: 700;
	font-size: 0.92rem;
	color: var(--asc-teal-400);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 100%;
}

/* Input + live preview */

.asc-input-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin-top: 6px;
}

.asc-input {
	flex: 1 1 auto;
	width: 100%;
	resize: none;
	border: 0;
	outline: none;
	background: transparent;
	color: var(--asc-navy-900);
	font-size: clamp(1.35rem, 6vw, 1.75rem);
	font-family: "Cambria Math", Cambria, Georgia, serif;
	padding: 6px 2px 2px;
	line-height: 1.25;
	min-height: 1.4em;
}

.asc-input::placeholder {
	color: rgba(9, 27, 46, 0.25);
}

.asc-live-preview {
	flex: 0 0 auto;
	max-width: 55%;
	color: var(--asc-teal-600);
	font-size: clamp(0.95rem, 4vw, 1.15rem);
	font-weight: 700;
	text-align: right;
	padding-bottom: 6px;
	opacity: 0.85;
	overflow-wrap: anywhere;
}

.asc-error {
	min-height: 1.4em;
	color: #b3331d;
	font-size: 0.78rem;
	background: var(--asc-teal-100);
	padding: 0 14px 8px;
	margin-top: -4px;
}

/* ---------- Toolbar ---------- */

.asc-tabs {
	display: flex;
	align-items: center;
	gap: 6px;
	background: var(--asc-navy-700);
	padding: 8px 10px;
	border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.asc-tabs-more-hint {
	display: none;
	flex: 0 0 auto;
	color: var(--asc-teal-400);
	font-size: 0.8rem;
	padding: 0 2px;
}

.asc-tabs.has-more-tabs .asc-tabs-more-hint {
	display: inline-block;
}

.asc-tabs-scroll {
	display: flex;
	gap: 4px;
	overflow-x: auto;
	scrollbar-width: none;
	flex: 1 1 auto;
	min-width: 0;
}
.asc-tabs-scroll::-webkit-scrollbar {
	display: none;
}

.asc-tab {
	flex: 0 0 auto;
	background: transparent;
	border: none;
	color: rgba(234, 247, 245, 0.6);
	font-weight: 600;
	font-size: 0.82rem;
	padding: 7px 13px;
	border-radius: 999px;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.15s ease, color 0.15s ease;
}

.asc-tab:hover {
	color: var(--asc-teal-100);
}

.asc-tab.is-active {
	background: var(--asc-teal-600);
	color: #fff;
}

.asc-toolbar-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	flex: 0 0 auto;
}

.asc-icon-btn {
	background: transparent;
	border: 1px solid transparent;
	color: rgba(234, 247, 245, 0.7);
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	line-height: 1;
	width: auto;
	height: auto;
	min-width: auto;
	padding: 6px 9px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	white-space: nowrap;
	border-radius: 999px;
	cursor: pointer;
}

.asc-icon-btn:hover {
	background: rgba(44, 196, 187, 0.18);
	color: var(--asc-teal-100);
}

.asc-icon-btn:disabled {
	opacity: 0.3;
	cursor: default;
}
.asc-icon-btn:disabled:hover {
	background: transparent;
}

.asc-clear-all {
	background: transparent;
	border: 1px solid var(--asc-navy-300);
	color: rgba(234, 247, 245, 0.75);
	font-size: 0.72rem;
	font-weight: 600;
	padding: 6px 11px;
	border-radius: 999px;
	cursor: pointer;
	margin-left: 4px;
	white-space: nowrap;
}

.asc-clear-all:hover {
	border-color: var(--asc-teal-400);
	color: var(--asc-teal-400);
}

/* ---------- Memory row ---------- */

.asc-mem-row {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6px;
	background: var(--asc-navy-700);
	padding: 0 10px 8px;
}

.asc-mem-btn {
	background: rgba(9, 27, 46, 0.35);
	border: none;
	color: rgba(234, 247, 245, 0.75);
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.02em;
	padding: 6px 4px;
	border-radius: var(--asc-radius-sm);
	cursor: pointer;
}

.asc-mem-btn:hover {
	background: var(--asc-teal-600);
	color: #fff;
}

.asc-mem-btn:active {
	transform: scale(0.96);
}

/* ---------- Panels / keypad ---------- */

.asc-panels {
	background: var(--asc-navy-700);
	padding: 8px 8px 10px;
}

.asc-panel {
	display: none;
}

.asc-panel.is-active {
	display: block;
	animation: asc-fade-in 0.12s ease;
}

@keyframes asc-fade-in {
	from { opacity: 0; transform: translateY(2px); }
	to { opacity: 1; transform: translateY(0); }
}

.asc-grid {
	display: grid;
	gap: 6px;
}

.asc-grid-6 {
	grid-template-columns: repeat(6, 1fr);
}

.asc-grid-10 {
	grid-template-columns: repeat(10, 1fr);
}

.asc-key {
	background: var(--asc-navy-500);
	color: var(--asc-teal-100);
	border: none;
	border-radius: var(--asc-radius-sm);
	font-size: clamp(0.82rem, 3.6vw, 0.98rem);
	min-height: 44px;
	padding: 8px 2px;
	cursor: pointer;
	transition: background 0.12s ease, transform 0.05s ease;
	line-height: 1;
	touch-action: manipulation;
}

.asc-key sup {
	font-size: 0.65em;
}

.asc-key:hover {
	background: var(--asc-teal-600);
	color: #fff;
}

.asc-key:active {
	transform: scale(0.94);
	background: var(--asc-teal-600);
}

.asc-key-op {
	background: var(--asc-navy-900);
	color: var(--asc-teal-400);
}

.asc-key-op:hover {
	background: var(--asc-teal-600);
	color: #fff;
}

.asc-key-equals {
	background: linear-gradient(135deg, var(--asc-teal-600), #0A5F5E);
	color: #fff;
	font-weight: 700;
	font-size: clamp(1rem, 4vw, 1.2rem);
	min-height: 46px;
}

.asc-key-equals:hover {
	background: var(--asc-teal-400);
	color: var(--asc-navy-900);
}

.asc-key-pct {
	color: var(--asc-teal-400);
}

.asc-frac {
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	font-size: 0.8em;
	line-height: 1.05;
}
.asc-frac i:first-child {
	border-bottom: 1.5px solid currentColor;
	padding: 0 2px 1px;
	font-style: normal;
}
.asc-frac i:last-child {
	padding-top: 1px;
	font-style: normal;
}

.asc-key-letter {
	font-size: clamp(0.75rem, 3.2vw, 0.88rem);
	padding: 8px 2px;
	min-height: 40px;
}

.asc-grid-qwerty .asc-row-offset {
	grid-column-start: 1;
}

/* ---------- Responsive ---------- */

@media (max-width: 616px) {
	.asc-history-card {
		max-height: 150px;
	}
	.asc-history {
		max-height: 110px !important;
	}
	.asc-history-header {
		padding: 10px 14px 4px;
	}
}

@media (max-width: 480px) {
	.asc-wrapper {
		max-width: 100%;
		margin: 0.75rem auto;
	}
	.asc-calculator,
	.asc-history-card {
		border-radius: var(--asc-radius-md);
	}
	.asc-layout {
		gap: 10px !important;
	}
	.asc-history-card {
		max-height: 120px;
	}
	.asc-history {
		max-height: 90px !important;
	}
	.asc-grid-6,
	.asc-grid-10 {
		gap: 5px;
	}
	.asc-mem-row {
		padding: 0 8px 8px;
	}
}

@media (max-width: 360px) {
	.asc-key {
		min-height: 40px;
	}
	.asc-mem-btn {
		font-size: 0.68rem;
		padding: 5px 2px;
	}
	.asc-tab {
		padding: 6px 10px;
		font-size: 0.78rem;
	}
	.asc-icon-btn {
		font-size: 0.66rem;
		padding: 5px 6px;
	}
	.asc-clear-all {
		padding: 5px 8px;
		font-size: 0.68rem;
	}
}

@media (max-height: 700px) {
	.asc-display {
		padding: 8px 12px 6px;
	}
	.asc-tabs {
		padding: 6px 10px;
	}
	.asc-mem-row {
		padding: 0 8px 6px;
		gap: 4px;
	}
	.asc-panels {
		padding: 6px 6px 8px;
	}
	.asc-key {
		min-height: 38px;
		padding: 6px 2px;
	}
	.asc-key-equals {
		min-height: 40px;
	}
	.asc-grid {
		gap: 4px;
	}
}

@media (max-height: 480px) and (orientation: landscape) {
	.asc-history-card {
		max-height: 90px;
	}
	.asc-history {
		max-height: 68px !important;
	}
	.asc-history-header {
		padding: 6px 12px 2px;
	}
	.asc-display {
		padding: 8px 12px 6px;
	}
	.asc-key {
		min-height: 34px;
		padding: 4px 2px;
	}
	.asc-mem-row {
		padding: 0 8px 6px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.asc-key,
	.asc-panel.is-active {
		transition: none;
		animation: none;
	}
}

.asc-wrapper button:focus-visible,
.asc-wrapper textarea:focus-visible {
	outline: 2px solid var(--asc-teal-400);
	outline-offset: 2px;
}