/* ============================================================
   Tähetuled (Letter Lights) — Styles
   ============================================================ */

/* ---- CSS Custom Properties ---- */
:root {
    --bg-deep:    #070b1a;
    --bg-mid:     #0f1630;
    --bg-surface: #1a2040;
    --text:       #f0f0f5;
    --text-dim:   #8890b0;
    --accent:     #ff6e6c;
    --accent2:    #7f5af0;
    --green:      #2cb67d;
    --yellow:     #ffd93d;
    --pole-color: #4a4e69;
    --housing:    #23272f;
    --housing-border: #3a3f4b;

    --lamp-size:  clamp(160px, 28vmin, 260px);
    --font-lamp:  clamp(48px, 10vmin, 80px);
    --radius:     16px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, Helvetica, Arial, sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

/* ---- Starry Background ---- */
#stars-bg {
    position: fixed; inset: 0;
    background:
        radial-gradient(1.5px 1.5px at 10% 20%, #fff8 0%, transparent 100%),
        radial-gradient(1px 1px at 30% 60%, #fff6 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 55% 15%, #fff7 0%, transparent 100%),
        radial-gradient(1px 1px at 70% 80%, #fff5 0%, transparent 100%),
        radial-gradient(1.2px 1.2px at 85% 40%, #fff6 0%, transparent 100%),
        radial-gradient(1px 1px at 20% 90%, #fff5 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 45% 45%, #fff4 0%, transparent 100%),
        radial-gradient(1px 1px at 65% 30%, #fff5 0%, transparent 100%),
        radial-gradient(1.2px 1.2px at 90% 70%, #fff6 0%, transparent 100%),
        radial-gradient(1px 1px at 5% 55%, #fff4 0%, transparent 100%),
        radial-gradient(1px 1px at 40% 85%, #fff5 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 75% 10%, #fff7 0%, transparent 100%),
        radial-gradient(1px 1px at 15% 40%, #fff4 0%, transparent 100%),
        radial-gradient(1.2px 1.2px at 60% 65%, #fff5 0%, transparent 100%),
        radial-gradient(1px 1px at 95% 25%, #fff4 0%, transparent 100%),
        linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
    z-index: 0;
    animation: twinkle 4s ease-in-out infinite alternate;
    pointer-events: none;
}
@keyframes twinkle { 0%{opacity:.8} 100%{opacity:1} }

/* ---- App / Screens ---- */
#app {
    position: relative; z-index: 1;
    width: 100%; height: 100%;
}

.screen {
    display: none;
    position: absolute; inset: 0;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; }

.screen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 18px;
}

/* ---- Menu Screen ---- */
.title-area { text-align: center; }
.title-icon { font-size: clamp(48px, 10vmin, 80px); line-height: 1; }
.title-area h1 {
    font-size: clamp(32px, 7vmin, 56px);
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--yellow));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.title-area h2 {
    font-size: clamp(16px, 3vmin, 24px);
    color: var(--text-dim);
    font-weight: 400;
    margin-top: 2px;
}
.instructions {
    font-size: clamp(14px, 2.5vmin, 20px);
    color: var(--text);
    margin-top: 10px;
}
.instructions-sm {
    font-size: clamp(12px, 2vmin, 16px);
    color: var(--text-dim);
}

/* ---- Settings Bar ---- */
.settings-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--housing-border);
}
.setting-group {
    display: flex; align-items: center; gap: 8px;
}
.setting-label {
    font-size: 13px; color: var(--text-dim); white-space: nowrap;
}
.toggle-group { display: flex; gap: 4px; }
.toggle-btn {
    border: 1px solid var(--housing-border);
    background: var(--bg-mid);
    color: var(--text-dim);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all .2s;
}
.toggle-btn.active {
    background: var(--accent2);
    color: #fff;
    border-color: var(--accent2);
}

/* ---- Level Grid ---- */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 700px;
    max-height: 35vh;
    overflow-y: auto;
    padding: 4px;
}
.level-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 6px;
    border-radius: 12px;
    border: 2px solid var(--housing-border);
    background: var(--bg-surface);
    cursor: pointer;
    transition: all .2s;
    text-align: center;
    min-height: 60px;
}
.level-card:hover, .level-card:active { border-color: var(--accent2); transform: scale(1.04); }
.level-card.selected { border-color: var(--accent); background: rgba(255,110,108,.12); }
.level-card.locked { opacity: .4; pointer-events: none; }
.level-card .lnum { font-weight: 700; font-size: 18px; }
.level-card .lname { font-size: 10px; color: var(--text-dim); margin-top: 2px; line-height: 1.2; }
.level-card .lstars { font-size: 12px; margin-top: 3px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: 12px;
    font-family: inherit; font-weight: 700; cursor: pointer;
    transition: transform .15s, box-shadow .15s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.95); }
.btn-large { padding: 14px 36px; font-size: clamp(16px, 3vmin, 22px); min-width: 200px; }
.btn-small { padding: 8px 16px; font-size: 14px; }
.btn-primary { background: var(--accent2); color: #fff; box-shadow: 0 4px 16px rgba(127,90,240,.3); }
.btn-success { background: var(--green); color: #fff; box-shadow: 0 4px 16px rgba(44,182,125,.3); }
.btn-ghost  { background: transparent; color: var(--text-dim); border: 1px solid var(--housing-border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

.pulse-anim { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(127,90,240,.3); }
    50%      { box-shadow: 0 4px 30px rgba(127,90,240,.55); }
}

/* ---- Game Header ---- */
.game-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--housing-border);
    flex-shrink: 0;
}
.header-label { font-size: 14px; color: var(--text-dim); }
.header-label.score { margin-left: auto; font-size: 16px; color: var(--yellow); }

/* ---- Timer ---- */
.timer-container {
    height: 6px;
    background: var(--bg-surface);
    flex-shrink: 0;
    overflow: hidden;
}
.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--green), var(--yellow), var(--accent));
    border-radius: 0 3px 3px 0;
    transition: width .1s linear;
}

/* ---- Game Area ---- */
.game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 10px 20px;
    min-height: 0;
}
.panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
    max-width: 280px;
}
.panel-label {
    font-size: clamp(14px, 2.5vmin, 20px);
    font-weight: 700;
    color: var(--text);
    text-align: center;
}
.panel-divider {
    width: 2px;
    align-self: stretch;
    margin: 30px 0;
    background: linear-gradient(180deg, transparent, var(--housing-border), transparent);
    flex-shrink: 0;
}

