/* =====================================================
   TEMPORIZADORES — PROFENINJA
   ===================================================== */

/* ── Custom properties (tema claro por defecto) ── */
:root {
    --tm-bg:          #f0f4ff;
    --tm-surface:     #ffffff;
    --tm-surface2:    #f1f5f9;
    --tm-border:      #e2e8f0;
    --tm-text:        #1e293b;
    --tm-text2:       #475569;
    --tm-muted:       #94a3b8;
    --tm-accent:      #3b82f6;
    --tm-accent-end:  #6366f1;
    --tm-accent-h:    #2563eb;
    --tm-success:     #10b981;
    --tm-warning:     #f59e0b;
    --tm-danger:      #ef4444;
    --tm-shadow:      0 4px 20px rgba(0,0,0,0.08);
    --tm-shadow-lg:   0 12px 40px rgba(0,0,0,0.13);
    --tm-radius:      16px;
    --tm-radius-sm:   10px;
    --tm-ease:        cubic-bezier(0.4, 0, 0.2, 1);
    --ring-ok:        #3b82f6;
    --ring-warn:      #f59e0b;
    --ring-danger:    #ef4444;
}

body.theme-light {
    --tm-bg:        #f0f4ff;
    --tm-surface:   #ffffff;
    --tm-surface2:  #f1f5f9;
    --tm-border:    #e2e8f0;
    --tm-text:      #1e293b;
    --tm-text2:     #475569;
    --tm-muted:     #94a3b8;
}

body.theme-dark {
    --tm-bg:        #0f0f23;
    --tm-surface:   #1a1a2e;
    --tm-surface2:  #16213e;
    --tm-border:    rgba(255,255,255,0.1);
    --tm-text:      rgba(255,255,255,0.95);
    --tm-text2:     rgba(255,255,255,0.65);
    --tm-muted:     rgba(255,255,255,0.35);
    --tm-accent:    #60a5fa;
    --tm-accent-end:#818cf8;
    --tm-accent-h:  #93c5fd;
    --tm-shadow:    0 4px 20px rgba(0,0,0,0.4);
    --tm-shadow-lg: 0 12px 40px rgba(0,0,0,0.55);
    --ring-ok:      #60a5fa;
    --ring-warn:    #fbbf24;
    --ring-danger:  #f87171;
}

body.theme-rosa {
    --tm-bg:        #fdf2f8;
    --tm-surface:   #ffffff;
    --tm-surface2:  #fce7f3;
    --tm-border:    #f9a8d4;
    --tm-text:      #831843;
    --tm-text2:     #be185d;
    --tm-muted:     #f472b6;
    --tm-accent:    #ec4899;
    --tm-accent-end:#db2777;
    --tm-accent-h:  #db2777;
    --tm-shadow:    0 4px 20px rgba(236,72,153,0.15);
    --tm-shadow-lg: 0 12px 40px rgba(236,72,153,0.22);
    --ring-ok:      #ec4899;
    --ring-warn:    #f97316;
    --ring-danger:  #ef4444;
}

body.theme-neon {
    --tm-bg:        #050510;
    --tm-surface:   rgba(0,255,136,0.06);
    --tm-surface2:  rgba(0,255,136,0.1);
    --tm-border:    rgba(0,255,136,0.22);
    --tm-text:      #00ff88;
    --tm-text2:     rgba(0,255,136,0.75);
    --tm-muted:     rgba(0,255,136,0.4);
    --tm-accent:    #00ff88;
    --tm-accent-end:#00d4ff;
    --tm-accent-h:  #00cc6a;
    --tm-shadow:    0 4px 20px rgba(0,255,136,0.12);
    --tm-shadow-lg: 0 12px 40px rgba(0,255,136,0.18);
    --ring-ok:      #00ff88;
    --ring-warn:    #ffcc00;
    --ring-danger:  #ff4455;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--tm-bg);
    color: var(--tm-text);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.35s var(--tm-ease), color 0.35s var(--tm-ease);
}

button { cursor: pointer; font-family: inherit; }
input  { font-family: inherit; }

/* ── App shell ── */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* =====================================================
   HEADER
   ===================================================== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--tm-border);
    padding: 0.85rem 1.5rem;
    transition: background 0.35s var(--tm-ease), border-color 0.35s var(--tm-ease);
}
body.theme-dark .app-header,
body.theme-neon .app-header {
    background: rgba(15,15,35,0.8);
}
body.theme-rosa .app-header {
    background: rgba(253,242,248,0.85);
}

.header-content {
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    justify-content: center;
}

.button-wrap.volver-menu {
    position: absolute;
    left: 0;
}

