/* =========================================================================
   Practice Typing Test — widget styles
   Design language: "field-notes typewriter" — deep pine ink / aged paper
   with a brass accent, monospace passage type, and a brass speed-dial
   as the results signature element.
   ========================================================================= */

.ptt-widget {
	--ptt-font-mono: 'IBM Plex Mono', 'JetBrains Mono', SFMono-Regular, Menlo, Consolas, 'Courier New', monospace;
	--ptt-font-ui: 'Space Grotesk', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

	--ptt-accent: #b5793a;
	--ptt-accent-strong: #8f5e28;
	--ptt-success: #3f7a55;
	--ptt-error: #b13d34;
	--ptt-error-bg: rgba(177, 61, 52, 0.14);

	--ptt-radius: 10px;
	--ptt-radius-sm: 6px;

	box-sizing: border-box;
	max-width: 880px;
	margin: 2rem auto;
	font-family: var(--ptt-font-ui);
	border-radius: var(--ptt-radius);
	overflow: hidden;
	border: 1px solid var(--ptt-border);
	background: var(--ptt-bg);
	color: var(--ptt-text);
	box-shadow: 0 1px 2px rgba(20, 20, 15, 0.06), 0 12px 32px -18px rgba(20, 20, 15, 0.35);
}
.ptt-widget *, .ptt-widget *::before, .ptt-widget *::after { box-sizing: border-box; }

/* ---- Theme tokens ---- */
.ptt-widget[data-theme="light"] {
	--ptt-bg: #ece7da;
	--ptt-panel: #f7f4ec;
	--ptt-text: #1f2a24;
	--ptt-text-dim: #6b6152;
	--ptt-border: #d8d0bd;
	--ptt-pending: #9a9080;
	--ptt-caret-bg: rgba(181, 121, 58, 0.16);
}
.ptt-widget[data-theme="dark"] {
	--ptt-bg: #16241f;
	--ptt-panel: #1c2d27;
	--ptt-text: #ece5d3;
	--ptt-text-dim: #93a89a;
	--ptt-border: #2c4038;
	--ptt-pending: #5d7469;
	--ptt-caret-bg: rgba(198, 138, 59, 0.22);
}

/* ---- Header / toolbar ---- */
.ptt-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 14px 18px;
	background: var(--ptt-panel);
	border-bottom: 1px solid var(--ptt-border);
}
.ptt-brand {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 700;
	letter-spacing: 0.02em;
	font-size: 15px;
}
.ptt-brand .ptt-key {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	border-radius: 4px;
	background: var(--ptt-accent);
	color: #fff;
	font-family: var(--ptt-font-mono);
	font-size: 12px;
	font-weight: 700;
}
.ptt-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	border: 1px solid var(--ptt-border);
	background: transparent;
	color: var(--ptt-text-dim);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
	font-size: 15px;
	line-height: 1;
}
.ptt-icon-btn:hover { color: var(--ptt-text); background: var(--ptt-bg); }
.ptt-icon-btn:active { transform: scale(0.92); }
.ptt-icon-btn[aria-pressed="true"] { color: #fff; background: var(--ptt-accent); border-color: var(--ptt-accent); }
.ptt-header-actions { display: flex; gap: 8px; }

/* ---- Controls row (mode/content/difficulty/duration tabs) ---- */
.ptt-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 18px;
	padding: 12px 18px;
	background: var(--ptt-bg);
	border-bottom: 1px solid var(--ptt-border);
	font-size: 13px;
}
.ptt-control-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ptt-control-label {
	color: var(--ptt-text-dim);
	text-transform: uppercase;
	font-size: 10.5px;
	letter-spacing: 0.08em;
	margin-right: 2px;
}
.ptt-pill {
	appearance: none;
	border: 1px solid var(--ptt-border);
	background: var(--ptt-panel);
	color: var(--ptt-text-dim);
	padding: 5px 11px;
	border-radius: 999px;
	font-family: var(--ptt-font-ui);
	font-size: 12.5px;
	cursor: pointer;
	transition: all 0.15s ease;
}
.ptt-pill:hover { color: var(--ptt-text); border-color: var(--ptt-accent); }
.ptt-pill.is-active {
	background: var(--ptt-accent);
	border-color: var(--ptt-accent);
	color: #fff;
	font-weight: 600;
}
.ptt-select {
	appearance: none;
	border: 1px solid var(--ptt-border);
	background: var(--ptt-panel);
	color: var(--ptt-text);
	padding: 5px 26px 5px 10px;
	border-radius: var(--ptt-radius-sm);
	font-family: var(--ptt-font-ui);
	font-size: 12.5px;
	cursor: pointer;
	background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
	background-position: calc(100% - 13px) center, calc(100% - 8px) center;
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
}
.ptt-controls[hidden], .ptt-control-group[hidden] { display: none; }

