/**
 * Scrabble LOC — Styles
 * Version: 1.1.1
 * Mobile-first, CSS custom properties.
 */

/* ─── Palette partagée (onglets + app) ───────────────────────────────── */
.scrabble-tabs,
#scrabble-advanced-app {
	--scr-tws:   #e63946;
	--scr-dws:   #f4a261;
	--scr-tls:   #1d3557;
	--scr-dls:   #457b9d;
	--scr-ctr:   #e63946;
	--scr-empty: #ede8d8;

	--scr-tile-bg:    #f5e6c8;
	--scr-tile-text:  #2b2d42;

	--scr-new-play:      #06d6a0;
	--scr-existing-play: #ffd166;

	--scr-primary:        #1d3557;
	--scr-primary-hover:  #457b9d;
	--scr-secondary:      #718096;
	--scr-radius:         6px;
}

/* ─── Onglets de navigation ─────────────────────────────────────────── */
.scrabble-tabs {
	display: flex;
	border-bottom: 2px solid var(--scr-primary);
	margin-bottom: 18px;
}
.scrabble-tab {
	padding: 8px 18px;
	text-decoration: none;
	color: var(--scr-primary);
	border: 2px solid transparent;
	border-bottom: none;
	border-radius: 4px 4px 0 0;
	background: var(--scr-empty);
	font-weight: 500;
	margin-right: 4px;
	transition: background 0.15s, color 0.15s;
}
.scrabble-tab:hover {
	background: var(--scr-tile-bg);
	color: var(--scr-primary);
	text-decoration: none;
}
.scrabble-tab-active {
	background: #fff;
	color: var(--scr-primary);
	border-color: var(--scr-primary);
	border-bottom-color: #fff;
	margin-bottom: -2px;
	font-weight: 700;
}

/* ─── Panneau historique (chercheur de mots) ─────────────────────────── */
#historique-liste .list-group-item {
	padding: 6px 12px;
	font-size: 0.9em;
}
#historique-liste .list-group-item:hover {
	background-color: var(--scr-empty);
}
#historique-liste .hist-label {
	font-weight: bold;
}
#historique-liste .hist-details {
	color: #666;
	font-size: 0.85em;
}

/* ─── Layout custom properties ──────────────────────────────────────── */
#scrabble-advanced-app {
	--scr-cell-size:   clamp(20px, calc(94vw / 15), 36px);
	--scr-font-cell:   clamp(9px,  calc(94vw / 15 * 0.55), 18px);
	--scr-gap:         1px;

	box-sizing: border-box;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	color: #2b2d42;
	max-width: 600px;
	margin: 0 auto;
	padding: 8px;
}

#scrabble-advanced-app *,
#scrabble-advanced-app *::before,
#scrabble-advanced-app *::after {
	box-sizing: inherit;
}

/* ─── Header / Beta badge ────────────────────────────────────────────── */
.scr-header {
	display: flex;
	justify-content: flex-end;
	margin-bottom: 4px;
}

.scr-beta {
	display: inline-block;
	padding: 2px 7px;
	border-radius: 999px;
	background: var(--scr-dws);
	color: #7b341e;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	line-height: 1.6;
}

/* ─── Toolbar ────────────────────────────────────────────────────────── */
.scr-toolbar {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 6px;
	flex-wrap: wrap;
	margin-bottom: 6px;
}

.scr-direction {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 8px;
	border: 1px solid #cbd5e0;
	border-radius: var(--scr-radius);
	background: #f8f9fa;
	font-size: 12px;
	color: #4a5568;
	margin-right: auto;
	user-select: none;
}

.scr-direction__arrow {
	font-weight: 700;
	font-size: 14px;
	color: var(--scr-primary);
	min-width: 12px;
	text-align: center;
}

/* ─── Grid wrapper (horizontal scroll on very small screens) ─────────── */
.scr-grid-wrapper {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	margin-bottom: 12px;
}

/* ─── Grid ───────────────────────────────────────────────────────────── */
.scr-grid {
	display: grid;
	grid-template-columns: repeat(15, var(--scr-cell-size));
	gap: var(--scr-gap);
	width: fit-content;
}