.button-wrap.volver-menu button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--tm-surface);
    border: 1px solid var(--tm-border);
    color: var(--tm-text);
    transition: all 0.2s var(--tm-ease);
}
.button-wrap.volver-menu button:hover {
    background: var(--tm-surface2);
    box-shadow: var(--tm-shadow);
    transform: scale(1.06);
}

.header-center { text-align: center; }

.app-title {
    font-size: clamp(1.3rem, 3.5vw, 1.7rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    color: var(--tm-text);
}

.app-subtitle {
    font-size: 0.8rem;
    color: var(--tm-muted);
    letter-spacing: 0.03em;
    margin-top: 0.1rem;
}

/* =====================================================
   TABS
   ===================================================== */
.tabs-bar {
    background: var(--tm-surface);
    border-bottom: 1px solid var(--tm-border);
    display: flex;
    justify-content: center;
    transition: background 0.35s var(--tm-ease);
}

.tabs-inner {
    display: flex;
    width: 100%;
    max-width: 560px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.85rem 0.5rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--tm-muted);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.22s var(--tm-ease);
    outline: none;
    white-space: nowrap;
}
.tab-btn:hover {
    color: var(--tm-text2);
    background: var(--tm-surface2);
}
.tab-btn.active {
    color: var(--tm-accent);
    border-bottom-color: var(--tm-accent);
    font-weight: 700;
}
.tab-btn svg { flex-shrink: 0; }

/* =====================================================
   PANELS
   ===================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel {
    display: none;
    animation: panelIn 0.3s var(--tm-ease) forwards;
    padding: 2rem 1rem 3rem;
}
.panel.active { display: flex; flex-direction: column; align-items: center; }

@keyframes panelIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0);    }
}

.panel-inner {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.6rem;
}

/* =====================================================
   COUNTDOWN — RING
   ===================================================== */
.ring-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
}

.ring-box {
    position: relative;
    width: min(280px, 72vw);
    height: min(280px, 72vw);
}

.ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-track {
    fill: none;
    stroke: var(--tm-border);
    stroke-width: 10;
}
body.theme-dark .ring-track,
body.theme-neon .ring-track {
    stroke: rgba(255,255,255,0.07);
}

.ring-arc {
    fill: none;
    stroke: var(--ring-ok);
    stroke-width: 10;
    stroke-linecap: round;
    /* 2π × 120 = 753.982 */
    stroke-dasharray: 753.982;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.95s linear, stroke 0.5s ease;
    filter: drop-shadow(0 0 7px currentColor);
}

/* Centre content */
.ring-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    pointer-events: none;
}