/* ---- Street Light ---- */
.street-light-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.light-housing {
    background: var(--housing);
    border: 2px solid var(--housing-border);
    border-radius: 20px;
    padding: clamp(8px, 1.5vmin, 14px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(6px, 1.2vmin, 12px);
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    position: relative;
}
.light-pole {
    width: 10px;
    height: clamp(30px, 6vmin, 60px);
    background: linear-gradient(90deg, #5a5e72, #3e4155, #5a5e72);
    border-radius: 0 0 4px 4px;
}
.light-base {
    width: 50px; height: 8px;
    background: linear-gradient(90deg, #5a5e72, #3e4155, #5a5e72);
    border-radius: 4px;
}

/* ---- Lamp ---- */
.lamp {
    width: var(--lamp-size);
    height: var(--lamp-size);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: box-shadow .4s, opacity .4s, transform .3s;
}
.lamp.lit {
    box-shadow:
        0 0 12px 4px var(--lamp-glow),
        0 0 30px 8px var(--lamp-glow),
        inset 0 0 15px rgba(255,255,255,.15);
}
.lamp.dim {
    opacity: .3;
    box-shadow: none;
}
.lamp.correct {
    box-shadow:
        0 0 12px 4px var(--green),
        0 0 40px 12px var(--green);
    animation: pop .4s ease;
}
.lamp.wrong {
    box-shadow:
        0 0 12px 4px var(--accent),
        0 0 40px 12px var(--accent);
    animation: shake .4s ease;
}

/* ---- Lamp Letter ---- */
.lamp-letter {
    font-size: var(--font-lamp);
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,.3);
    pointer-events: none;
    transition: opacity .4s, transform .4s;
}
.lamp-letter.hidden {
    opacity: 0;
    transform: scale(.5);
}

/* ---- Lamp Canvas (Draw Mode) ---- */
.lamp-canvas-wrap {
    width: 85%;
    height: 85%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lamp-canvas {
    border-radius: 50%;
    background: rgba(255,255,255,.10);
    touch-action: none;
    cursor: crosshair;
}
.lamp-canvas.active-canvas {
    background: rgba(255,255,255,.18);
    box-shadow: inset 0 0 10px rgba(255,255,255,.1);
}
.canvas-clear-btn {
    position: absolute;
    top: -8px; right: -8px;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 16px; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity .2s;
    z-index: 2;
}
.lamp-canvas-wrap:hover .canvas-clear-btn,
.lamp-canvas-wrap.has-content .canvas-clear-btn { opacity: 1; }

/* ---- Result overlay on lamp ---- */
.lamp-result {
    position: absolute;
    bottom: -6px; right: -6px;
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700;
    z-index: 3;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.lamp-result.ok  { background: var(--green); color: #fff; }
.lamp-result.bad { background: var(--accent); color: #fff; }

.lamp-expected {
    position: absolute;
    top: -8px; left: 50%; transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    font-size: 14px; font-weight: 700;
    padding: 2px 10px;
    border-radius: 10px;
    white-space: nowrap;
    z-index: 3;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* ---- Game Footer ---- */
.game-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 20px;
    flex-shrink: 0;
    min-height: 60px;
}
.game-message {
    font-size: clamp(14px, 2.5vmin, 20px);
    font-weight: 600;
    text-align: center;
    transition: opacity .3s;
}

/* ---- Overlay ---- */
.overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(7,11,26,.85);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn .3s ease;
}
.overlay-card {
    background: var(--bg-surface);
    border: 2px solid var(--housing-border);
    border-radius: 24px;
    padding: clamp(24px, 4vmin, 48px);
    text-align: center;
    max-width: 440px;
    width: 100%;
    animation: scaleIn .4s ease;
}
.overlay-card h2 { font-size: clamp(22px, 4vmin, 36px); margin-bottom: 8px; }
.overlay-card p  { color: var(--text-dim); font-size: 16px; margin-bottom: 16px; }
.overlay-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }

.big-stars { font-size: clamp(36px, 8vmin, 64px); margin-bottom: 8px; }

/* ---- Confetti ---- */
#confetti-container { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.confetti-piece {
    position: absolute;
    top: -20px;
    width: 10px; height: 18px;
    border-radius: 2px;
    animation: confettiFall var(--duration) ease-out forwards;
    animation-delay: var(--delay);
    opacity: 0;
}
@keyframes confettiFall {
    0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(110vh) rotate(var(--rot)); opacity: 0; }
}

/* ---- Keyframe Helpers ---- */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pop     { 0%{transform:scale(1)} 50%{transform:scale(1.15)} 100%{transform:scale(1)} }
@keyframes shake   { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }



/* ---- Responsive ---- */
@media (max-height: 500px) {
    .title-icon { font-size: 36px; }
    .title-area h1 { font-size: 28px; }
    .title-area h2, .instructions, .instructions-sm { font-size: 12px; }
    .settings-bar { padding: 6px 12px; gap: 10px; }
    .level-grid { max-height: 25vh; }
    .btn-large { padding: 10px 24px; font-size: 16px; }
    .game-footer { padding: 6px 16px; min-height: 48px; }
}

@media (max-width: 600px) {
    .game-area { flex-direction: column; gap: 10px; padding: 8px; }
    .panel-divider { width: auto; height: 2px; margin: 0 30px; align-self: auto; }
    .panel { max-width: 100%; }
    .light-housing { flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .light-pole, .light-base { display: none; }
}

/* ---- Landscape optimization for iPad ---- */
@media (min-width: 700px) and (orientation: landscape) {
    .menu-content { flex-direction: column; }
    .game-area { gap: 40px; }
    .panel { max-width: 320px; }
}

/* ---- Override input zoom on iOS ---- */
@supports (-webkit-touch-callout: none) {
}
