@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --bg:          #09090b;
    --bg2:         #18181b;
    --bg3:         #27272a;
    --border:      #3f3f46;
    --text:        #fafafa;
    --text2:       #a1a1aa;
    --accent:      #e4e4e7;

    --c3k:   #ef4444;
    --c2k:   #f97316;
    --c3h:   #1d4ed8;
    --c2h:   #3b82f6;
    --cstar: #eab308;

    --tile:      #d97706;
    --tile-h:    #b45309;
    --tile-text: #09090b;

    --font: 'DM Sans', -apple-system, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --radius: 8px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: var(--cstar); }

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── App wrapper ────────────────────────────────────────────────────────────── */
#app { padding: 20px 24px; max-width: 1480px; margin: 0 auto; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}
#header h1 { font-size: 22px; font-weight: 700; }
#header h1 span { font-size: 20px; }
#header p { font-size: 12px; color: var(--text2); margin-top: 4px; }
#header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Badge ───────────────────────────────────────────────────────────────────── */
.badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid currentColor;
    white-space: nowrap;
}
.badge-loading { color: var(--cstar); }
.badge-ready   { color: #10b981; }
.badge-error   { color: var(--c3k); }

/* ── Notifications ───────────────────────────────────────────────────────────── */
.notif {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid;
}
.notif-error   { background: rgba(239,68,68,.12);  border-color: #ef4444; color: #f87171; }
.notif-success { background: rgba(16,185,129,.12); border-color: #10b981; color: #34d399; }

/* ── Main grid ───────────────────────────────────────────────────────────────── */
#main-grid {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 20px;
    align-items: start;
}

@media (max-width: 1100px) {
    #main-grid { grid-template-columns: 280px 1fr; }
    #col-right { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
    #main-grid { grid-template-columns: 1fr; }
}

/* ── Left column ─────────────────────────────────────────────────────────────── */
#col-left { display: flex; flex-direction: column; gap: 16px; }

/* Dropzone */
#dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    background: var(--bg2);
    cursor: pointer;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .2s, background .2s;
}
#dropzone.drag-over {
    border-color: var(--cstar);
    background: rgba(234,179,8,.06);
}
#dropzone label { cursor: pointer; display: block; width: 100%; }
.dz-icon { font-size: 28px; display: block; margin-bottom: 8px; }
#dropzone strong { font-size: 13px; display: block; }
#dropzone small  { font-size: 11px; color: var(--text2); display: block; margin-top: 6px; }

/* Rack card */
#rack-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}
#rack-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
}
#rack-header small { font-weight: 400; font-size: 11px; }
#rack {
    display: flex;
    gap: 6px;
    justify-content: center;
}
.rack-cell {
    width: 40px;
    aspect-ratio: 1/1;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    transition: all .15s;
    font-family: var(--font);
}
.rack-cell:focus { border-color: var(--text2); }
.rack-cell.filled {
    background: var(--tile);
    color: var(--tile-text);
    border-color: var(--tile-h);
    box-shadow: 0 3px 6px rgba(0,0,0,.3);
}

/* Action row */
#action-row { display: flex; gap: 10px; }
#btn-solve { flex: 1; }
.btn-icon { padding: 0 14px; font-size: 16px; }

/* Guide card */
#guide-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    font-size: 12px;
    color: var(--text2);
    line-height: 1.7;
}
#guide-card h4 { color: var(--text); font-size: 13px; margin-bottom: 8px; }
#guide-card ul { padding-left: 16px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-family: var(--font);
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover:not(:disabled) { background: #fff; transform: translateY(-1px); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg3); border-color: var(--text2); }
.btn-danger { background: rgba(239,68,68,.15); color: #ef4444; border: 1px solid rgba(239,68,68,.4); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-link {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--c3k);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    padding: 0;
}

/* ── Board ───────────────────────────────────────────────────────────────────── */
#col-center { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#board-wrap { width: 100%; max-width: 580px; }
#board {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    gap: 2px;
    background: #09090b;
    border: 3px solid var(--bg3);
    border-radius: 8px;
    padding: 3px;
    aspect-ratio: 1/1;
    width: 100%;
}