.ring-time {
    display: flex;
    align-items: center;
    gap: 0.05rem;
    font-size: clamp(2rem, 8.5vw, 3.5rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.025em;
    line-height: 1;
    color: var(--tm-text);
}

.rt-colon {
    opacity: 0.4;
    margin: 0 0.05em;
}
.running .rt-colon {
    animation: blinkColon 1s step-start infinite;
}
@keyframes blinkColon {
    0%, 100% { opacity: 0.4; }
    50%       { opacity: 0.1; }
}

.ring-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--tm-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

/* Finished pulse */
.ring-box.finished .ring-arc {
    animation: pulsaRing 0.9s ease-in-out infinite alternate;
}
@keyframes pulsaRing {
    from { stroke: var(--ring-danger); filter: drop-shadow(0 0 5px var(--ring-danger)); }
    to   { stroke: var(--ring-warn);   filter: drop-shadow(0 0 20px var(--ring-warn)); }
}

/* =====================================================
   TIME INPUTS
   ===================================================== */
.time-inputs {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.tf-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.step-up, .step-dn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 28px;
    background: var(--tm-surface2);
    border: 1px solid var(--tm-border);
    border-radius: 8px;
    color: var(--tm-text2);
    transition: all 0.18s var(--tm-ease);
    padding: 0;
}
.step-up:hover, .step-dn:hover {
    background: var(--tm-accent);
    border-color: var(--tm-accent);
    color: #fff;
    transform: scale(1.08);
}

.tf-input {
    width: 64px;
    height: 54px;
    background: var(--tm-surface);
    border: 2px solid var(--tm-border);
    border-radius: 12px;
    color: var(--tm-text);
    font-size: 1.4rem;
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
    outline: none;
    transition: border-color 0.2s var(--tm-ease), box-shadow 0.2s var(--tm-ease);
    -moz-appearance: textfield;
}
.tf-input::-webkit-outer-spin-button,
.tf-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tf-input:focus {
    border-color: var(--tm-accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
body.theme-rosa .tf-input:focus { box-shadow: 0 0 0 3px rgba(236,72,153,0.15); }
body.theme-neon .tf-input:focus { box-shadow: 0 0 0 3px rgba(0,255,136,0.18); }

.tf-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--tm-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.tf-sep {
    font-size: 1.8rem;
    font-weight: 300;
    color: var(--tm-muted);
    padding-bottom: 1.4rem;
    user-select: none;
}

/* =====================================================
   PRESETS
   ===================================================== */
.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    width: 100%;
}

.preset {
    background: var(--tm-surface2);
    border: 2px solid var(--tm-border);
    border-radius: 100px;
    padding: 0.4rem 1.05rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--tm-text2);
    transition: all 0.18s var(--tm-ease);
    outline: none;
}
.preset:hover {
    border-color: var(--tm-accent);
    color: var(--tm-accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59,130,246,0.15);
}
.preset.active {
    background: var(--tm-accent);
    border-color: var(--tm-accent);
    color: #fff;
    box-shadow: 0 4px 14px rgba(59,130,246,0.35);
    transform: translateY(-1px);
}
body.theme-rosa .preset.active { box-shadow: 0 4px 14px rgba(236,72,153,0.35); }
body.theme-neon .preset.active { box-shadow: 0 4px 14px rgba(0,255,136,0.3); color: #000; }

/* =====================================================
   CONTROLS
   ===================================================== */
.ctrl-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: center;
    width: 100%;
}

.ctrl {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.3rem;
    border-radius: 12px;
    border: 2px solid transparent;
    font-size: 0.875rem;
    font-weight: 700;
    transition: all 0.18s var(--tm-ease);
    outline: none;
    white-space: nowrap;
}
.ctrl:active:not(:disabled) { transform: scale(0.96); }
.ctrl:disabled { opacity: 0.38; cursor: not-allowed; transform: none !important; }

.start-ctrl {
    background: var(--tm-accent);
    color: #fff;
    box-shadow: 0 4px 14px rgba(59,130,246,0.3);
}
.start-ctrl:hover:not(:disabled) {
    background: var(--tm-accent-h);
    box-shadow: 0 6px 20px rgba(59,130,246,0.42);
    transform: translateY(-1px);
}
body.theme-neon .start-ctrl { color: #000; }

.pause-ctrl {
    background: var(--tm-surface2);
    border-color: var(--tm-border);
    color: var(--tm-text2);
}
.pause-ctrl:hover:not(:disabled) {
    border-color: var(--tm-warning);
    color: var(--tm-warning);
    transform: translateY(-1px);
}

.reset-ctrl {
    background: var(--tm-surface2);
    border-color: var(--tm-border);
    color: var(--tm-text2);
}
.reset-ctrl:hover:not(:disabled) {
    border-color: var(--tm-danger);
    color: var(--tm-danger);
    transform: translateY(-1px);
}

.lap-ctrl {
    background: var(--tm-surface2);
    border-color: var(--tm-border);
    color: var(--tm-text2);
}
.lap-ctrl:hover:not(:disabled) {
    border-color: var(--tm-success);
    color: var(--tm-success);
    transform: translateY(-1px);
}

/* =====================================================
   STOPWATCH DISPLAY
   ===================================================== */
.sw-display-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 1.5rem 0 0.5rem;
}

.sw-digits {
    display: flex;
    align-items: baseline;
    font-variant-numeric: tabular-nums;
}

.sw-seg {
    font-size: clamp(3.2rem, 13vw, 5.8rem);
    font-weight: 900;
    letter-spacing: -0.035em;
    color: var(--tm-text);
    line-height: 1;
}

.sw-col {
    font-size: clamp(2.4rem, 10vw, 4.5rem);
    font-weight: 200;
    color: var(--tm-muted);
    line-height: 1;
    margin: 0 0.05em;
    user-select: none;
}
/* animate colon only when running */
.sw-digits.running .sw-col {
    animation: blinkColon 1s step-start infinite;
}

.sw-ms {
    font-size: clamp(1.2rem, 4.5vw, 2.1rem);
    font-weight: 500;
    color: var(--tm-muted);
    align-self: flex-end;
    margin-bottom: 0.35rem;
    letter-spacing: -0.01em;
}

/* =====================================================
   LAPS
   ===================================================== */
.laps-card {
    width: 100%;
    border-radius: var(--tm-radius);
    border: 1px solid var(--tm-border);
    background: var(--tm-surface);
    overflow: hidden;
    box-shadow: var(--tm-shadow);
}

.laps-thead {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    padding: 0.55rem 1rem;
    background: var(--tm-surface2);
    border-bottom: 1px solid var(--tm-border);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--tm-muted);
}

.laps-body {
    max-height: 230px;
    overflow-y: auto;
}
.laps-body::-webkit-scrollbar { width: 4px; }
.laps-body::-webkit-scrollbar-track { background: transparent; }
.laps-body::-webkit-scrollbar-thumb { background: var(--tm-border); border-radius: 100px; }

