:root {
    --bg:       #0d0d0f;
    --bg2:      #141418;
    --bg3:      #1c1c22;
    --border:   rgba(255,255,255,0.07);
    --text:     #e8e8f0;
    --muted:    #6b6b7e;
    --accent1:  #7c3aed;
    --accent2:  #2563eb;
    --gradient: linear-gradient(135deg, #7c3aed, #2563eb);
    --radius:   16px;
}

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

html, body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 620px;
    padding: 24px 16px;
}

/* SCREENS */
.screen { display: none; }
.screen.active { display: block; }

/* LOGO */
.logo-area {
    text-align: center;
    margin-bottom: 36px;
}

.logo-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
}

.accent {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.95rem;
}

/* CARDS */
.form-card,
.loading-card,
.player-card,
.error-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
}

/* FORM */
.field-group { margin-bottom: 24px; }

.field-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

textarea {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    padding: 14px 16px;
    resize: none;
    transition: border-color .2s;
    line-height: 1.6;
}

textarea:focus {
    outline: none;
    border-color: var(--accent1);
}

textarea::placeholder { color: var(--muted); }

.char-count {
    display: block;
    text-align: right;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 6px;
}

/* DURATION */
.duration-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.duration-selector input[type="radio"] { display: none; }

.duration-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px 8px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all .2s;
    gap: 4px;
}

.duration-btn .d-min {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--muted);
    transition: color .2s;
    line-height: 1;
}

.duration-btn .d-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

input[type="radio"]:checked + .duration-btn {
    border-color: var(--accent1);
    background: rgba(124, 58, 237, 0.1);
}

input[type="radio"]:checked + .duration-btn .d-min {
    color: #a78bfa;
}

/* BUTTONS */
.btn-primary {
    width: 100%;
    padding: 15px;
    background: var(--gradient);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: opacity .2s, transform .15s;
}

.btn-primary svg { width: 18px; height: 18px; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    flex: 1;
    padding: 13px;
    background: var(--gradient);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: opacity .2s;
}

.btn-secondary svg { width: 16px; height: 16px; }
.btn-secondary:hover { opacity: 0.9; }

.btn-outline {
    flex: 1;
    padding: 13px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: border-color .2s, background .2s;
}

.btn-outline svg { width: 16px; height: 16px; }
.btn-outline:hover { border-color: var(--accent1); background: rgba(124, 58, 237, 0.06); }

/* LOADING */
.loading-card { text-align: center; }

.wave-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 60px;
    margin-bottom: 28px;
}

.wave-bar {
    width: 5px;
    border-radius: 3px;
    background: var(--gradient);
    animation: wave 1.2s ease-in-out infinite;
}

.wave-bar:nth-child(1)  { height: 20px; animation-delay: 0s; }
.wave-bar:nth-child(2)  { height: 35px; animation-delay: .1s; }
.wave-bar:nth-child(3)  { height: 50px; animation-delay: .2s; }
.wave-bar:nth-child(4)  { height: 40px; animation-delay: .3s; }
.wave-bar:nth-child(5)  { height: 55px; animation-delay: .4s; }
.wave-bar:nth-child(6)  { height: 42px; animation-delay: .5s; }
.wave-bar:nth-child(7)  { height: 50px; animation-delay: .6s; }
.wave-bar:nth-child(8)  { height: 32px; animation-delay: .7s; }
.wave-bar:nth-child(9)  { height: 18px; animation-delay: .8s; }

@keyframes wave {
    0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
    50%       { transform: scaleY(1);   opacity: 1; }
}

.loading-msg {
    font-size: 1.05rem;
    color: var(--text);
    margin-bottom: 24px;
    min-height: 2.2em;
    transition: opacity .4s;
}

.progress-track {
    height: 4px;
    background: var(--bg3);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 16px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--gradient);
    border-radius: 2px;
    animation: progress-fake 90s linear forwards;
}

@keyframes progress-fake {
    0%   { width: 0%; }
    60%  { width: 70%; }
    90%  { width: 88%; }
    100% { width: 92%; }
}

.loading-hint {
    font-size: 0.78rem;
    color: var(--muted);
}

/* PLAYER */
.player-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.player-icon {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.player-header h2 { font-size: 1.2rem; color: #fff; }

.player-topic {
    margin-top: 4px;
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 340px;
}

.player-actions {
    display: flex;
    gap: 12px;
}

/* ERROR */
.error-card { text-align: center; }

.error-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.error-card h2 { margin-bottom: 10px; color: #f87171; }
.error-card p  { color: var(--muted); font-size: 0.9rem; margin-bottom: 24px; }
.error-card .btn-outline { width: auto; display: inline-flex; }

/* NAVIGAZIONE */
.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding: 10px 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.app-nav-current {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color .2s, background .2s;
}

.app-nav-link svg { width: 15px; height: 15px; }
.app-nav-link:hover { border-color: var(--accent1); background: rgba(124,58,237,0.06); }

/* MODE BUTTONS */
.mode-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-mode {
    width: 100%;
}

.btn-analysis {
    background: linear-gradient(135deg, #059669, #0d9488);
}

.btn-analysis:hover {
    opacity: 0.9;
}

/* AUDIO — nascosto, gestito via custom player */
audio {
    display: none;
}

/* CUSTOM PLAYER */
.custom-player {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
}

.btn-play {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    background: var(--gradient);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, opacity .2s;
}

.btn-play svg {
    width: 22px;
    height: 22px;
}

.btn-play:active {
    transform: scale(0.92);
}

.player-controls {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.time-label {
    font-size: 0.75rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: center;
}

.seek-bar {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.seek-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent1);
    border: none;
    cursor: pointer;
}

.seek-bar::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent1);
    border: none;
    cursor: pointer;
}

/* RESPONSIVE */
@media (max-width: 480px) {
    .form-card, .loading-card, .player-card, .error-card { padding: 24px 20px; }
    h1 { font-size: 1.6rem; }
    .player-actions { flex-direction: column; }
    .custom-player { padding: 12px 14px; gap: 10px; }
    .btn-play { width: 44px; height: 44px; min-width: 44px; }
    .time-label { font-size: 0.7rem; min-width: 30px; }
}
