:root {
    --bg: #120c22;
    --card: rgba(24, 16, 42, 0.92);
    --ink: #f6eefe;
    --muted: #cbb9e8;
    --accent: #d7b4ff;
    --accent-dark: #a78bfa;
    --success: #86efac;
    --danger: #fca5a5;
    --divider: rgba(215, 180, 255, 0.25);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    user-select: none;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--card);
    border-bottom: 1px solid var(--divider);
    flex-shrink: 0;
    gap: 8px;
}

.times {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    line-height: 1.2;
}

.times .current {
    font-weight: 600;
    color: var(--accent);
}

.times .best {
    color: var(--muted);
    font-size: 12px;
}

.exit-btn {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
}

.exit-btn:active {
    background: rgba(215, 180, 255, 0.15);
}

/* Level selector */
.levels {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
}

.levels button {
    flex: 1;
    padding: 8px 4px;
    border: 1px solid var(--divider);
    background: transparent;
    color: var(--muted);
    border-radius: 10px;
    font-size: 13px;
    cursor: pointer;
}

.levels button.active {
    background: var(--accent);
    color: #1a0f2e;
    border-color: var(--accent);
    font-weight: 600;
}

/* Game area */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.canvas-wrap {
    flex: 1;
    position: relative;
    background: #0d0818;
    min-height: 0;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* Divider with counter */
.divider {
    flex-shrink: 0;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(90deg, transparent, rgba(215, 180, 255, 0.12), transparent);
    border-top: 1px solid var(--divider);
    border-bottom: 1px solid var(--divider);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--accent);
    text-align: center;
    padding: 0 12px;
}

/* Bottom controls */
.controls {
    display: flex;
    gap: 8px;
    padding: 10px 12px 14px;
    background: var(--card);
    border-top: 1px solid var(--divider);
    flex-shrink: 0;
}

.controls button {
    flex: 1;
    padding: 12px 6px;
    border: none;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
}

.controls button:active {
    transform: scale(0.96);
}

.btn-start {
    background: var(--accent);
    color: #1a0f2e;
}

.btn-hint {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow: hidden; /* Чтобы заполнение не вылезало за скругленные края кнопки */
    background: #25183a; /* Темный фон кнопки во время кулдауна */
    color: #1a0f2e;
    border: 1px solid #4ade80;
    transition: background 0.3s, opacity 0.3s;
}

/* Сама полоса наполнения */
.hint-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #00e676; /* Ярко-зеленый цвет кулдауна */
    transform: scaleX(0); /* Изначально скрыта */
    transform-origin: left center; /* КРИТИЧЕСКИ ВАЖНО: рост слева направо */
    z-index: 1;
}

/* Контент внутри кнопки должен быть выше плашки заполнения */
.hint-content {
    position: relative;
    display: flex;
    align-items: center;
    z-index: 2;
    pointer-events: none; /* Чтобы клики проходили сквозь текст на саму кнопку */
}

/* Когда кнопка активна и готова к использованию (не в кулдауне) */
.btn-hint.ready {
    background: #00e676; /* Полностью зеленая кнопка, когда готова */
}

/* Если кнопка готова, скрываем полосу, так как кнопка и так вся зеленая */
.btn-hint.ready .hint-fill {
    transform: scaleX(0);
    transition: none;
}

.hint-icon {
    display: block;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

.hint-count {
    background: #fbbf24;
    color: #1a0f2e;
    font-size: 10px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    align-items: center;
    padding: 0 5px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    line-height: 1;
}

.btn-next {
    background: rgba(255, 255, 255, 0.08);
    color: var(--ink);
}

.btn-start.paused {
    background: #fbbf24;
    color: #1a0f2e;
}

/* Flash overlay */
.flash {
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.15s;
}

.flash.show {
    opacity: 0.55;
}

/* Win overlay */
.win-overlay {
    position: absolute;
    inset: 0;
    background: rgba(18, 12, 34, 0.88);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    gap: 12px;
    text-align: center;
    padding: 20px;
}

.win-overlay.show {
    display: flex;
}

.win-overlay h2 {
    font-size: 28px;
    color: var(--success);
}

.win-overlay .time {
    font-size: 22px;
    color: var(--accent);
}

.win-overlay button {
    margin-top: 8px;
    padding: 12px 28px;
    background: var(--accent);
    color: #1a0f2e;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

/* Hint circle */
.hint-circle {
    position: absolute;
    border: 3px solid #fbbf24;
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.3);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.7;
    }
}