.cell {
    aspect-ratio: 1/1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(7px, 1.8vw, 17px);
    font-weight: 700;
    border-radius: 3px;
    cursor: pointer;
    user-select: none;
    transition: all .12s;
    border: 1px solid rgba(255,255,255,.03);
    position: relative;
    font-family: var(--font);
}
.cell-empty  { background: var(--bg3); color: rgba(255,255,255,.18); font-size: clamp(5px,1.3vw,11px); font-family: var(--mono); font-weight: 400; }
.cell-3k     { background: var(--c3k); color: #fff; }
.cell-2k     { background: var(--c2k); color: #fff; }
.cell-3h     { background: var(--c3h); color: #fff; }
.cell-2h     { background: var(--c2h); color: #fff; }
.cell-star   { background: var(--cstar); color: var(--bg); }
.cell-tile   { background: var(--tile); color: var(--tile-text); }
.cell-active { border: 2px solid #fff !important; }
.cell-preview {
    background: var(--cstar) !important;
    color: var(--bg) !important;
    border: 2px solid var(--cstar) !important;
    animation: pulse 1.5s infinite;
}
.joker-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(0,0,0,.4);
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(234,179,8,.7); }
    70%  { box-shadow: 0 0 0 6px rgba(234,179,8,0); }
    100% { box-shadow: 0 0 0 0 rgba(234,179,8,0); }
}

/* Legend */
#legend {
    display: flex;
    gap: 14px;
    font-size: 11px;
    color: var(--text2);
    flex-wrap: wrap;
    justify-content: center;
}
#legend span { display: flex; align-items: center; gap: 4px; }
.sq { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sq-3k { background: var(--c3k); }
.sq-2k { background: var(--c2k); }
.sq-3h { background: var(--c3h); }
.sq-2h { background: var(--c2h); }

/* ── Moves panel ─────────────────────────────────────────────────────────────── */
#moves-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 600px;
}
#moves-header h3 { font-size: 15px; margin-bottom: 8px; }
#move-filter {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    outline: none;
    font-family: var(--font);
}
#move-filter:focus { border-color: var(--text2); }

#moves-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-right: 2px;
}
.moves-empty { text-align: center; color: var(--text2); font-size: 12px; padding: 20px 0; line-height: 1.7; }

.move-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 11px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    transition: all .12s;
}
.move-item:hover { border-color: var(--cstar); background: rgba(234,179,8,.08); }
.move-item.selected {
    border-color: var(--cstar);
    background: rgba(234,179,8,.12);
    transform: translateX(2px);
}
.move-word { font-size: 15px; font-weight: 700; }
.move-word.selected-text { color: var(--cstar); }
.move-pos { font-size: 10px; color: var(--text2); margin-top: 2px; }
.move-score {
    background: var(--border);
    padding: 3px 8px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--mono);
    white-space: nowrap;
}
.move-item.selected .move-score { background: var(--cstar); color: var(--bg); }

#move-preview {
    padding: 9px;
    background: rgba(255,255,255,.03);
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 11px;
    color: var(--text2);
    line-height: 1.5;
}

/* ── Letter Picker ───────────────────────────────────────────────────────────── */
#picker {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: min(92vw, 520px);
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 20px 40px rgba(0,0,0,.6);
    z-index: 500;
}
#picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text2);
}
.picker-section { margin-bottom: 10px; }
.picker-section small { font-size: 10px; color: var(--text2); display: block; margin-bottom: 5px; }
.picker-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
}
.picker-btn {
    aspect-ratio: 1/1;
    font-size: 13px;
    font-weight: 700;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font);
    transition: background .1s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.picker-btn:hover { background: var(--border); }
.picker-btn.clear-btn { background: rgba(239,68,68,.2); color: #ef4444; }
.picker-joker-btn { background: #52525b; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(9,9,11,.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
#modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: min(92vw, 480px);
    box-shadow: 0 20px 40px rgba(0,0,0,.5);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#modal h2 { font-size: 18px; }
#modal p { font-size: 13px; color: var(--text2); line-height: 1.6; }
#modal label { font-size: 12px; font-weight: 600; }
#modal-key {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    font-family: var(--font);
}
#modal small { font-size: 11px; color: var(--text2); }
#modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