.laps-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--tm-muted);
    font-size: 0.88rem;
}

.lap-row {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--tm-border);
    font-size: 0.88rem;
    animation: slideIn 0.2s var(--tm-ease);
    transition: background 0.15s ease;
}
.lap-row:last-child { border-bottom: none; }
.lap-row:hover { background: var(--tm-surface2); }

.lap-num {
    font-weight: 700;
    color: var(--tm-muted);
}
.lap-partial, .lap-total {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.lap-row.best-lap .lap-partial { color: var(--tm-success); font-weight: 700; }
.lap-row.worst-lap .lap-partial { color: var(--tm-danger); font-weight: 700; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to   { opacity: 1; transform: translateX(0);     }
}

/* =====================================================
   CLOCK
   ===================================================== */
.clock-panel { min-height: 60vh; }
.clock-inner {
    justify-content: center;
    min-height: 60vh;
    gap: 2.5rem;
}

.clock-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.clock-time-row {
    display: flex;
    align-items: baseline;
    gap: 0.05em;
    font-variant-numeric: tabular-nums;
}

.clock-seg {
    font-size: clamp(4rem, 16vw, 9rem);
    font-weight: 900;
    letter-spacing: -0.04em;
    color: var(--tm-text);
    line-height: 1;
}
body.theme-dark .clock-seg { text-shadow: 0 0 40px rgba(96,165,250,0.3); }
body.theme-neon .clock-seg { text-shadow: 0 0 40px currentColor; }

.clock-colon, .clock-colon-s {
    font-size: clamp(3rem, 13vw, 7rem);
    font-weight: 200;
    color: var(--tm-muted);
    margin: 0 0.04em;
    line-height: 1;
    user-select: none;
    transition: opacity 0.25s ease;
}

.clock-ampm {
    font-size: clamp(1.4rem, 5vw, 3rem);
    font-weight: 700;
    color: var(--tm-accent);
    align-self: flex-end;
    margin-bottom: 0.5rem;
    margin-left: 0.3rem;
}

.clock-date {
    font-size: clamp(0.85rem, 2.5vw, 1.1rem);
    font-weight: 500;
    color: var(--tm-muted);
    letter-spacing: 0.02em;
    text-align: center;
}

.fmt-row {
    display: flex;
    gap: 0.5rem;
}

.fmt-btn {
    background: var(--tm-surface2);
    border: 2px solid var(--tm-border);
    border-radius: 10px;
    padding: 0.42rem 1.3rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--tm-text2);
    transition: all 0.18s var(--tm-ease);
    outline: none;
}
.fmt-btn:hover:not(.active) {
    border-color: var(--tm-accent);
    color: var(--tm-accent);
}
.fmt-btn.active {
    background: var(--tm-accent);
    border-color: var(--tm-accent);
    color: #fff;
}
body.theme-neon .fmt-btn.active { color: #000; }

/* =====================================================
   ALARM OVERLAY
   ===================================================== */
.alarm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.alarm-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.alarm-card {
    background: var(--tm-surface);
    border: 1px solid var(--tm-border);
    border-radius: 24px;
    padding: 3rem 2.5rem 2.5rem;
    text-align: center;
    box-shadow: var(--tm-shadow-lg);
    max-width: 380px;
    width: 90%;
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.alarm-icon {
    display: block;
    font-size: 3.8rem;
    margin-bottom: 1rem;
    animation: ringBell 0.5s ease-in-out infinite alternate;
}
@keyframes ringBell {
    from { transform: rotate(-18deg) scale(1);   }
    to   { transform: rotate( 18deg) scale(1.12); }
}

.alarm-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--tm-text);
    margin-bottom: 0.5rem;
}
.alarm-body {
    color: var(--tm-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}
.alarm-close-btn { margin: 0 auto; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 480px) {
    .app-header  { padding: 0.7rem 1rem; }
    .button-wrap.volver-menu { left: 0; }
    .panel       { padding: 1.5rem 0.75rem 2.5rem; }
    .panel-inner { gap: 1.3rem; }

    .tf-input { width: 54px; height: 46px; font-size: 1.15rem; }
    .step-up, .step-dn { width: 32px; height: 24px; }
    .tf-sep   { font-size: 1.4rem; }

    .ctrl     { padding: 0.55rem 0.9rem; font-size: 0.8rem; }
    .ctrl-row { gap: 0.5rem; }

    .laps-body { max-height: 180px; }
}

@media (max-width: 380px) {
    /* Hide label text in tabs, keep icons */
    .tab-btn span { display: none; }
    .tab-btn { padding: 0.85rem 0.75rem; }
    .time-inputs { gap: 0.35rem; }
}