/* ---- Stats bar ---- */
.ptt-stats {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	border-bottom: 1px solid var(--ptt-border);
}
.ptt-stat {
	padding: 12px 10px;
	text-align: center;
	border-right: 1px solid var(--ptt-border);
}
.ptt-stat:last-child { border-right: none; }
.ptt-stat-value {
	font-family: var(--ptt-font-mono);
	font-size: 22px;
	font-weight: 700;
	color: var(--ptt-accent);
	line-height: 1.2;
	font-variant-numeric: tabular-nums;
}
.ptt-stat-label {
	font-size: 10.5px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--ptt-text-dim);
	margin-top: 2px;
}

/* ---- Progress "carriage" bar ---- */
.ptt-progress-track {
	height: 4px;
	background: var(--ptt-border);
	position: relative;
	overflow: hidden;
}
.ptt-progress-fill {
	position: absolute;
	inset: 0 auto 0 0;
	width: 0%;
	background: var(--ptt-accent);
	transition: width 0.12s linear;
}

/* ---- Typing area ---- */
.ptt-stage { padding: 22px 26px; position: relative; }

.ptt-textbox {
	font-family: var(--ptt-font-mono);
	font-size: 19px;
	line-height: 1.9;
	letter-spacing: 0.01em;
	color: var(--ptt-pending);
	user-select: none;
	white-space: pre-wrap;
	word-wrap: break-word;
	position: relative;
	max-height: 8.6em;
	overflow-y: auto;
	padding: 4px 2px;
	filter: blur(0px);
	transition: filter 0.2s ease;
}
.ptt-widget.is-blurred .ptt-textbox { filter: blur(4px); }
.ptt-widget.is-blurred .ptt-blur-overlay { display: flex; }

.ptt-blur-overlay {
	display: none;
	position: absolute;
	inset: 0;
	align-items: center;
	justify-content: center;
	background: transparent;
	cursor: text;
	font-size: 14px;
	color: var(--ptt-text-dim);
	z-index: 2;
}
.ptt-blur-overlay span {
	background: var(--ptt-panel);
	border: 1px solid var(--ptt-border);
	padding: 8px 16px;
	border-radius: 999px;
}

.ptt-char { position: relative; }
.ptt-char.is-correct { color: var(--ptt-text); }
.ptt-char.is-incorrect { color: var(--ptt-error); background: var(--ptt-error-bg); border-radius: 2px; text-decoration: underline wavy var(--ptt-error); text-decoration-thickness: 1px; }
.ptt-char.is-current { background: var(--ptt-caret-bg); border-radius: 2px; }
.ptt-char.is-current::before {
	content: "";
	position: absolute;
	left: 0;
	top: 1px;
	bottom: 1px;
	width: 2px;
	background: var(--ptt-accent);
	animation: ptt-blink 1s step-start infinite;
}
@keyframes ptt-blink { 50% { opacity: 0; } }

.ptt-hidden-input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
	width: 1px;
	height: 1px;
}