/* ─── Cell base ──────────────────────────────────────────────────────── */
.scr-cell {
	width:  var(--scr-cell-size);
	height: var(--scr-cell-size);
	padding: 0;
	border: none;
	border-radius: 2px;
	background: var(--scr-empty);
	color: var(--scr-tile-text);
	font-size: var(--scr-font-cell);
	font-weight: 700;
	text-align: center;
	text-transform: uppercase;
	cursor: pointer;
	outline: none;
	line-height: var(--scr-cell-size);
	transition: background 0.15s, box-shadow 0.15s;
	-webkit-tap-highlight-color: transparent;
}

.scr-cell:focus {
	box-shadow: 0 0 0 2px var(--scr-primary);
	z-index: 1;
	position: relative;
}

/* Direction indicator: highlight the edge in the typing direction. */
.scr-dir-h .scr-cell:focus {
	box-shadow:
		inset -3px 0 0 var(--scr-tws),
		0 0 0 2px var(--scr-primary);
}
.scr-dir-v .scr-cell:focus {
	box-shadow:
		inset 0 -3px 0 var(--scr-tws),
		0 0 0 2px var(--scr-primary);
}

/* Cell with a letter typed by the user */
.scr-cell--filled {
	background: var(--scr-tile-bg);
}

/* ─── Special squares ────────────────────────────────────────────────── */
.scr-cell--tws {
	background: var(--scr-tws);
	color: #fff;
}
.scr-cell--dws {
	background: var(--scr-dws);
	color: #fff;
}
.scr-cell--tls {
	background: var(--scr-tls);
	color: #fff;
}
.scr-cell--dls {
	background: var(--scr-dls);
	color: #fff;
}
.scr-cell--ctr {
	background: var(--scr-ctr);
	color: #fff;
}

/* When a special square has a letter, show tile colour */
.scr-cell--tws.scr-cell--filled,
.scr-cell--dws.scr-cell--filled,
.scr-cell--tls.scr-cell--filled,
.scr-cell--dls.scr-cell--filled,
.scr-cell--ctr.scr-cell--filled {
	background: var(--scr-tile-bg);
	color: var(--scr-tile-text);
}

/* ─── Best-move highlight ────────────────────────────────────────────── */
.scr-cell--new-play {
	background: var(--scr-new-play) !important;
	color: #1a1a2e !important;
	animation: scr-pop 0.25s ease;
}

.scr-cell--existing-play {
	background: var(--scr-existing-play) !important;
	color: #1a1a2e !important;
}

@keyframes scr-pop {
	0%   { transform: scale(0.8); }
	60%  { transform: scale(1.1); }
	100% { transform: scale(1); }
}

/* ─── Rack section ───────────────────────────────────────────────────── */
.scr-rack-section {
	margin-bottom: 12px;
}

.scr-label {
	display: block;
	font-size: 13px;
	font-weight: 600;
	margin-bottom: 6px;
	color: #4a5568;
}

.scr-rack-row {
	display: flex;
	gap: 8px;
	align-items: stretch;
}

.scr-rack-input {
	flex: 1;
	min-width: 0;
	padding: 10px 12px;
	border: 2px solid #cbd5e0;
	border-radius: var(--scr-radius);
	font-size: 20px;
	font-weight: 700;
	letter-spacing: 4px;
	text-transform: uppercase;
	color: var(--scr-tile-text);
	background: #fff;
	outline: none;
	transition: border-color 0.15s;
}

.scr-rack-input:focus {
	border-color: var(--scr-primary);
}

/* ─── Buttons ────────────────────────────────────────────────────────── */
.scr-btn {
	padding: 10px 16px;
	border: none;
	border-radius: var(--scr-radius);
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.15s, opacity 0.15s;
}

.scr-btn:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.scr-btn--primary {
	background: var(--scr-primary);
	color: #fff;
}

.scr-btn--primary:hover:not(:disabled) {
	background: var(--scr-primary-hover);
}

.scr-btn--secondary {
	background: #edf2f7;
	color: #4a5568;
}

.scr-btn--secondary:hover:not(:disabled) {
	background: #e2e8f0;
}