/* Custom text entry */
.ptt-custom-entry { display: none; }
.ptt-widget[data-content="custom"] .ptt-custom-entry.is-visible { display: block; margin-bottom: 16px; }
.ptt-custom-textarea {
	width: 100%;
	min-height: 110px;
	font-family: var(--ptt-font-mono);
	font-size: 14px;
	padding: 10px 12px;
	border-radius: var(--ptt-radius-sm);
	border: 1px solid var(--ptt-border);
	background: var(--ptt-panel);
	color: var(--ptt-text);
	resize: vertical;
}
.ptt-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	border: 1px solid var(--ptt-accent);
	background: var(--ptt-accent);
	color: #fff;
	padding: 8px 16px;
	border-radius: var(--ptt-radius-sm);
	font-family: var(--ptt-font-ui);
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.1s ease;
}
.ptt-btn:hover { background: var(--ptt-accent-strong); border-color: var(--ptt-accent-strong); }
.ptt-btn:active { transform: scale(0.97); }
.ptt-btn.ptt-btn-ghost {
	background: transparent;
	color: var(--ptt-text);
	border-color: var(--ptt-border);
}
.ptt-btn.ptt-btn-ghost:hover { border-color: var(--ptt-accent); color: var(--ptt-accent); }

/* ---- Footer action row ---- */
.ptt-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 10px;
	padding: 14px 26px 22px;
}
.ptt-hint { font-size: 12px; color: var(--ptt-text-dim); }
.ptt-hint kbd {
	font-family: var(--ptt-font-mono);
	background: var(--ptt-panel);
	border: 1px solid var(--ptt-border);
	border-bottom-width: 2px;
	padding: 1px 6px;
	border-radius: 4px;
	font-size: 11px;
}

/* ---- Results panel ---- */
.ptt-results { display: none; padding: 26px; border-top: 1px solid var(--ptt-border); background: var(--ptt-panel); }
.ptt-results.is-visible { display: block; }
.ptt-results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.ptt-results-title { font-family: var(--ptt-font-ui); font-size: 18px; font-weight: 700; }
.ptt-best-badge {
	font-size: 12px;
	font-weight: 700;
	color: var(--ptt-success);
	background: rgba(63, 122, 85, 0.14);
	padding: 4px 10px;
	border-radius: 999px;
	display: none;
}
.ptt-best-badge.is-visible { display: inline-block; }

.ptt-results-grid { display: grid; grid-template-columns: 190px 1fr; gap: 22px; align-items: center; }

/* Brass speed dial (signature element) */
.ptt-dial-wrap { display: flex; flex-direction: column; align-items: center; }
.ptt-dial-num { font-family: var(--ptt-font-mono); font-size: 34px; font-weight: 700; color: var(--ptt-accent); margin-top: -46px; }
.ptt-dial-label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ptt-text-dim); margin-top: 2px; }

.ptt-metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ptt-metric {
	background: var(--ptt-bg);
	border: 1px solid var(--ptt-border);
	border-radius: var(--ptt-radius-sm);
	padding: 10px 12px;
}
.ptt-metric-value { font-family: var(--ptt-font-mono); font-size: 18px; font-weight: 700; }
.ptt-metric-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ptt-text-dim); margin-top: 2px; }

.ptt-graph-wrap { margin-top: 18px; }
.ptt-graph-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ptt-text-dim); margin-bottom: 6px; }
.ptt-graph { width: 100%; height: 90px; display: block; }

.ptt-results-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ---- History ---- */
.ptt-history { margin-top: 22px; }
.ptt-history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ptt-history-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ptt-text-dim); }
.ptt-history-clear { background: none; border: none; color: var(--ptt-text-dim); font-size: 12px; cursor: pointer; text-decoration: underline; }
.ptt-history-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ptt-history-table th, .ptt-history-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--ptt-border); font-family: var(--ptt-font-mono); }
.ptt-history-table th { color: var(--ptt-text-dim); font-family: var(--ptt-font-ui); font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.06em; }
.ptt-history-empty { font-size: 12.5px; color: var(--ptt-text-dim); padding: 10px 0; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
	.ptt-stats { grid-template-columns: repeat(2, 1fr); }
	.ptt-stat:nth-child(2) { border-right: none; }
	.ptt-results-grid { grid-template-columns: 1fr; }
	.ptt-dial-wrap { margin: 0 auto; }
	.ptt-metric-grid { grid-template-columns: repeat(3, 1fr); }
	.ptt-textbox { font-size: 16px; }
	.ptt-stage { padding: 16px; }
}

/* ---- Accessibility ---- */
.ptt-widget a:focus-visible,
.ptt-widget button:focus-visible,
.ptt-widget select:focus-visible,
.ptt-widget textarea:focus-visible {
	outline: 2px solid var(--ptt-accent);
	outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
	.ptt-widget * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