.scr-btn--icon {
	padding: 6px 10px;
	font-size: 16px;
	line-height: 1;
	background: #edf2f7;
	color: #4a5568;
}

.scr-btn--icon:hover:not(:disabled) {
	background: #e2e8f0;
}

/* ─── Result card ────────────────────────────────────────────────────── */
.scr-result {
	background: #fff;
	border: 2px solid var(--scr-primary);
	border-radius: var(--scr-radius);
	padding: 16px;
	text-align: center;
	margin-bottom: 12px;
}

.scr-result__word {
	font-size: clamp(28px, 8vw, 48px);
	font-weight: 800;
	letter-spacing: 4px;
	color: var(--scr-primary);
	text-transform: uppercase;
	line-height: 1.1;
}

.scr-result__score {
	font-size: clamp(20px, 6vw, 32px);
	font-weight: 700;
	color: var(--scr-tws);
	margin: 4px 0 8px;
}

.scr-result__meta {
	font-size: 13px;
	color: #718096;
}

/* ─── Message (errors / no move) ─────────────────────────────────────── */
.scr-message {
	padding: 12px 16px;
	border-radius: var(--scr-radius);
	font-size: 14px;
	font-weight: 600;
	background: #fff5f5;
	color: #c53030;
	border: 1px solid #feb2b2;
	margin-bottom: 12px;
}

.scr-message--info {
	background: #ebf8ff;
	color: var(--scr-primary);
	border-color: #bee3f8;
}

/* ─── Joker tile ─────────────────────────────────────────────────────── */

/* On the grid: joker letter kept lowercase, italic */
.scr-cell--joker {
	text-transform: none;
	font-style: italic;
}

/* In the result word */
.scr-result__joker {
	font-style: italic;
	text-decoration: underline;
	text-decoration-thickness: 3px;
	color: var(--scr-dls);
}

/* ─── Legend (small squares legend below grid) ───────────────────────── */
.scr-legend {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 12px;
	margin-bottom: 12px;
	font-size: 11px;
	color: #4a5568;
}

.scr-legend__item {
	display: flex;
	align-items: center;
	gap: 4px;
}

.scr-legend__swatch {
	width: 14px;
	height: 14px;
	border-radius: 2px;
	flex-shrink: 0;
}

.scr-legend__swatch--tws { background: var(--scr-tws); }
.scr-legend__swatch--dws { background: var(--scr-dws); }
.scr-legend__swatch--tls { background: var(--scr-tls); }
.scr-legend__swatch--dls { background: var(--scr-dls); }

/* ─── Alternatives panel ─────────────────────────────────────────────── */
#scr-alternatives {
	margin-bottom: 12px;
}

.scr-alt-title {
	font-size: 12px;
	font-weight: 600;
	color: #718096;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	margin-bottom: 6px;
}

.scr-alt-list {
	display: flex;
	flex-direction: column;
	gap: 3px;
	max-height: 260px;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

.scr-alt-item {
	display: grid;
	grid-template-columns: 22px 1fr auto auto;
	gap: 6px;
	align-items: center;
	width: 100%;
	padding: 7px 10px;
	border: 1px solid #e2e8f0;
	border-radius: var(--scr-radius);
	background: #f8f9fa;
	cursor: pointer;
	text-align: left;
	font-size: 13px;
	transition: background 0.1s, border-color 0.1s;
}

.scr-alt-item:hover {
	background: #edf2f7;
	border-color: #cbd5e0;
}

.scr-alt-item--selected {
	background: #ebf8ff;
	border-color: var(--scr-primary);
}

.scr-alt-rank {
	color: #a0aec0;
	font-size: 11px;
	text-align: center;
	font-weight: 600;
}

.scr-alt-item--selected .scr-alt-rank {
	color: var(--scr-primary);
}

.scr-alt-word {
	font-weight: 700;
	letter-spacing: 2px;
	color: var(--scr-tile-text);
	text-transform: uppercase;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.scr-alt-pos {
	font-size: 11px;
	color: #718096;
	white-space: nowrap;
}

.scr-alt-score {
	font-weight: 700;
	color: var(--scr-tws);
	white-space: nowrap;
	min-width: 46px;
	text-align: right;
	font-size: 13px;
}
